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

91 lines
2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
import CodeComponent from '~/notebook/cells/code.vue';
const Component = Vue.extend(CodeComponent);
describe('Code component', () => {
let vm;
let json;
beforeEach(() => {
json = getJSONFixture('blob/notebook/basic.json');
});
2020-04-22 19:07:51 +05:30
const setupComponent = cell => {
const comp = new Component({
propsData: {
cell,
},
});
comp.$mount();
return comp;
};
2017-08-17 22:00:37 +05:30
describe('without output', () => {
2018-12-13 13:39:08 +05:30
beforeEach(done => {
2020-04-22 19:07:51 +05:30
vm = setupComponent(json.cells[0]);
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
setImmediate(() => {
2017-08-17 22:00:37 +05:30
done();
});
});
it('does not render output prompt', () => {
expect(vm.$el.querySelectorAll('.prompt').length).toBe(1);
});
});
describe('with output', () => {
2018-12-13 13:39:08 +05:30
beforeEach(done => {
2020-04-22 19:07:51 +05:30
vm = setupComponent(json.cells[2]);
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
setImmediate(() => {
2017-08-17 22:00:37 +05:30
done();
});
});
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
beforeEach(() => {
const cell = json.cells[2];
cell.outputs[0].text = cell.outputs[0].text.join('');
vm = setupComponent(cell);
return vm.$nextTick();
});
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', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => {
2020-04-22 19:07:51 +05:30
const cell = json.cells[0];
cell.source = cell.source.join('');
vm = setupComponent(cell);
2020-05-24 23:13:21 +05:30
return vm.$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
});