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