diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/frontend/blob/csv/csv_viewer_spec.js | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/frontend/blob/csv/csv_viewer_spec.js')
-rw-r--r-- | spec/frontend/blob/csv/csv_viewer_spec.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/frontend/blob/csv/csv_viewer_spec.js b/spec/frontend/blob/csv/csv_viewer_spec.js new file mode 100644 index 00000000000..abb914b8f57 --- /dev/null +++ b/spec/frontend/blob/csv/csv_viewer_spec.js @@ -0,0 +1,75 @@ +import { GlAlert, GlLoadingIcon, GlTable } from '@gitlab/ui'; +import { getAllByRole } from '@testing-library/dom'; +import { shallowMount, mount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import CSVViewer from '~/blob/csv/csv_viewer.vue'; + +const validCsv = 'one,two,three'; +const brokenCsv = '{\n "json": 1,\n "key": [1, 2, 3]\n}'; + +describe('app/assets/javascripts/blob/csv/csv_viewer.vue', () => { + let wrapper; + + const createComponent = ({ csv = validCsv, mountFunction = shallowMount } = {}) => { + wrapper = mountFunction(CSVViewer, { + propsData: { + csv, + }, + }); + }; + + const findCsvTable = () => wrapper.findComponent(GlTable); + const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); + const findAlert = () => wrapper.findComponent(GlAlert); + + afterEach(() => { + wrapper.destroy(); + }); + + it('should render loading spinner', () => { + createComponent(); + + expect(findLoadingIcon().props()).toMatchObject({ + size: 'lg', + }); + }); + + describe('when the CSV contains errors', () => { + it('should render alert', async () => { + createComponent({ csv: brokenCsv }); + await nextTick; + + expect(findAlert().props()).toMatchObject({ + variant: 'danger', + }); + }); + }); + + describe('when the CSV contains no errors', () => { + it('should not render alert', async () => { + createComponent(); + await nextTick; + + expect(findAlert().exists()).toBe(false); + }); + + it('renders the CSV table with the correct attributes', async () => { + createComponent(); + await nextTick; + + expect(findCsvTable().attributes()).toMatchObject({ + 'empty-text': 'No CSV data to display.', + items: validCsv, + }); + }); + + it('renders the CSV table with the correct content', async () => { + createComponent({ mountFunction: mount }); + await nextTick; + + expect(getAllByRole(wrapper.element, 'row', { name: /One/i })).toHaveLength(1); + expect(getAllByRole(wrapper.element, 'row', { name: /Two/i })).toHaveLength(1); + expect(getAllByRole(wrapper.element, 'row', { name: /Three/i })).toHaveLength(1); + }); + }); +}); |