debian-mirror-gitlab/spec/frontend/notebook/cells/code_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import { mount } from '@vue/test-utils';
2021-11-18 22:05:49 +05:30
import fixture from 'test_fixtures/blob/notebook/basic.json';
2022-08-13 15:12:31 +05:30
import Code from '~/notebook/cells/code.vue';
2017-08-17 22:00:37 +05:30
describe('Code component', () => {
2022-08-13 15:12:31 +05:30
let wrapper;
2017-08-17 22:00:37 +05:30
let json;
2022-08-13 15:12:31 +05:30
const mountComponent = (cell) => mount(Code, { propsData: { cell } });
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2021-11-18 22:05:49 +05:30
// Clone fixture as it could be modified by tests
json = JSON.parse(JSON.stringify(fixture));
2017-08-17 22:00:37 +05:30
});
2022-08-13 15:12:31 +05:30
afterEach(() => {
wrapper.destroy();
});
2020-04-22 19:07:51 +05:30
2017-08-17 22:00:37 +05:30
describe('without output', () => {
2022-04-04 11:22:00 +05:30
beforeEach(() => {
2022-08-13 15:12:31 +05:30
wrapper = mountComponent(json.cells[0]);
2017-08-17 22:00:37 +05:30
});
it('does not render output prompt', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.findAll('.prompt')).toHaveLength(1);
2017-08-17 22:00:37 +05:30
});
});
describe('with output', () => {
2022-04-04 11:22:00 +05:30
beforeEach(() => {
2022-08-13 15:12:31 +05:30
wrapper = mountComponent(json.cells[2]);
2017-08-17 22:00:37 +05:30
});
it('does not render output prompt', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.findAll('.prompt')).toHaveLength(2);
2017-08-17 22:00:37 +05:30
});
it('renders output cell', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.find('.output').exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
});
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
describe('with string for output', () => {
// NBFormat Version 4.1 allows outputs.text to be a string
2022-08-13 15:12:31 +05:30
beforeEach(() => {
2020-05-24 23:13:21 +05:30
const cell = json.cells[2];
cell.outputs[0].text = cell.outputs[0].text.join('');
2022-08-13 15:12:31 +05:30
wrapper = mountComponent(cell);
2020-05-24 23:13:21 +05:30
});
it('does not render output prompt', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.findAll('.prompt')).toHaveLength(2);
2020-05-24 23:13:21 +05:30
});
it('renders output cell', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.find('.output').exists()).toBe(true);
2020-05-24 23:13:21 +05:30
});
});
2020-04-22 19:07:51 +05:30
describe('with string for cell.source', () => {
2022-08-13 15:12:31 +05:30
beforeEach(() => {
2020-04-22 19:07:51 +05:30
const cell = json.cells[0];
cell.source = cell.source.join('');
2022-08-13 15:12:31 +05:30
wrapper = mountComponent(cell);
2020-04-22 19:07:51 +05:30
});
it('renders the same input as when cell.source is an array', () => {
2022-08-13 15:12:31 +05:30
expect(wrapper.find('.input').text()).toContain("console.log('test')");
2020-04-22 19:07:51 +05:30
});
});
2017-08-17 22:00:37 +05:30
});