2017-12-15 02:10:34 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-03-23 08:37:24 -04:00
|
|
|
import renderNotebook from '~/blob/notebook';
|
|
|
|
|
|
|
|
describe('iPython notebook renderer', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
preloadFixtures('static/notebook_viewer.html');
|
2017-03-23 08:37:24 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('static/notebook_viewer.html');
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows loading icon', () => {
|
|
|
|
renderNotebook();
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.loading')).not.toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('successful response', () => {
|
2017-12-15 02:10:34 -05:00
|
|
|
let mock;
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(done => {
|
2017-12-15 02:10:34 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet('/test').reply(200, {
|
2018-10-17 03:13:26 -04:00
|
|
|
cells: [
|
|
|
|
{
|
|
|
|
cell_type: 'markdown',
|
|
|
|
source: ['# test'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cell_type: 'code',
|
|
|
|
execution_count: 1,
|
|
|
|
source: ['def test(str)', ' return str'],
|
|
|
|
outputs: [],
|
|
|
|
},
|
|
|
|
],
|
2017-12-15 02:10:34 -05:00
|
|
|
});
|
2017-03-23 08:37:24 -04:00
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.loading')).toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the notebook', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.md')).not.toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the markdown cell', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('h1')).not.toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('h1').textContent.trim()).toBe('test');
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('highlights code', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.token')).not.toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.language-python')).not.toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error in JSON response', () => {
|
2017-12-15 02:10:34 -05:00
|
|
|
let mock;
|
2017-03-23 08:37:24 -04:00
|
|
|
|
2018-05-28 07:41:30 -04:00
|
|
|
beforeEach(done => {
|
2017-12-15 02:10:34 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-10-17 03:13:26 -04:00
|
|
|
mock.onGet('/test').reply(() =>
|
|
|
|
// eslint-disable-next-line prefer-promise-reject-errors
|
|
|
|
Promise.reject({ status: 200, data: '{ "cells": [{"cell_type": "markdown"} }' }),
|
|
|
|
);
|
2017-03-23 08:37:24 -04:00
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.loading')).toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.md').textContent.trim()).toBe(
|
|
|
|
'An error occurred whilst parsing the file.',
|
|
|
|
);
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error getting file', () => {
|
2017-12-15 02:10:34 -05:00
|
|
|
let mock;
|
2017-03-23 08:37:24 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(done => {
|
2017-12-15 02:10:34 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet('/test').reply(500, '');
|
2017-03-23 08:37:24 -04:00
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.loading')).toBeNull();
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.md').textContent.trim()).toBe(
|
|
|
|
'An error occurred whilst loading the file. Please try again later.',
|
|
|
|
);
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|