Add tests for Rules redux action/reducer
This commit is contained in:
parent
924b042c84
commit
ac53ed11b9
3 changed files with 71 additions and 0 deletions
14
app/soapbox/__fixtures__/rules.json
Normal file
14
app/soapbox/__fixtures__/rules.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
[
|
||||
{
|
||||
"id": "1",
|
||||
"text": "Illegal activity and behavior",
|
||||
"subtext": "Content that depicts illegal or criminal acts, threats of violence.",
|
||||
"rule_type": "content"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"text": "Intellectual property infringement",
|
||||
"subtext": "Impersonating another account or business, infringing on intellectual property rights.",
|
||||
"rule_type": "content"
|
||||
}
|
||||
]
|
26
app/soapbox/actions/__tests__/rules.test.ts
Normal file
26
app/soapbox/actions/__tests__/rules.test.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { __stub } from 'soapbox/api';
|
||||
import { mockStore, rootState } from 'soapbox/jest/test-helpers';
|
||||
|
||||
import { fetchRules, RULES_FETCH_REQUEST, RULES_FETCH_SUCCESS } from '../rules';
|
||||
|
||||
describe('fetchRules()', () => {
|
||||
it('sets the rules', (done) => {
|
||||
const rules = require('soapbox/__fixtures__/rules.json');
|
||||
|
||||
__stub((mock) => {
|
||||
mock.onGet('/api/v1/instance/rules').reply(200, rules);
|
||||
});
|
||||
|
||||
const store = mockStore(rootState);
|
||||
|
||||
store.dispatch(fetchRules()).then((context) => {
|
||||
const actions = store.getActions();
|
||||
|
||||
expect(actions[0].type).toEqual(RULES_FETCH_REQUEST);
|
||||
expect(actions[1].type).toEqual(RULES_FETCH_SUCCESS);
|
||||
expect(actions[1].payload[0].id).toEqual('1');
|
||||
|
||||
done();
|
||||
}).catch(console.error);
|
||||
});
|
||||
});
|
31
app/soapbox/reducers/__tests__/rules.test.ts
Normal file
31
app/soapbox/reducers/__tests__/rules.test.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
import { RULES_FETCH_REQUEST, RULES_FETCH_SUCCESS } from 'soapbox/actions/rules';
|
||||
|
||||
import reducer from '../rules';
|
||||
|
||||
const initialState = {
|
||||
items: [],
|
||||
isLoading: false,
|
||||
};
|
||||
|
||||
describe('rules reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {} as any)).toEqual(initialState);
|
||||
});
|
||||
|
||||
describe('RULES_FETCH_REQUEST', () => {
|
||||
it('sets "needsOnboarding" to "true"', () => {
|
||||
const action = { type: RULES_FETCH_REQUEST };
|
||||
expect(reducer(initialState, action).isLoading).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ONBOARDING_END', () => {
|
||||
it('sets "needsOnboarding" to "false"', () => {
|
||||
const action = { type: RULES_FETCH_SUCCESS, payload: [{ id: '123' }] };
|
||||
const result = reducer(initialState, action);
|
||||
expect(result.isLoading).toEqual(false);
|
||||
expect(result.items[0].id).toEqual('123');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue