blob: 01332cfbb3d88ca5c868444d7d795f11da2fdfce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import Vue from 'vue';
import { initCatalog } from '~/ci/catalog/';
import * as Router from '~/ci/catalog/router';
import CiResourcesPage from '~/ci/catalog/components/pages/ci_resources_page.vue';
describe('~/ci/catalog/index', () => {
describe('initCatalog', () => {
const SELECTOR = 'SELECTOR';
let el;
let component;
const baseRoute = '/explore/catalog';
const createElement = () => {
el = document.createElement('div');
el.id = SELECTOR;
el.dataset.ciCatalogPath = baseRoute;
document.body.appendChild(el);
};
afterEach(() => {
el = null;
});
describe('when the element exists', () => {
beforeEach(() => {
createElement();
jest.spyOn(Router, 'createRouter');
component = initCatalog(`#${SELECTOR}`);
});
it('returns a Vue Instance', () => {
expect(component).toBeInstanceOf(Vue);
});
it('creates a router with the received base path and component', () => {
expect(Router.createRouter).toHaveBeenCalledTimes(1);
expect(Router.createRouter).toHaveBeenCalledWith(baseRoute, CiResourcesPage);
});
});
describe('When the element does not exist', () => {
it('returns `null`', () => {
expect(initCatalog('foo')).toBe(null);
});
});
});
});
|