2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-11-18 22:05:49 +05:30
|
|
|
import fixture from 'test_fixtures/blob/notebook/basic.json';
|
2017-08-17 22:00:37 +05:30
|
|
|
import CodeComponent from '~/notebook/cells/code.vue';
|
|
|
|
|
|
|
|
const Component = Vue.extend(CodeComponent);
|
|
|
|
|
|
|
|
describe('Code component', () => {
|
|
|
|
let vm;
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let json;
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const setupComponent = (cell) => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const comp = new Component({
|
|
|
|
propsData: {
|
|
|
|
cell,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
comp.$mount();
|
|
|
|
return comp;
|
|
|
|
};
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('without output', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(() => {
|
2020-04-22 19:07:51 +05:30
|
|
|
vm = setupComponent(json.cells[0]);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
return nextTick();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render output prompt', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.prompt').length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with output', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(() => {
|
2020-04-22 19:07:51 +05:30
|
|
|
vm = setupComponent(json.cells[2]);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
return nextTick();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render output prompt', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.prompt').length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders output cell', () => {
|
|
|
|
expect(vm.$el.querySelector('.output')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
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-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const cell = json.cells[2];
|
|
|
|
cell.outputs[0].text = cell.outputs[0].text.join('');
|
|
|
|
|
|
|
|
vm = setupComponent(cell);
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render output prompt', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.prompt').length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders output cell', () => {
|
|
|
|
expect(vm.$el.querySelector('.output')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('with string for cell.source', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const cell = json.cells[0];
|
|
|
|
cell.source = cell.source.join('');
|
|
|
|
|
|
|
|
vm = setupComponent(cell);
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the same input as when cell.source is an array', () => {
|
|
|
|
const expected = "console.log('test')";
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.input').innerText).toContain(expected);
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|