debian-mirror-gitlab/spec/javascripts/blob/notebook/index_spec.js

151 lines
3.1 KiB
JavaScript
Raw Normal View History

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', () => {
preloadFixtures('static/notebook_viewer.html.raw');
beforeEach(() => {
loadFixtures('static/notebook_viewer.html.raw');
});
it('shows loading icon', () => {
renderNotebook();
expect(
document.querySelector('.loading'),
).not.toBeNull();
});
describe('successful response', () => {
2018-03-17 18:26:18 +05:30
let mock;
beforeEach((done) => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(200, {
2017-08-17 22:00:37 +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', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
});
it('renders the notebook', () => {
expect(
document.querySelector('.md'),
).not.toBeNull();
});
it('renders the markdown cell', () => {
expect(
document.querySelector('h1'),
).not.toBeNull();
expect(
document.querySelector('h1').textContent.trim(),
).toBe('test');
});
it('highlights code', () => {
expect(
document.querySelector('.token'),
).not.toBeNull();
expect(
document.querySelector('.language-python'),
).not.toBeNull();
});
});
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-11-08 19:23:39 +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', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
});
it('shows error message', () => {
expect(
document.querySelector('.md').textContent.trim(),
2018-03-17 18:26:18 +05:30
).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
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', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
});
it('shows error message', () => {
expect(
document.querySelector('.md').textContent.trim(),
2018-03-17 18:26:18 +05:30
).toBe('An error occurred whilst loading the file. Please try again later.');
2017-08-17 22:00:37 +05:30
});
});
});