diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:08 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:08 +0000 |
commit | 7671216b60e2796a050358ff808b4a0c2de3d22f (patch) | |
tree | 605dfc1339a3cd7dc7353ac6d725191086a9acca /spec/frontend/vue_shared | |
parent | c2367afbf57ebc65d5b78a743b5d6a91f0aece9f (diff) | |
download | gitlab-ce-7671216b60e2796a050358ff808b4a0c2de3d22f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared')
-rw-r--r-- | spec/frontend/vue_shared/components/file_row_spec.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/file_row_spec.js b/spec/frontend/vue_shared/components/file_row_spec.js new file mode 100644 index 00000000000..420281e844c --- /dev/null +++ b/spec/frontend/vue_shared/components/file_row_spec.js @@ -0,0 +1,90 @@ +import { file } from 'jest/ide/helpers'; +import FileRow from '~/vue_shared/components/file_row.vue'; +import { mount } from '@vue/test-utils'; + +describe('File row component', () => { + let wrapper; + + function createComponent(propsData) { + wrapper = mount(FileRow, { + propsData, + }); + } + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders name', () => { + const fileName = 't4'; + createComponent({ + file: file(fileName), + level: 0, + }); + + const name = wrapper.find('.file-row-name'); + + expect(name.text().trim()).toEqual(fileName); + }); + + it('emits toggleTreeOpen on click', () => { + const fileName = 't3'; + createComponent({ + file: { + ...file(fileName), + type: 'tree', + }, + level: 0, + }); + jest.spyOn(wrapper.vm, '$emit'); + + wrapper.element.click(); + + expect(wrapper.vm.$emit).toHaveBeenCalledWith('toggleTreeOpen', fileName); + }); + + it('calls scrollIntoView if made active', () => { + createComponent({ + file: { + ...file(), + type: 'blob', + active: false, + }, + level: 0, + }); + + jest.spyOn(wrapper.vm, 'scrollIntoView'); + + wrapper.setProps({ + file: Object.assign({}, wrapper.props('file'), { + active: true, + }), + }); + + return wrapper.vm.$nextTick().then(() => { + expect(wrapper.vm.scrollIntoView).toHaveBeenCalled(); + }); + }); + + it('indents row based on level', () => { + createComponent({ + file: file('t4'), + level: 2, + }); + + expect(wrapper.find('.file-row-name').element.style.marginLeft).toBe('32px'); + }); + + it('renders header for file', () => { + createComponent({ + file: { + isHeader: true, + path: 'app/assets', + tree: [], + }, + level: 0, + }); + + expect(wrapper.element.classList).toContain('js-file-row-header'); + }); +}); |