Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/ide/ide_router_spec.js')
-rw-r--r--spec/frontend/ide/ide_router_spec.js37
1 files changed, 28 insertions, 9 deletions
diff --git a/spec/frontend/ide/ide_router_spec.js b/spec/frontend/ide/ide_router_spec.js
index 1461b756d13..b53e2019819 100644
--- a/spec/frontend/ide/ide_router_spec.js
+++ b/spec/frontend/ide/ide_router_spec.js
@@ -1,17 +1,20 @@
-import router from '~/ide/ide_router';
-import store from '~/ide/stores';
+import { createRouter } from '~/ide/ide_router';
+import { createStore } from '~/ide/stores';
+import waitForPromises from 'helpers/wait_for_promises';
describe('IDE router', () => {
const PROJECT_NAMESPACE = 'my-group/sub-group';
const PROJECT_NAME = 'my-project';
+ const TEST_PATH = `/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}/merge_requests/2`;
- afterEach(() => {
- router.push('/');
- });
+ let store;
+ let router;
- afterAll(() => {
- // VueRouter leaves this window.history at the "base" url. We need to clean this up.
+ beforeEach(() => {
window.history.replaceState({}, '', '/');
+ store = createStore();
+ router = createRouter(store);
+ jest.spyOn(store, 'dispatch').mockReturnValue(new Promise(() => {}));
});
[
@@ -31,8 +34,6 @@ describe('IDE router', () => {
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`,
].forEach(route => {
it(`finds project path when route is "${route}"`, () => {
- jest.spyOn(store, 'dispatch').mockReturnValue(new Promise(() => {}));
-
router.push(route);
expect(store.dispatch).toHaveBeenCalledWith('getProjectData', {
@@ -41,4 +42,22 @@ describe('IDE router', () => {
});
});
});
+
+ 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 });
+ });
});