gitlab-org--gitlab-foss/spec/frontend/mr_notes/stores/actions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.6 KiB
JavaScript
Raw Normal View History

import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import { createStore } from '~/mr_notes/stores';
describe('MR Notes Mutator Actions', () => {
let store;
beforeEach(() => {
store = createStore();
});
describe('setEndpoints', () => {
it('sets endpoints', async () => {
const endpoints = { endpointA: 'a' };
await store.dispatch('setEndpoints', endpoints);
expect(store.state.page.endpoints).toEqual(endpoints);
});
});
describe('fetchMrMetadata', () => {
const mrMetadata = { meta: true, data: 'foo' };
const metadata = 'metadata';
const endpoints = { metadata };
let mock;
beforeEach(async () => {
await store.dispatch('setEndpoints', endpoints);
mock = new MockAdapter(axios);
mock.onGet(metadata).reply(200, mrMetadata);
});
afterEach(() => {
mock.restore();
});
it('should fetch the data from the API', async () => {
await store.dispatch('fetchMrMetadata');
await axios.waitForAll();
expect(mock.history.get).toHaveLength(1);
expect(mock.history.get[0].url).toBe(metadata);
});
it('should set the fetched data into state', async () => {
await store.dispatch('fetchMrMetadata');
expect(store.state.page.mrMetadata).toEqual(mrMetadata);
});
it('should set failedToLoadMetadata flag when request fails', async () => {
mock.onGet(metadata).reply(500);
await store.dispatch('fetchMrMetadata');
expect(store.state.page.failedToLoadMetadata).toBe(true);
});
});
});