summaryrefslogtreecommitdiff
path: root/spec/javascripts/notebook
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/notebook')
-rw-r--r--spec/javascripts/notebook/cells/code_spec.js74
-rw-r--r--spec/javascripts/notebook/cells/markdown_spec.js105
-rw-r--r--spec/javascripts/notebook/cells/output/html_sanitize_tests.js68
-rw-r--r--spec/javascripts/notebook/cells/output/html_spec.js31
-rw-r--r--spec/javascripts/notebook/cells/output/index_spec.js115
-rw-r--r--spec/javascripts/notebook/cells/prompt_spec.js56
-rw-r--r--spec/javascripts/notebook/index_spec.js100
7 files changed, 0 insertions, 549 deletions
diff --git a/spec/javascripts/notebook/cells/code_spec.js b/spec/javascripts/notebook/cells/code_spec.js
deleted file mode 100644
index f3f97145ad3..00000000000
--- a/spec/javascripts/notebook/cells/code_spec.js
+++ /dev/null
@@ -1,74 +0,0 @@
-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');
- });
-
- const setupComponent = cell => {
- const comp = new Component({
- propsData: {
- cell,
- },
- });
- comp.$mount();
- return comp;
- };
-
- describe('without output', () => {
- beforeEach(done => {
- vm = setupComponent(json.cells[0]);
-
- setTimeout(() => {
- done();
- });
- });
-
- it('does not render output prompt', () => {
- expect(vm.$el.querySelectorAll('.prompt').length).toBe(1);
- });
- });
-
- describe('with output', () => {
- beforeEach(done => {
- vm = setupComponent(json.cells[2]);
-
- setTimeout(() => {
- 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();
- });
- });
-
- describe('with string for cell.source', () => {
- beforeEach(done => {
- const cell = json.cells[0];
- cell.source = cell.source.join('');
-
- vm = setupComponent(cell);
-
- setTimeout(() => {
- done();
- });
- });
-
- 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);
- });
- });
-});
diff --git a/spec/javascripts/notebook/cells/markdown_spec.js b/spec/javascripts/notebook/cells/markdown_spec.js
deleted file mode 100644
index 07b18d97cd9..00000000000
--- a/spec/javascripts/notebook/cells/markdown_spec.js
+++ /dev/null
@@ -1,105 +0,0 @@
-import Vue from 'vue';
-import katex from 'katex';
-import MarkdownComponent from '~/notebook/cells/markdown.vue';
-
-const Component = Vue.extend(MarkdownComponent);
-
-window.katex = katex;
-
-describe('Markdown component', () => {
- let vm;
- let cell;
- let json;
-
- beforeEach(done => {
- json = getJSONFixture('blob/notebook/basic.json');
-
- // eslint-disable-next-line prefer-destructuring
- cell = json.cells[1];
-
- vm = new Component({
- propsData: {
- cell,
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('does not render promot', () => {
- expect(vm.$el.querySelector('.prompt span')).toBeNull();
- });
-
- it('does not render the markdown text', () => {
- expect(vm.$el.querySelector('.markdown').innerHTML.trim()).not.toEqual(cell.source.join(''));
- });
-
- it('renders the markdown HTML', () => {
- expect(vm.$el.querySelector('.markdown h1')).not.toBeNull();
- });
-
- it('sanitizes output', done => {
- Object.assign(cell, {
- source: [
- '[XSS](data:text/html;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5kb21haW4pPC9zY3JpcHQ+Cg==)\n',
- ],
- });
-
- Vue.nextTick(() => {
- expect(vm.$el.querySelector('a').getAttribute('href')).toBeNull();
-
- done();
- });
- });
-
- describe('katex', () => {
- beforeEach(() => {
- json = getJSONFixture('blob/notebook/math.json');
- });
-
- it('renders multi-line katex', done => {
- vm = new Component({
- propsData: {
- cell: json.cells[0],
- },
- }).$mount();
-
- Vue.nextTick(() => {
- expect(vm.$el.querySelector('.katex')).not.toBeNull();
-
- done();
- });
- });
-
- it('renders inline katex', done => {
- vm = new Component({
- propsData: {
- cell: json.cells[1],
- },
- }).$mount();
-
- Vue.nextTick(() => {
- expect(vm.$el.querySelector('p:first-child .katex')).not.toBeNull();
-
- done();
- });
- });
-
- it('renders multiple inline katex', done => {
- vm = new Component({
- propsData: {
- cell: json.cells[1],
- },
- }).$mount();
-
- Vue.nextTick(() => {
- expect(vm.$el.querySelectorAll('p:nth-child(2) .katex').length).toBe(4);
-
- done();
- });
- });
- });
-});
diff --git a/spec/javascripts/notebook/cells/output/html_sanitize_tests.js b/spec/javascripts/notebook/cells/output/html_sanitize_tests.js
deleted file mode 100644
index 74c48f04367..00000000000
--- a/spec/javascripts/notebook/cells/output/html_sanitize_tests.js
+++ /dev/null
@@ -1,68 +0,0 @@
-export default {
- 'protocol-based JS injection: simple, no spaces': {
- input: '<a href="javascript:alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: simple, spaces before': {
- input: '<a href="javascript :alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: simple, spaces after': {
- input: '<a href="javascript: alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: simple, spaces before and after': {
- input: '<a href="javascript : alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: preceding colon': {
- input: '<a href=":javascript:alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: UTF-8 encoding': {
- input: '<a href="javascript&#58;">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: long UTF-8 encoding': {
- input: '<a href="javascript&#0058;">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: long UTF-8 encoding without semicolons': {
- input:
- '<a href=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: hex encoding': {
- input: '<a href="javascript&#x3A;">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: long hex encoding': {
- input: '<a href="javascript&#x003A;">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: hex encoding without semicolons': {
- input:
- '<a href=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: null char': {
- input: '<a href=java\0script:alert("XSS")>foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: invalid URL char': {
- input: '<img src=javascript:alert("XSS")>',
- output: '<img>',
- },
- 'protocol-based JS injection: Unicode': {
- input: '<a href="\u0001java\u0003script:alert(\'XSS\')">foo</a>',
- output: '<a>foo</a>',
- },
- 'protocol-based JS injection: spaces and entities': {
- input: '<a href=" &#14; javascript:alert(\'XSS\');">foo</a>',
- output: '<a>foo</a>',
- },
- 'img on error': {
- input: '<img src="x" onerror="alert(document.domain)" />',
- output: '<img src="x">',
- },
-};
diff --git a/spec/javascripts/notebook/cells/output/html_spec.js b/spec/javascripts/notebook/cells/output/html_spec.js
deleted file mode 100644
index 3ee404fb187..00000000000
--- a/spec/javascripts/notebook/cells/output/html_spec.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import Vue from 'vue';
-import htmlOutput from '~/notebook/cells/output/html.vue';
-import sanitizeTests from './html_sanitize_tests';
-
-describe('html output cell', () => {
- function createComponent(rawCode) {
- const Component = Vue.extend(htmlOutput);
-
- return new Component({
- propsData: {
- rawCode,
- count: 0,
- index: 0,
- },
- }).$mount();
- }
-
- describe('sanitizes output', () => {
- Object.keys(sanitizeTests).forEach(key => {
- it(key, () => {
- const test = sanitizeTests[key];
- const vm = createComponent(test.input);
- const outputEl = [...vm.$el.querySelectorAll('div')].pop();
-
- expect(outputEl.innerHTML).toEqual(test.output);
-
- vm.$destroy();
- });
- });
- });
-});
diff --git a/spec/javascripts/notebook/cells/output/index_spec.js b/spec/javascripts/notebook/cells/output/index_spec.js
deleted file mode 100644
index 005569f1c2d..00000000000
--- a/spec/javascripts/notebook/cells/output/index_spec.js
+++ /dev/null
@@ -1,115 +0,0 @@
-import Vue from 'vue';
-import CodeComponent from '~/notebook/cells/output/index.vue';
-
-const Component = Vue.extend(CodeComponent);
-
-describe('Output component', () => {
- let vm;
- let json;
-
- const createComponent = output => {
- vm = new Component({
- propsData: {
- outputs: [].concat(output),
- count: 1,
- },
- });
- vm.$mount();
- };
-
- beforeEach(() => {
- json = getJSONFixture('blob/notebook/basic.json');
- });
-
- describe('text output', () => {
- beforeEach(done => {
- createComponent(json.cells[2].outputs[0]);
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders as plain text', () => {
- expect(vm.$el.querySelector('pre')).not.toBeNull();
- });
-
- it('renders promot', () => {
- expect(vm.$el.querySelector('.prompt span')).not.toBeNull();
- });
- });
-
- describe('image output', () => {
- beforeEach(done => {
- createComponent(json.cells[3].outputs[0]);
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders as an image', () => {
- expect(vm.$el.querySelector('img')).not.toBeNull();
- });
- });
-
- describe('html output', () => {
- it('renders raw HTML', () => {
- createComponent(json.cells[4].outputs[0]);
-
- expect(vm.$el.querySelector('p')).not.toBeNull();
- expect(vm.$el.querySelectorAll('p').length).toBe(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]]);
-
- expect(vm.$el.querySelectorAll('p').length).toBe(2);
- });
- });
-
- describe('svg output', () => {
- beforeEach(done => {
- createComponent(json.cells[5].outputs[0]);
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders as an svg', () => {
- expect(vm.$el.querySelector('svg')).not.toBeNull();
- });
- });
-
- describe('default to plain text', () => {
- beforeEach(done => {
- createComponent(json.cells[6].outputs[0]);
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders as plain text', () => {
- expect(vm.$el.querySelector('pre')).not.toBeNull();
- expect(vm.$el.textContent.trim()).toContain('testing');
- });
-
- it('renders promot', () => {
- 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]);
-
- setTimeout(() => {
- expect(vm.$el.querySelector('pre')).not.toBeNull();
- expect(vm.$el.textContent.trim()).toContain('testing');
-
- done();
- });
- });
- });
-});
diff --git a/spec/javascripts/notebook/cells/prompt_spec.js b/spec/javascripts/notebook/cells/prompt_spec.js
deleted file mode 100644
index cbbcb1e68e3..00000000000
--- a/spec/javascripts/notebook/cells/prompt_spec.js
+++ /dev/null
@@ -1,56 +0,0 @@
-import Vue from 'vue';
-import PromptComponent from '~/notebook/cells/prompt.vue';
-
-const Component = Vue.extend(PromptComponent);
-
-describe('Prompt component', () => {
- let vm;
-
- describe('input', () => {
- beforeEach(done => {
- vm = new Component({
- propsData: {
- type: 'In',
- count: 1,
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders in label', () => {
- expect(vm.$el.textContent.trim()).toContain('In');
- });
-
- it('renders count', () => {
- expect(vm.$el.textContent.trim()).toContain('1');
- });
- });
-
- describe('output', () => {
- beforeEach(done => {
- vm = new Component({
- propsData: {
- type: 'Out',
- count: 1,
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders in label', () => {
- expect(vm.$el.textContent.trim()).toContain('Out');
- });
-
- it('renders count', () => {
- expect(vm.$el.textContent.trim()).toContain('1');
- });
- });
-});
diff --git a/spec/javascripts/notebook/index_spec.js b/spec/javascripts/notebook/index_spec.js
deleted file mode 100644
index 2e2ea5ad8af..00000000000
--- a/spec/javascripts/notebook/index_spec.js
+++ /dev/null
@@ -1,100 +0,0 @@
-import Vue from 'vue';
-import Notebook from '~/notebook/index.vue';
-
-const Component = Vue.extend(Notebook);
-
-describe('Notebook component', () => {
- let vm;
- let json;
- let jsonWithWorksheet;
-
- beforeEach(() => {
- json = getJSONFixture('blob/notebook/basic.json');
- jsonWithWorksheet = getJSONFixture('blob/notebook/worksheets.json');
- });
-
- describe('without JSON', () => {
- beforeEach(done => {
- vm = new Component({
- propsData: {
- notebook: {},
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('does not render', () => {
- expect(vm.$el.tagName).toBeUndefined();
- });
- });
-
- describe('with JSON', () => {
- beforeEach(done => {
- vm = new Component({
- propsData: {
- notebook: json,
- codeCssClass: 'js-code-class',
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders cells', () => {
- expect(vm.$el.querySelectorAll('.cell').length).toBe(json.cells.length);
- });
-
- it('renders markdown cell', () => {
- expect(vm.$el.querySelector('.markdown')).not.toBeNull();
- });
-
- it('renders code cell', () => {
- expect(vm.$el.querySelector('pre')).not.toBeNull();
- });
-
- it('add code class to code blocks', () => {
- expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
- });
- });
-
- describe('with worksheets', () => {
- beforeEach(done => {
- vm = new Component({
- propsData: {
- notebook: jsonWithWorksheet,
- codeCssClass: 'js-code-class',
- },
- });
- vm.$mount();
-
- setTimeout(() => {
- done();
- });
- });
-
- it('renders cells', () => {
- expect(vm.$el.querySelectorAll('.cell').length).toBe(
- jsonWithWorksheet.worksheets[0].cells.length,
- );
- });
-
- it('renders markdown cell', () => {
- expect(vm.$el.querySelector('.markdown')).not.toBeNull();
- });
-
- it('renders code cell', () => {
- expect(vm.$el.querySelector('pre')).not.toBeNull();
- });
-
- it('add code class to code blocks', () => {
- expect(vm.$el.querySelector('.js-code-class')).not.toBeNull();
- });
- });
-});