diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-21 14:26:18 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-05-21 14:26:18 +0100 |
commit | 5ddedb6b8bf3f47c400e3d38e415462abefa3b50 (patch) | |
tree | f458e8cedf8d9be1a0b95804f22c0e7f4bcfb862 /spec/frontend/repository/components | |
parent | 729bac5e1643eb47e97ed1b9e2a90868cdbb2382 (diff) | |
download | gitlab-ce-5ddedb6b8bf3f47c400e3d38e415462abefa3b50.tar.gz |
Added tree list row component
Diffstat (limited to 'spec/frontend/repository/components')
-rw-r--r-- | spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap | 33 | ||||
-rw-r--r-- | spec/frontend/repository/components/table/row_spec.js | 85 |
2 files changed, 118 insertions, 0 deletions
diff --git a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap new file mode 100644 index 00000000000..f0b72343b6e --- /dev/null +++ b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Repository table row component renders table row 1`] = ` +<tr + class="tree-item file_1" +> + <td + class="tree-item-file-name" + > + <i + aria-label="file" + class="fa fa-fw fa-file-text-o" + role="img" + /> + + <a + class="str-truncated" + > + test + </a> + + <!----> + </td> + + <td + class="d-none d-sm-table-cell tree-commit" + /> + + <td + class="tree-time-ago text-right" + /> +</tr> +`; diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js new file mode 100644 index 00000000000..216128dce25 --- /dev/null +++ b/spec/frontend/repository/components/table/row_spec.js @@ -0,0 +1,85 @@ +import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import TableRow from '~/repository/components/table/row.vue'; + +let vm; +let $router; + +function factory(propsData = {}) { + $router = { + push: jest.fn(), + }; + + vm = shallowMount(TableRow, { + propsData, + mocks: { + $router, + }, + stubs: { + RouterLink: RouterLinkStub, + }, + }); + + vm.setData({ ref: 'master' }); +} + +describe('Repository table row component', () => { + afterEach(() => { + vm.destroy(); + }); + + it('renders table row', () => { + factory({ + id: 1, + path: 'test', + type: 'file', + }); + + expect(vm.element).toMatchSnapshot(); + }); + + it.each` + type | component | componentName + ${'folder'} | ${RouterLinkStub} | ${'RouterLink'} + ${'file'} | ${'a'} | ${'hyperlink'} + ${'commit'} | ${'a'} | ${'hyperlink'} + `('renders a $componentName for type $type', ({ type, component }) => { + factory({ + id: 1, + path: 'test', + type, + }); + + expect(vm.find(component).exists()).toBe(true); + }); + + it.each` + type | pushes + ${'folder'} | ${true} + ${'file'} | ${false} + ${'commit'} | ${false} + `('pushes new router if type $type is folder', ({ type, pushes }) => { + factory({ + id: 1, + path: 'test', + type, + }); + + vm.trigger('click'); + + if (pushes) { + expect($router.push).toHaveBeenCalledWith({ path: '/tree/master/test' }); + } else { + expect($router.push).not.toHaveBeenCalled(); + } + }); + + it('renders commit ID for submodule', () => { + factory({ + id: 1, + path: 'test', + type: 'commit', + }); + + expect(vm.find('.commit-sha').text()).toContain('1'); + }); +}); |