summaryrefslogtreecommitdiff
path: root/spec/frontend/notebook/cells/output/latex_spec.js
blob: 848d206942127aa5ee1477a7a85835da1b9f0e9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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('$$'));
  });
});