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';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
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(() => {
|
|
|
|
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(() => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(endpoint).reply(HTTP_STATUS_OK, mockNotebook);
|
2020-04-08 14:13:33 +05:30
|
|
|
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
|
2023-04-23 21:23:45 +05:30
|
|
|
Promise.reject({ status: HTTP_STATUS_OK }),
|
2020-04-08 14:13:33 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
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(() => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(endpoint).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR, '');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
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.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|