diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2019-05-30 09:02:51 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2019-05-30 09:02:51 +0000 |
commit | 38319ae7dda547062a671e4bcd2177d6dd96075e (patch) | |
tree | b2bac35e7d5cbe4e6d22d2e96435d9c1468c63e0 /spec | |
parent | 0e2336442636cdb7f5082b652ff5332d78855e9a (diff) | |
parent | 2cf3fbcfb4a19169713382e3e27e43b9dfce6baa (diff) | |
download | gitlab-ce-38319ae7dda547062a671e4bcd2177d6dd96075e.tar.gz |
Merge branch 'vue-repo-parent-row-fixes' into 'master'
Fixes bug with parent row component triggering multiple Vue router pushes
See merge request gitlab-org/gitlab-ce!28882
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/repository/components/table/parent_row_spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
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', + }); + }); +}); |