diff options
Diffstat (limited to 'spec/frontend/ci/catalog/index_spec.js')
-rw-r--r-- | spec/frontend/ci/catalog/index_spec.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/frontend/ci/catalog/index_spec.js b/spec/frontend/ci/catalog/index_spec.js new file mode 100644 index 00000000000..01332cfbb3d --- /dev/null +++ b/spec/frontend/ci/catalog/index_spec.js @@ -0,0 +1,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); + }); + }); + }); +}); |