Signed-off-by: marcin mikołajczak <git@mkljczk.pl>environments/review-mastodon-r-p8g8in/deployments/4535
parent
93e9760274
commit
f69d1d95e4
@ -1,23 +0,0 @@
|
|||||||
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', async () => {
|
|
||||||
const rules = await import('soapbox/__fixtures__/rules.json');
|
|
||||||
|
|
||||||
__stub((mock) => {
|
|
||||||
mock.onGet('/api/v1/instance/rules').reply(200, rules);
|
|
||||||
});
|
|
||||||
|
|
||||||
const store = mockStore(rootState);
|
|
||||||
await store.dispatch(fetchRules());
|
|
||||||
|
|
||||||
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');
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,32 +0,0 @@
|
|||||||
import api from '../api';
|
|
||||||
|
|
||||||
import type { Rule } from 'soapbox/reducers/rules';
|
|
||||||
import type { RootState } from 'soapbox/store';
|
|
||||||
|
|
||||||
const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST';
|
|
||||||
const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS';
|
|
||||||
|
|
||||||
type RulesFetchRequestAction = {
|
|
||||||
type: typeof RULES_FETCH_REQUEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
type RulesFetchRequestSuccessAction = {
|
|
||||||
type: typeof RULES_FETCH_SUCCESS;
|
|
||||||
payload: Rule[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RulesActions = RulesFetchRequestAction | RulesFetchRequestSuccessAction
|
|
||||||
|
|
||||||
const fetchRules = () => (dispatch: React.Dispatch<RulesActions>, getState: () => RootState) => {
|
|
||||||
dispatch({ type: RULES_FETCH_REQUEST });
|
|
||||||
|
|
||||||
return api(getState)
|
|
||||||
.get('/api/v1/instance/rules')
|
|
||||||
.then((response) => dispatch({ type: RULES_FETCH_SUCCESS, payload: response.data }));
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
|
||||||
fetchRules,
|
|
||||||
RULES_FETCH_REQUEST,
|
|
||||||
RULES_FETCH_SUCCESS,
|
|
||||||
};
|
|
@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
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 } as any;
|
|
||||||
expect(reducer(initialState, action).isLoading).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ONBOARDING_END', () => {
|
|
||||||
it('sets "needsOnboarding" to "false"', () => {
|
|
||||||
const action = { type: RULES_FETCH_SUCCESS, payload: [{ id: '123' }] } as any;
|
|
||||||
const result = reducer(initialState, action);
|
|
||||||
expect(result.isLoading).toEqual(false);
|
|
||||||
expect(result.items[0].id).toEqual('123');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,31 +0,0 @@
|
|||||||
import { RULES_FETCH_REQUEST, RULES_FETCH_SUCCESS } from '../actions/rules';
|
|
||||||
|
|
||||||
import type { RulesActions } from '../actions/rules';
|
|
||||||
|
|
||||||
export type Rule = {
|
|
||||||
id: string;
|
|
||||||
text: string;
|
|
||||||
subtext: string;
|
|
||||||
rule_type: 'content' | 'account';
|
|
||||||
}
|
|
||||||
|
|
||||||
type RulesState = {
|
|
||||||
items: Rule[];
|
|
||||||
isLoading: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: RulesState = {
|
|
||||||
items: [],
|
|
||||||
isLoading: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function rules(state: RulesState = initialState, action: RulesActions): RulesState {
|
|
||||||
switch (action.type) {
|
|
||||||
case RULES_FETCH_REQUEST:
|
|
||||||
return { ...state, isLoading: true };
|
|
||||||
case RULES_FETCH_SUCCESS:
|
|
||||||
return { ...state, isLoading: false, items: action.payload };
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue