Allow voting for anonymous users
This commit is contained in:
@@ -27,6 +27,7 @@ export const StaticStore: StaticStoreType = {
|
||||
readonly_age: 0,
|
||||
max_image_size: 0,
|
||||
simple_view: false,
|
||||
anon_vote: false,
|
||||
},
|
||||
query: querySettings as QuerySettingsType,
|
||||
};
|
||||
|
||||
@@ -112,6 +112,7 @@ export interface Config {
|
||||
readonly_age: number;
|
||||
max_image_size: number;
|
||||
simple_view: boolean;
|
||||
anon_vote: boolean;
|
||||
}
|
||||
|
||||
export interface RemarkConfig {
|
||||
|
||||
@@ -32,6 +32,33 @@ const DefaultProps: Partial<Props> = {
|
||||
|
||||
describe('<Comment />', () => {
|
||||
describe('voting', () => {
|
||||
it('should be disabled for an anonymous user', () => {
|
||||
const props = { ...DefaultProps, user: { id: 'anonymous_1' } } as Props;
|
||||
const wrapper = shallow(<Comment {...props} />);
|
||||
const voteButtons = wrapper.find('.comment__vote');
|
||||
|
||||
expect(voteButtons.length).toEqual(2);
|
||||
|
||||
voteButtons.forEach(button => {
|
||||
expect(button.prop('aria-disabled')).toEqual('true');
|
||||
expect(button.prop('title')).toEqual("Anonymous users can't vote");
|
||||
});
|
||||
});
|
||||
|
||||
it('should be enabled for an anonymous user when it was allowed from server', () => {
|
||||
StaticStore.config.anon_vote = true;
|
||||
|
||||
const props = { ...DefaultProps, user: { id: 'anonymous_1' } } as Props;
|
||||
const wrapper = shallow(<Comment {...props} />);
|
||||
const voteButtons = wrapper.find('.comment__vote');
|
||||
|
||||
expect(voteButtons.length).toEqual(2);
|
||||
|
||||
voteButtons.forEach(button => {
|
||||
expect(button.prop('aria-disabled')).toEqual('false');
|
||||
});
|
||||
});
|
||||
|
||||
it('disabled on user info widget', () => {
|
||||
const element = mount(<Comment {...({ ...DefaultProps, view: 'user' } as Props)} />);
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ export class Comment extends Component<Props, State> {
|
||||
if (this.isCurrentUser()) return "Can't vote for your own comment";
|
||||
if (StaticStore.config.positive_score && this.props.data.score < 1) return 'Only positive score allowed';
|
||||
if (this.isGuest()) return 'Sign in to vote';
|
||||
if (this.isAnonymous()) return "Anonymous users can't vote";
|
||||
if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote";
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -367,7 +367,7 @@ export class Comment extends Component<Props, State> {
|
||||
if (this.props.data.delete) return "Can't vote for deleted comment";
|
||||
if (this.isCurrentUser()) return "Can't vote for your own comment";
|
||||
if (this.isGuest()) return 'Sign in to vote';
|
||||
if (this.isAnonymous()) return "Anonymous users can't vote";
|
||||
if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote";
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,5 +22,6 @@ beforeEach(() => {
|
||||
readonly_age: 100,
|
||||
version: 'jest-test',
|
||||
simple_view: false,
|
||||
anon_vote: false,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user