2020-10-24 23:57:45 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { createRouter } from '~/ide/ide_router';
|
|
|
|
import { createStore } from '~/ide/stores';
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
describe('IDE router', () => {
|
|
|
|
const PROJECT_NAMESPACE = 'my-group/sub-group';
|
|
|
|
const PROJECT_NAME = 'my-project';
|
2020-06-23 00:09:42 +05:30
|
|
|
const TEST_PATH = `/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/merge_requests/2`;
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
let store;
|
|
|
|
let router;
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
beforeEach(() => {
|
2018-11-18 11:00:15 +05:30
|
|
|
window.history.replaceState({}, '', '/');
|
2020-06-23 00:09:42 +05:30
|
|
|
store = createStore();
|
|
|
|
router = createRouter(store);
|
|
|
|
jest.spyOn(store, 'dispatch').mockReturnValue(new Promise(() => {}));
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
[
|
2021-09-04 01:27:46 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/main/-/src/blob/`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/main/-/src/blob`,
|
2018-11-18 11:00:15 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/blob/-/src/blob`,
|
2021-09-04 01:27:46 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/main/-/src/tree/`,
|
2018-11-18 11:00:15 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/weird:branch/name-123/-/src/tree/`,
|
2021-09-04 01:27:46 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/blob/main/-/src/blob`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/blob/main/-/src/edit`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/blob/main/-/src/merge_requests/2`,
|
2018-11-18 11:00:15 +05:30
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/blob/blob/-/src/blob`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/edit/blob/-/src/blob`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/merge_requests/2`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/tree/blob`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/edit`,
|
|
|
|
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`,
|
2021-03-08 18:12:59 +05:30
|
|
|
].forEach((route) => {
|
2018-11-18 11:00:15 +05:30
|
|
|
it(`finds project path when route is "${route}"`, () => {
|
|
|
|
router.push(route);
|
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('getProjectData', {
|
|
|
|
namespace: PROJECT_NAMESPACE,
|
|
|
|
projectId: PROJECT_NAME,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
it('keeps router in sync when store changes', async () => {
|
|
|
|
expect(router.currentRoute.fullPath).toBe('/');
|
|
|
|
|
|
|
|
store.state.router.fullPath = TEST_PATH;
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(router.currentRoute.fullPath).toBe(TEST_PATH);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('keeps store in sync when router changes', () => {
|
|
|
|
expect(store.dispatch).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
router.push(TEST_PATH);
|
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('router/push', TEST_PATH, { root: true });
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|