debian-mirror-gitlab/spec/frontend/blob/notebook/notebook_viever_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-04-08 14:13:33 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-10-24 23:57:45 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2020-04-08 14:13:33 +05:30
import component from '~/blob/notebook/notebook_viewer.vue';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2020-04-08 14:13:33 +05:30
import NotebookLab from '~/notebook/index.vue';
describe('iPython notebook renderer', () => {
let wrapper;
let mock;
const endpoint = 'test';
2021-11-11 11:23:49 +05:30
const relativeRawPath = '';
2020-04-08 14:13:33 +05:30
const mockNotebook = {
cells: [
{
cell_type: 'markdown',
source: ['# test'],
},
{
cell_type: 'code',
execution_count: 1,
source: ['def test(str)', ' return str'],
outputs: [],
},
],
};
const mountComponent = () => {
2021-11-11 11:23:49 +05:30
wrapper = shallowMount(component, { propsData: { endpoint, relativeRawPath } });
2020-04-08 14:13:33 +05:30
};
2022-08-27 11:52:29 +05:30
const findLoading = () => wrapper.findComponent(GlLoadingIcon);
const findNotebookLab = () => wrapper.findComponent(NotebookLab);
const findLoadErrorMessage = () => wrapper.findComponent({ ref: 'loadErrorMessage' });
const findParseErrorMessage = () => wrapper.findComponent({ ref: 'parsingErrorMessage' });
2020-04-08 14:13:33 +05:30
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.',
);
});
});
});