summaryrefslogtreecommitdiff
path: root/spec/frontend/notebook/cells
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notebook/cells')
-rw-r--r--spec/frontend/notebook/cells/code_spec.js6
-rw-r--r--spec/frontend/notebook/cells/output/index_spec.js54
-rw-r--r--spec/frontend/notebook/cells/output/latex_spec.js40
-rw-r--r--spec/frontend/notebook/cells/prompt_spec.js4
4 files changed, 84 insertions, 20 deletions
diff --git a/spec/frontend/notebook/cells/code_spec.js b/spec/frontend/notebook/cells/code_spec.js
index 33dabe2b6dc..e14767f2594 100644
--- a/spec/frontend/notebook/cells/code_spec.js
+++ b/spec/frontend/notebook/cells/code_spec.js
@@ -11,7 +11,7 @@ describe('Code component', () => {
json = getJSONFixture('blob/notebook/basic.json');
});
- const setupComponent = cell => {
+ const setupComponent = (cell) => {
const comp = new Component({
propsData: {
cell,
@@ -22,7 +22,7 @@ describe('Code component', () => {
};
describe('without output', () => {
- beforeEach(done => {
+ beforeEach((done) => {
vm = setupComponent(json.cells[0]);
setImmediate(() => {
@@ -36,7 +36,7 @@ describe('Code component', () => {
});
describe('with output', () => {
- beforeEach(done => {
+ beforeEach((done) => {
vm = setupComponent(json.cells[2]);
setImmediate(() => {
diff --git a/spec/frontend/notebook/cells/output/index_spec.js b/spec/frontend/notebook/cells/output/index_spec.js
index b9a2dfb8f34..2985abf0f4f 100644
--- a/spec/frontend/notebook/cells/output/index_spec.js
+++ b/spec/frontend/notebook/cells/output/index_spec.js
@@ -7,7 +7,7 @@ describe('Output component', () => {
let vm;
let json;
- const createComponent = output => {
+ const createComponent = (output) => {
vm = new Component({
propsData: {
outputs: [].concat(output),
@@ -18,12 +18,14 @@ describe('Output component', () => {
};
beforeEach(() => {
+ // This is the output after rendering a jupyter notebook
json = getJSONFixture('blob/notebook/basic.json');
});
describe('text output', () => {
- beforeEach(done => {
- createComponent(json.cells[2].outputs[0]);
+ beforeEach((done) => {
+ const textType = json.cells[2];
+ createComponent(textType.outputs[0]);
setImmediate(() => {
done();
@@ -40,8 +42,9 @@ describe('Output component', () => {
});
describe('image output', () => {
- beforeEach(done => {
- createComponent(json.cells[3].outputs[0]);
+ beforeEach((done) => {
+ const imageType = json.cells[3];
+ createComponent(imageType.outputs[0]);
setImmediate(() => {
done();
@@ -55,23 +58,42 @@ describe('Output component', () => {
describe('html output', () => {
it('renders raw HTML', () => {
- createComponent(json.cells[4].outputs[0]);
+ const htmlType = json.cells[4];
+ createComponent(htmlType.outputs[0]);
expect(vm.$el.querySelector('p')).not.toBeNull();
- expect(vm.$el.querySelectorAll('p').length).toBe(1);
+ expect(vm.$el.querySelectorAll('p')).toHaveLength(1);
expect(vm.$el.textContent.trim()).toContain('test');
});
it('renders multiple raw HTML outputs', () => {
- createComponent([json.cells[4].outputs[0], json.cells[4].outputs[0]]);
+ const htmlType = json.cells[4];
+ createComponent([htmlType.outputs[0], htmlType.outputs[0]]);
- expect(vm.$el.querySelectorAll('p').length).toBe(2);
+ expect(vm.$el.querySelectorAll('p')).toHaveLength(2);
+ });
+ });
+
+ describe('LaTeX output', () => {
+ it('renders LaTeX', () => {
+ const output = {
+ data: {
+ 'text/latex': ['$$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$$'],
+ 'text/plain': ['<IPython.core.display.Latex object>'],
+ },
+ metadata: {},
+ output_type: 'display_data',
+ };
+ createComponent(output);
+
+ expect(vm.$el.querySelector('.MathJax')).not.toBeNull();
});
});
describe('svg output', () => {
- beforeEach(done => {
- createComponent(json.cells[5].outputs[0]);
+ beforeEach((done) => {
+ const svgType = json.cells[5];
+ createComponent(svgType.outputs[0]);
setImmediate(() => {
done();
@@ -84,8 +106,9 @@ describe('Output component', () => {
});
describe('default to plain text', () => {
- beforeEach(done => {
- createComponent(json.cells[6].outputs[0]);
+ beforeEach((done) => {
+ const unknownType = json.cells[6];
+ createComponent(unknownType.outputs[0]);
setImmediate(() => {
done();
@@ -101,8 +124,9 @@ describe('Output component', () => {
expect(vm.$el.querySelector('.prompt span')).not.toBeNull();
});
- it("renders as plain text when doesn't recognise other types", done => {
- createComponent(json.cells[7].outputs[0]);
+ it("renders as plain text when doesn't recognise other types", (done) => {
+ const unknownType = json.cells[7];
+ createComponent(unknownType.outputs[0]);
setImmediate(() => {
expect(vm.$el.querySelector('pre')).not.toBeNull();
diff --git a/spec/frontend/notebook/cells/output/latex_spec.js b/spec/frontend/notebook/cells/output/latex_spec.js
new file mode 100644
index 00000000000..848d2069421
--- /dev/null
+++ b/spec/frontend/notebook/cells/output/latex_spec.js
@@ -0,0 +1,40 @@
+import { shallowMount } from '@vue/test-utils';
+import LatexOutput from '~/notebook/cells/output/latex.vue';
+import Prompt from '~/notebook/cells/prompt.vue';
+
+describe('LaTeX output cell', () => {
+ beforeEach(() => {
+ window.MathJax = {
+ tex2svg: jest.fn((code) => ({ outerHTML: code })),
+ };
+ });
+
+ const inlineLatex = '$$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$$';
+ const count = 12345;
+
+ const createComponent = (rawCode, index) =>
+ shallowMount(LatexOutput, {
+ propsData: {
+ count,
+ index,
+ rawCode,
+ },
+ });
+
+ it.each`
+ index | expectation
+ ${0} | ${true}
+ ${1} | ${false}
+ `('sets `Prompt.show-output` to $expectation when index is $index', ({ index, expectation }) => {
+ const wrapper = createComponent(inlineLatex, index);
+ const prompt = wrapper.find(Prompt);
+
+ expect(prompt.props().count).toEqual(count);
+ expect(prompt.props().showOutput).toEqual(expectation);
+ });
+
+ it('strips the `$$` delimter from LaTeX', () => {
+ createComponent(inlineLatex, 0);
+ expect(window.MathJax.tex2svg).toHaveBeenCalledWith(expect.not.stringContaining('$$'));
+ });
+});
diff --git a/spec/frontend/notebook/cells/prompt_spec.js b/spec/frontend/notebook/cells/prompt_spec.js
index cf5a7a603c6..8cdcd1f84de 100644
--- a/spec/frontend/notebook/cells/prompt_spec.js
+++ b/spec/frontend/notebook/cells/prompt_spec.js
@@ -7,7 +7,7 @@ describe('Prompt component', () => {
let vm;
describe('input', () => {
- beforeEach(done => {
+ beforeEach((done) => {
vm = new Component({
propsData: {
type: 'In',
@@ -31,7 +31,7 @@ describe('Prompt component', () => {
});
describe('output', () => {
- beforeEach(done => {
+ beforeEach((done) => {
vm = new Component({
propsData: {
type: 'Out',