summaryrefslogtreecommitdiff
path: root/spec/frontend/behaviors
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-31 18:09:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-31 18:09:10 +0000
commit62ddd3a00522d62ab23c7804e24dbe1c941bc0a7 (patch)
tree71f2cf18cdc83a3fce5221d05df3a792a562dd4e /spec/frontend/behaviors
parent1e6a9268646e7346519610492fc2a02d6655a663 (diff)
downloadgitlab-ce-62ddd3a00522d62ab23c7804e24dbe1c941bc0a7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/behaviors')
-rw-r--r--spec/frontend/behaviors/markdown/paste_markdown_table_spec.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js
new file mode 100644
index 00000000000..a8177a5ad39
--- /dev/null
+++ b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js
@@ -0,0 +1,95 @@
+import PasteMarkdownTable from '~/behaviors/markdown/paste_markdown_table';
+
+describe('PasteMarkdownTable', () => {
+ let data;
+
+ beforeEach(() => {
+ const event = new window.Event('paste');
+
+ Object.defineProperty(event, 'dataTransfer', {
+ value: {
+ getData: jest.fn().mockImplementation(type => {
+ if (type === 'text/html') {
+ return '<table><tr><td></td></tr></table>';
+ }
+ return 'hello world';
+ }),
+ },
+ });
+
+ data = event.dataTransfer;
+ });
+
+ describe('isTable', () => {
+ it('return false when no HTML data is provided', () => {
+ data.types = ['text/plain'];
+
+ expect(PasteMarkdownTable.isTable(data)).toBe(false);
+ });
+
+ it('returns false when no text data is provided', () => {
+ data.types = ['text/html'];
+
+ expect(PasteMarkdownTable.isTable(data)).toBe(false);
+ });
+
+ it('returns true when a table is provided in both text and HTML', () => {
+ data.types = ['text/html', 'text/plain'];
+
+ expect(PasteMarkdownTable.isTable(data)).toBe(true);
+ });
+
+ it('returns false when no HTML table is included', () => {
+ data.types = ['text/html', 'text/plain'];
+ data.getData = jest.fn().mockImplementation(() => 'nothing');
+
+ expect(PasteMarkdownTable.isTable(data)).toBe(false);
+ });
+ });
+
+ describe('convertToTableMarkdown', () => {
+ let converter;
+
+ beforeEach(() => {
+ converter = new PasteMarkdownTable(data);
+ });
+
+ it('returns a Markdown table', () => {
+ data.getData = jest.fn().mockImplementation(type => {
+ if (type === 'text/plain') {
+ return 'First\tLast\nJohn\tDoe\nJane\tDoe';
+ }
+
+ return '';
+ });
+
+ const expected = [
+ '| First | Last |',
+ '|-------|------|',
+ '| John | Doe |',
+ '| Jane | Doe |',
+ ].join('\n');
+
+ expect(converter.convertToTableMarkdown()).toBe(expected);
+ });
+
+ it('returns a Markdown table with rows normalized', () => {
+ data.getData = jest.fn().mockImplementation(type => {
+ if (type === 'text/plain') {
+ return 'First\tLast\nJohn\tDoe\nJane';
+ }
+
+ return '';
+ });
+
+ const expected = [
+ '| First | Last |',
+ '|-------|------|',
+ '| John | Doe |',
+ '| Jane | |',
+ ].join('\n');
+
+ expect(converter.convertToTableMarkdown()).toBe(expected);
+ });
+ });
+});