2021-09-02 11:11:35 -04:00
|
|
|
import { mount } from '@vue/test-utils';
|
2017-04-11 13:50:21 -04:00
|
|
|
import Vue from 'vue';
|
2021-10-08 08:11:10 -04:00
|
|
|
import json from 'test_fixtures/blob/notebook/basic.json';
|
|
|
|
import jsonWithWorksheet from 'test_fixtures/blob/notebook/worksheets.json';
|
2017-04-11 13:50:21 -04:00
|
|
|
import Notebook from '~/notebook/index.vue';
|
|
|
|
|
|
|
|
const Component = Vue.extend(Notebook);
|
|
|
|
|
|
|
|
describe('Notebook component', () => {
|
|
|
|
let vm;
|
|
|
|
|
2021-09-02 11:11:35 -04:00
|
|
|
function buildComponent(notebook) {
|
|
|
|
return mount(Component, {
|
|
|
|
propsData: { notebook, codeCssClass: 'js-code-class' },
|
|
|
|
provide: { relativeRawPath: '' },
|
|
|
|
}).vm;
|
|
|
|
}
|
|
|
|
|
2017-04-11 13:50:21 -04:00
|
|
|
describe('without JSON', () => {
|
2020-12-23 19:10:25 -05:00
|
|
|
beforeEach((done) => {
|
2021-09-02 11:11:35 -04:00
|
|
|
vm = buildComponent({});
|
2017-04-11 13:50:21 -04:00
|
|
|
|
2020-05-08 05:09:39 -04:00
|
|
|
setImmediate(() => {
|
2017-04-11 13:50:21 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render', () => {
|
|
|
|
expect(vm.$el.tagName).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with JSON', () => {
|
2020-12-23 19:10:25 -05:00
|
|
|
beforeEach((done) => {
|
2021-09-02 11:11:35 -04:00
|
|
|
vm = buildComponent(json);
|
2017-04-11 13:50:21 -04:00
|
|
|
|
2020-05-08 05:09:39 -04:00
|
|
|
setImmediate(() => {
|
2017-04-11 13:50:21 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders cells', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.cell').length).toBe(json.cells.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders markdown cell', () => {
|
|
|
|
expect(vm.$el.querySelector('.markdown')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders code cell', () => {
|
|
|
|
expect(vm.$el.querySelector('pre')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add code class to code blocks', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with worksheets', () => {
|
2020-12-23 19:10:25 -05:00
|
|
|
beforeEach((done) => {
|
2021-09-02 11:11:35 -04:00
|
|
|
vm = buildComponent(jsonWithWorksheet);
|
2017-04-11 13:50:21 -04:00
|
|
|
|
2020-05-08 05:09:39 -04:00
|
|
|
setImmediate(() => {
|
2017-04-11 13:50:21 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders cells', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelectorAll('.cell').length).toBe(
|
|
|
|
jsonWithWorksheet.worksheets[0].cells.length,
|
|
|
|
);
|
2017-04-11 13:50:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders markdown cell', () => {
|
|
|
|
expect(vm.$el.querySelector('.markdown')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders code cell', () => {
|
|
|
|
expect(vm.$el.querySelector('pre')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add code class to code blocks', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|