gitlab-org--gitlab-foss/spec/javascripts/notebook/cells/markdown_spec.js

111 lines
2.2 KiB
JavaScript
Raw Normal View History

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