2021-01-03 14:25:43 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
|
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import actions from '~/whats_new/store/actions';
|
|
|
|
import * as types from '~/whats_new/store/mutation_types';
|
|
|
|
|
|
|
|
describe('whats new actions', () => {
|
|
|
|
describe('openDrawer', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
useLocalStorageSpy();
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('should commit openDrawer', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
testAction(actions.openDrawer, 'storage-key', {}, [{ type: types.OPEN_DRAWER }]);
|
|
|
|
|
|
|
|
expect(window.localStorage.setItem).toHaveBeenCalledWith('storage-key', 'false');
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('closeDrawer', () => {
|
|
|
|
it('should commit closeDrawer', () => {
|
|
|
|
testAction(actions.closeDrawer, {}, {}, [{ type: types.CLOSE_DRAWER }]);
|
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('fetchItems', () => {
|
|
|
|
let axiosMock;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
axiosMock = new MockAdapter(axios);
|
|
|
|
axiosMock
|
|
|
|
.onGet('/-/whats_new')
|
2021-01-29 00:20:46 +05:30
|
|
|
.replyOnce(200, [{ title: 'Whats New Drawer', url: 'www.url.com' }], {
|
|
|
|
'x-next-page': '2',
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('passes arguments', () => {
|
|
|
|
axiosMock.reset();
|
|
|
|
|
|
|
|
axiosMock
|
|
|
|
.onGet('/-/whats_new', { params: { page: 8, version: 40 } })
|
|
|
|
.replyOnce(200, [{ title: 'GitLab Stories' }]);
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
actions.fetchItems,
|
|
|
|
{ page: 8, version: 40 },
|
|
|
|
{},
|
|
|
|
expect.arrayContaining([
|
|
|
|
{ type: types.ADD_FEATURES, payload: [{ title: 'GitLab Stories' }] },
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('if already fetching, does not fetch', () => {
|
|
|
|
testAction(actions.fetchItems, {}, { fetching: true }, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should commit fetching, setFeatures and setPagination', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
testAction(actions.fetchItems, {}, {}, [
|
2021-01-29 00:20:46 +05:30
|
|
|
{ type: types.SET_FETCHING, payload: true },
|
|
|
|
{ type: types.ADD_FEATURES, payload: [{ title: 'Whats New Drawer', url: 'www.url.com' }] },
|
|
|
|
{ type: types.SET_PAGE_INFO, payload: { nextPage: 2 } },
|
|
|
|
{ type: types.SET_FETCHING, payload: false },
|
2021-01-03 14:25:43 +05:30
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
describe('setDrawerBodyHeight', () => {
|
|
|
|
testAction(actions.setDrawerBodyHeight, 42, {}, [
|
|
|
|
{ type: types.SET_DRAWER_BODY_HEIGHT, payload: 42 },
|
|
|
|
]);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|