Commit 0171c8fa authored by Scott Hampton's avatar Scott Hampton

Refactor how endpoints are set

Remove the `setEndpoint` actions and
mutations in favor of setting the endpoint
when the store is created.
parent e5eb8437
......@@ -3,9 +3,6 @@ import * as types from './mutation_types';
import { parseAccessibilityReport, compareAccessibilityReports } from './utils';
import { s__ } from '~/locale';
export const setBaseEndpoint = ({ commit }, endpoint) => commit(types.SET_BASE_ENDPOINT, endpoint);
export const setHeadEndpoint = ({ commit }, endpoint) => commit(types.SET_HEAD_ENDPOINT, endpoint);
export const fetchReport = ({ state, dispatch, commit }) => {
commit(types.REQUEST_REPORT);
......
......@@ -6,9 +6,9 @@ import state from './state';
Vue.use(Vuex);
export default () =>
export default initialState =>
new Vuex.Store({
actions,
mutations,
state: state(),
state: state(initialState),
});
export const SET_BASE_ENDPOINT = 'SET_BASE_ENDPOINT';
export const SET_HEAD_ENDPOINT = 'SET_HEAD_ENDPOINT';
export const REQUEST_REPORT = 'REQUEST_REPORT';
export const RECEIVE_REPORT_SUCCESS = 'RECEIVE_REPORT_SUCCESS';
export const RECEIVE_REPORT_ERROR = 'RECEIVE_REPORT_ERROR';
import * as types from './mutation_types';
export default {
[types.SET_BASE_ENDPOINT](state, endpoint) {
state.baseEndpoint = endpoint;
},
[types.SET_HEAD_ENDPOINT](state, endpoint) {
state.headEndpoint = endpoint;
},
[types.REQUEST_REPORT](state) {
state.isLoading = true;
},
......
export default () => ({
endpoint: null,
export default (initialState = {}) => ({
baseEndpoint: initialState.baseEndpoint || '',
headEndpoint: initialState.headEndpoint || '',
isLoading: false,
hasError: false,
isLoading: initialState.isLoading || false,
hasError: initialState.hasError || false,
/**
* Report will have the following format:
......@@ -25,5 +26,5 @@ export default () => ({
* resolved_warnings: {Array.<Object>},
* }
*/
report: {},
report: initialState.report || {},
});
......@@ -16,32 +16,6 @@ describe('Accessibility Reports actions', () => {
localState = localStore.state;
});
describe('setBaseEndpoint', () => {
it('should commit SET_BASE_ENDPOINT mutation', done => {
testAction(
actions.setBaseEndpoint,
'endpoint.json',
localState,
[{ type: types.SET_BASE_ENDPOINT, payload: 'endpoint.json' }],
[],
done,
);
});
});
describe('setHeadEndpoint', () => {
it('should commit SET_HEAD_ENDPOINT mutation', done => {
testAction(
actions.setHeadEndpoint,
'endpoint.json',
localState,
[{ type: types.SET_HEAD_ENDPOINT, payload: 'endpoint.json' }],
[],
done,
);
});
});
describe('fetchReport', () => {
let mock;
......
......@@ -10,24 +10,6 @@ describe('Accessibility Reports mutations', () => {
localState = localStore.state;
});
describe('SET_BASE_ENDPOINT', () => {
it('sets the given endpoint', () => {
const endpoint = '/test-endpoint';
mutations.SET_BASE_ENDPOINT(localState, endpoint);
expect(localState.baseEndpoint).toEqual(endpoint);
});
});
describe('SET_HEAD_ENDPOINT', () => {
it('sets the given endpoint', () => {
const endpoint = '/test-endpoint';
mutations.SET_HEAD_ENDPOINT(localState, endpoint);
expect(localState.headEndpoint).toEqual(endpoint);
});
});
describe('REQUEST_REPORT', () => {
it('sets isLoading to true', () => {
mutations.REQUEST_REPORT(localState);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment