2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import MarkdownComponent from '~/notebook/cells/markdown.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import katex from 'katex';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const Component = Vue.extend(MarkdownComponent);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
window.katex = katex;
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('Markdown component', () => {
|
|
|
|
let vm;
|
|
|
|
let cell;
|
|
|
|
let json;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
json = getJSONFixture('blob/notebook/basic.json');
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
// eslint-disable-next-line prefer-destructuring
|
2017-08-17 22:00:37 +05:30
|
|
|
cell = json.cells[1];
|
|
|
|
|
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
cell,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
vm.$mount();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render promot', () => {
|
|
|
|
expect(vm.$el.querySelector('.prompt span')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the markdown text', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.markdown').innerHTML.trim()).not.toEqual(cell.source.join(''));
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the markdown HTML', () => {
|
|
|
|
expect(vm.$el.querySelector('.markdown h1')).not.toBeNull();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('sanitizes output', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
Object.assign(cell, {
|
2018-12-13 13:39:08 +05:30
|
|
|
source: [
|
|
|
|
'[XSS](data:text/html;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5kb21haW4pPC9zY3JpcHQ+Cg==)\n',
|
|
|
|
],
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('a')).toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('katex', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
json = getJSONFixture('blob/notebook/math.json');
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders multi-line katex', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
cell: json.cells[0],
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.katex')).not.toBeNull();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders inline katex', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
cell: json.cells[1],
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('p:first-child .katex')).not.toBeNull();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders multiple inline katex', done => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
cell: json.cells[1],
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('p:nth-child(2) .katex').length).toBe(4);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|