diff --git a/app/soapbox/__fixtures__/rules.json b/app/soapbox/__fixtures__/rules.json new file mode 100644 index 0000000000..c1c7a1f7d5 --- /dev/null +++ b/app/soapbox/__fixtures__/rules.json @@ -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" + } +] diff --git a/app/soapbox/actions/__tests__/rules.test.ts b/app/soapbox/actions/__tests__/rules.test.ts new file mode 100644 index 0000000000..4574adc2e3 --- /dev/null +++ b/app/soapbox/actions/__tests__/rules.test.ts @@ -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); + }); +}); diff --git a/app/soapbox/reducers/__tests__/rules.test.ts b/app/soapbox/reducers/__tests__/rules.test.ts new file mode 100644 index 0000000000..151516a831 --- /dev/null +++ b/app/soapbox/reducers/__tests__/rules.test.ts @@ -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'); + }); + }); +});