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