Add tests for Rules redux action/reducer

merge-requests/1294/head
Justin 2022-05-02 08:56:15 -04:00
rodzic 924b042c84
commit ac53ed11b9
3 zmienionych plików z 71 dodań i 0 usunięć

Wyświetl plik

@ -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"
}
]

Wyświetl plik

@ -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);
});
});

Wyświetl plik

@ -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');
});
});
});