diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-14 03:09:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-14 03:09:30 +0300 |
commit | 8957ace3159e5369a700a77614493ed6a8a98f93 (patch) | |
tree | 98ff5be0caa30cfebb4e0cd0ae2ceaf21ce92eb4 /spec/frontend/blob/notebook/notebook_viever_spec.js | |
parent | 232e0a31f1e5d5b3a788dfc3dba8f8d41df36bf9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/blob/notebook/notebook_viever_spec.js')
-rw-r--r-- | spec/frontend/blob/notebook/notebook_viever_spec.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/spec/frontend/blob/notebook/notebook_viever_spec.js b/spec/frontend/blob/notebook/notebook_viever_spec.js new file mode 100644 index 00000000000..535d2bd544a --- /dev/null +++ b/spec/frontend/blob/notebook/notebook_viever_spec.js @@ -0,0 +1,108 @@ +import { shallowMount } from '@vue/test-utils'; +import { GlLoadingIcon } from '@gitlab/ui'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import component from '~/blob/notebook/notebook_viewer.vue'; +import NotebookLab from '~/notebook/index.vue'; +import waitForPromises from 'helpers/wait_for_promises'; + +describe('iPython notebook renderer', () => { + let wrapper; + let mock; + + const endpoint = 'test'; + const mockNotebook = { + cells: [ + { + cell_type: 'markdown', + source: ['# test'], + }, + { + cell_type: 'code', + execution_count: 1, + source: ['def test(str)', ' return str'], + outputs: [], + }, + ], + }; + + const mountComponent = () => { + wrapper = shallowMount(component, { propsData: { endpoint } }); + }; + + const findLoading = () => wrapper.find(GlLoadingIcon); + const findNotebookLab = () => wrapper.find(NotebookLab); + const findLoadErrorMessage = () => wrapper.find({ ref: 'loadErrorMessage' }); + const findParseErrorMessage = () => wrapper.find({ ref: 'parsingErrorMessage' }); + + beforeEach(() => { + mock = new MockAdapter(axios); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + mock.restore(); + }); + + it('shows loading icon', () => { + mock.onGet(endpoint).reply(() => new Promise(() => {})); + mountComponent({ loadFile: jest.fn() }); + expect(findLoading().exists()).toBe(true); + }); + + describe('successful response', () => { + beforeEach(() => { + mock.onGet(endpoint).reply(200, mockNotebook); + mountComponent(); + return waitForPromises(); + }); + + it('does not show loading icon', () => { + expect(findLoading().exists()).toBe(false); + }); + + it('renders the notebook', () => { + expect(findNotebookLab().exists()).toBe(true); + }); + }); + + describe('error in JSON response', () => { + beforeEach(() => { + mock.onGet(endpoint).reply(() => + // eslint-disable-next-line prefer-promise-reject-errors + Promise.reject({ status: 200 }), + ); + + mountComponent(); + return waitForPromises(); + }); + + it('does not show loading icon', () => { + expect(findLoading().exists()).toBe(false); + }); + + it('shows error message', () => { + expect(findParseErrorMessage().text()).toEqual('An error occurred while parsing the file.'); + }); + }); + + describe('error getting file', () => { + beforeEach(() => { + mock.onGet(endpoint).reply(500, ''); + + mountComponent(); + return waitForPromises(); + }); + + it('does not show loading icon', () => { + expect(findLoading().exists()).toBe(false); + }); + + it('shows error message', () => { + expect(findLoadErrorMessage().text()).toEqual( + 'An error occurred while loading the file. Please try again later.', + ); + }); + }); +}); |