2017-03-23 08:37:24 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
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', () => {
|
|
|
|
const response = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify({
|
|
|
|
cells: [{
|
|
|
|
cell_type: 'markdown',
|
|
|
|
source: ['# test'],
|
|
|
|
}, {
|
|
|
|
cell_type: 'code',
|
|
|
|
execution_count: 1,
|
|
|
|
source: [
|
|
|
|
'def test(str)',
|
|
|
|
' return str',
|
|
|
|
],
|
|
|
|
outputs: [],
|
|
|
|
}],
|
|
|
|
}), {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(response);
|
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, response,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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(
|
2017-03-23 13:24:24 -04:00
|
|
|
document.querySelector('.token'),
|
2017-03-23 08:37:24 -04:00
|
|
|
).not.toBeNull();
|
|
|
|
|
|
|
|
expect(
|
2017-03-23 13:24:24 -04:00
|
|
|
document.querySelector('.language-python'),
|
2017-03-23 08:37:24 -04:00
|
|
|
).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error in JSON response', () => {
|
|
|
|
const response = (request, next) => {
|
|
|
|
next(request.respondWith('{ "cells": [{"cell_type": "markdown"} }', {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(response);
|
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, response,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.loading'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.md').textContent.trim(),
|
2017-09-25 16:02:08 -04:00
|
|
|
).toBe('An error occurred whilst parsing the file.');
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error getting file', () => {
|
|
|
|
const response = (request, next) => {
|
|
|
|
next(request.respondWith('', {
|
|
|
|
status: 500,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(response);
|
|
|
|
|
|
|
|
renderNotebook();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, response,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.loading'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.md').textContent.trim(),
|
2017-09-25 16:02:08 -04:00
|
|
|
).toBe('An error occurred whilst loading the file. Please try again later.');
|
2017-03-23 08:37:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|