diff options
Diffstat (limited to 'spec/frontend')
5 files changed, 168 insertions, 0 deletions
diff --git a/spec/frontend/ide/stores/mutations/branch_spec.js b/spec/frontend/ide/stores/mutations/branch_spec.js index 29eb859ddaf..0900b25d5d3 100644 --- a/spec/frontend/ide/stores/mutations/branch_spec.js +++ b/spec/frontend/ide/stores/mutations/branch_spec.js @@ -37,4 +37,39 @@ describe('Multi-file store branch mutations', () => { expect(localState.projects.Example.branches.master.commit.title).toBe('Example commit'); }); }); + + describe('SET_BRANCH_WORKING_REFERENCE', () => { + beforeEach(() => { + localState.projects = { + Foo: { + branches: { + bar: {}, + }, + }, + }; + }); + + it('sets workingReference for existing branch', () => { + mutations.SET_BRANCH_WORKING_REFERENCE(localState, { + projectId: 'Foo', + branchId: 'bar', + reference: 'foo-bar-ref', + }); + + expect(localState.projects.Foo.branches.bar.workingReference).toBe('foo-bar-ref'); + }); + + it('does not fail on non-existent just yet branch', () => { + expect(localState.projects.Foo.branches.unknown).toBeUndefined(); + + mutations.SET_BRANCH_WORKING_REFERENCE(localState, { + projectId: 'Foo', + branchId: 'unknown', + reference: 'fun-fun-ref', + }); + + expect(localState.projects.Foo.branches.unknown).not.toBeUndefined(); + expect(localState.projects.Foo.branches.unknown.workingReference).toBe('fun-fun-ref'); + }); + }); }); diff --git a/spec/frontend/ide/stores/mutations/project_spec.js b/spec/frontend/ide/stores/mutations/project_spec.js new file mode 100644 index 00000000000..b3ce39c33d2 --- /dev/null +++ b/spec/frontend/ide/stores/mutations/project_spec.js @@ -0,0 +1,23 @@ +import mutations from '~/ide/stores/mutations/project'; +import state from '~/ide/stores/state'; + +describe('Multi-file store branch mutations', () => { + let localState; + + beforeEach(() => { + localState = state(); + localState.projects = { abcproject: { empty_repo: true } }; + }); + + describe('TOGGLE_EMPTY_STATE', () => { + it('sets empty_repo for project to passed value', () => { + mutations.TOGGLE_EMPTY_STATE(localState, { projectPath: 'abcproject', value: false }); + + expect(localState.projects.abcproject.empty_repo).toBe(false); + + mutations.TOGGLE_EMPTY_STATE(localState, { projectPath: 'abcproject', value: true }); + + expect(localState.projects.abcproject.empty_repo).toBe(true); + }); + }); +}); diff --git a/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap b/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap index 5f9f13d591d..a2a7d0ee91e 100644 --- a/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap +++ b/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap @@ -3,6 +3,7 @@ exports[`MR Popover loaded state matches the snapshot 1`] = ` <glpopover-stub boundary="viewport" + cssclasses="" placement="top" show="" target="" @@ -61,6 +62,7 @@ exports[`MR Popover loaded state matches the snapshot 1`] = ` exports[`MR Popover shows skeleton-loader while apollo is loading 1`] = ` <glpopover-stub boundary="viewport" + cssclasses="" placement="top" show="" target="" diff --git a/spec/frontend/repository/components/breadcrumbs_spec.js b/spec/frontend/repository/components/breadcrumbs_spec.js new file mode 100644 index 00000000000..068fa317a87 --- /dev/null +++ b/spec/frontend/repository/components/breadcrumbs_spec.js @@ -0,0 +1,44 @@ +import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import Breadcrumbs from '~/repository/components/breadcrumbs.vue'; + +let vm; + +function factory(currentPath) { + vm = shallowMount(Breadcrumbs, { + propsData: { + currentPath, + }, + stubs: { + RouterLink: RouterLinkStub, + }, + }); +} + +describe('Repository breadcrumbs component', () => { + afterEach(() => { + vm.destroy(); + }); + + it.each` + path | linkCount + ${'/'} | ${1} + ${'app'} | ${2} + ${'app/assets'} | ${3} + ${'app/assets/javascripts'} | ${4} + `('renders $linkCount links for path $path', ({ path, linkCount }) => { + factory(path); + + expect(vm.findAll(RouterLinkStub).length).toEqual(linkCount); + }); + + it('renders last link as active', () => { + factory('app/assets'); + + expect( + vm + .findAll(RouterLinkStub) + .at(2) + .attributes('aria-current'), + ).toEqual('page'); + }); +}); diff --git a/spec/frontend/repository/components/table/parent_row_spec.js b/spec/frontend/repository/components/table/parent_row_spec.js new file mode 100644 index 00000000000..7020055271f --- /dev/null +++ b/spec/frontend/repository/components/table/parent_row_spec.js @@ -0,0 +1,64 @@ +import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import ParentRow from '~/repository/components/table/parent_row.vue'; + +let vm; +let $router; + +function factory(path) { + $router = { + push: jest.fn(), + }; + + vm = shallowMount(ParentRow, { + propsData: { + commitRef: 'master', + path, + }, + stubs: { + RouterLink: RouterLinkStub, + }, + mocks: { + $router, + }, + }); +} + +describe('Repository parent row component', () => { + afterEach(() => { + vm.destroy(); + }); + + it.each` + path | to + ${'app'} | ${'/tree/master/'} + ${'app/assets'} | ${'/tree/master/app'} + `('renders link in $path to $to', ({ path, to }) => { + factory(path); + + expect(vm.find(RouterLinkStub).props().to).toEqual({ + path: to, + }); + }); + + it('pushes new router when clicking row', () => { + factory('app/assets'); + + vm.find('td').trigger('click'); + + expect($router.push).toHaveBeenCalledWith({ + path: '/tree/master/app', + }); + }); + + // We test that it does not get called when clicking any internal + // links as this was causing multipe routes to get pushed + it('does not trigger router.push when clicking link', () => { + factory('app/assets'); + + vm.find('a').trigger('click'); + + expect($router.push).not.toHaveBeenCalledWith({ + path: '/tree/master/app', + }); + }); +}); |