[CORL-276] Sitewide Pre-Moderation (#2392)

* feat: initial implementation

* chore: docs update

* fix: lint

* fix: naming
This commit is contained in:
Wyatt Johnson
2019-07-05 23:18:58 +00:00
committed by GitHub
parent e7745a85aa
commit 9a191b44ba
10 changed files with 374 additions and 5 deletions
@@ -107,6 +107,139 @@ exports[`renders configure moderation 1`] = `
className="Box-root HorizontalGutter-root HorizontalGutter-double"
data-testid="configure-moderationContainer"
>
<fieldset
className="FieldSet-root Box-root HorizontalGutter-root HorizontalGutter-oneAndAHalf"
>
<legend
className="Box-root Typography-root Typography-heading1 Typography-colorTextPrimary Header-root"
>
Pre-moderation
</legend>
<p
className="Box-root Typography-root Typography-detail Typography-colorTextPrimary"
>
When pre-moderation is turned on, comments will not be published unless
approved by a moderator.
</p>
<fieldset
className="FieldSet-root Box-root HorizontalGutter-root FormField-root HorizontalGutter-half"
>
<legend
className="Box-root Typography-root Typography-inputLabel Typography-colorTextPrimary InputLabel-root"
>
Pre-moderate all comments sitewide
</legend>
<div>
<div
className="Box-root Flex-root RadioButton-root Flex-flex Flex-alignCenter"
>
<input
checked={false}
className="RadioButton-input"
disabled={false}
id="moderation-true"
name="moderation"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="radio"
value={true}
/>
<label
className="RadioButton-label"
htmlFor="moderation-true"
>
<span>
On
</span>
</label>
</div>
<div
className="Box-root Flex-root RadioButton-root Flex-flex Flex-alignCenter"
>
<input
checked={true}
className="RadioButton-input"
disabled={false}
id="moderation-false"
name="moderation"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="radio"
value={false}
/>
<label
className="RadioButton-label"
htmlFor="moderation-false"
>
<span>
Off
</span>
</label>
</div>
</div>
</fieldset>
<fieldset
className="FieldSet-root Box-root HorizontalGutter-root FormField-root HorizontalGutter-half"
>
<legend
className="Box-root Typography-root Typography-inputLabel Typography-colorTextPrimary InputLabel-root"
>
Pre-moderate comments containing links sitewide
</legend>
<div>
<div
className="Box-root Flex-root RadioButton-root Flex-flex Flex-alignCenter"
>
<input
checked={false}
className="RadioButton-input"
disabled={false}
id="premodLinksEnable-true"
name="premodLinksEnable"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="radio"
value={true}
/>
<label
className="RadioButton-label"
htmlFor="premodLinksEnable-true"
>
<span>
On
</span>
</label>
</div>
<div
className="Box-root Flex-root RadioButton-root Flex-flex Flex-alignCenter"
>
<input
checked={true}
className="RadioButton-input"
disabled={false}
id="premodLinksEnable-false"
name="premodLinksEnable"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="radio"
value={false}
/>
<label
className="RadioButton-label"
htmlFor="premodLinksEnable-false"
>
<span>
Off
</span>
</label>
</div>
</div>
</fieldset>
</fieldset>
<fieldset
className="FieldSet-root Box-root HorizontalGutter-root HorizontalGutter-oneAndAHalf"
>
@@ -1,5 +1,5 @@
import { pureMerge } from "coral-common/utils";
import { GQLResolver } from "coral-framework/schema";
import { GQLMODERATION_MODE, GQLResolver } from "coral-framework/schema";
import {
createResolversStub,
CreateTestRendererParams,
@@ -60,6 +60,102 @@ it("renders configure moderation", async () => {
expect(within(configureContainer).toJSON()).toMatchSnapshot();
});
it("change site wide pre-moderation", async () => {
const resolvers = createResolversStub<GQLResolver>({
Mutation: {
updateSettings: ({ variables }) => {
expectAndFail(variables.settings.moderation).toEqual(
GQLMODERATION_MODE.PRE
);
return {
settings: pureMerge(settings, variables.settings),
};
},
},
});
const {
configureContainer,
moderationContainer,
saveChangesButton,
} = await createTestRenderer({
resolvers,
});
const preModerationContainer = within(moderationContainer).getAllByText(
"Pre-moderate all comments sitewide",
{ selector: "fieldset" }
)[0];
const onField = within(preModerationContainer).getByLabelText("On");
// Let's enable it.
onField.props.onChange(onField.props.value.toString());
// Send form
within(configureContainer)
.getByType("form")
.props.onSubmit();
// Submit button and text field should be disabled.
expect(saveChangesButton.props.disabled).toBe(true);
expect(onField.props.disabled).toBe(true);
// Wait for submission to be finished
await wait(() => {
expect(onField.props.disabled).toBe(false);
});
// Should have successfully sent with server.
expect(resolvers.Mutation!.updateSettings!.called).toBe(true);
});
it("change site wide link pre-moderation", async () => {
const resolvers = createResolversStub<GQLResolver>({
Mutation: {
updateSettings: ({ variables }) => {
expectAndFail(variables.settings.premodLinksEnable).toEqual(true);
return {
settings: pureMerge(settings, variables.settings),
};
},
},
});
const {
configureContainer,
moderationContainer,
saveChangesButton,
} = await createTestRenderer({
resolvers,
});
const preModerationContainer = within(moderationContainer).getAllByText(
"Pre-moderate comments containing links sitewide",
{ selector: "fieldset" }
)[0];
const onField = within(preModerationContainer).getByLabelText("On");
// Let's enable it.
onField.props.onChange(onField.props.value.toString());
// Send form
within(configureContainer)
.getByType("form")
.props.onSubmit();
// Submit button and text field should be disabled.
expect(saveChangesButton.props.disabled).toBe(true);
expect(onField.props.disabled).toBe(true);
// Wait for submission to be finished
await wait(() => {
expect(onField.props.disabled).toBe(false);
});
// Should have successfully sent with server.
expect(resolvers.Mutation!.updateSettings!.called).toBe(true);
});
it("change akismet settings", async () => {
const resolvers = createResolversStub<GQLResolver>({
Mutation: {