diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 09:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 09:07:51 +0000 |
commit | 5afd8575506372dd64c238203bd05b4826f3ae2e (patch) | |
tree | e167192fdc7d73fcc1aa5bd33b535b813120ec37 /spec/frontend/behaviors | |
parent | 8bda404e2919234c299f088b7d8d04f8449125de (diff) | |
download | gitlab-ce-5afd8575506372dd64c238203bd05b4826f3ae2e.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.js | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js index a8177a5ad39..a98919e2113 100644 --- a/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js +++ b/spec/frontend/behaviors/markdown/paste_markdown_table_spec.js @@ -10,9 +10,9 @@ describe('PasteMarkdownTable', () => { value: { getData: jest.fn().mockImplementation(type => { if (type === 'text/html') { - return '<table><tr><td></td></tr></table>'; + return '<table><tr><td>First</td><td>Second</td></tr></table>'; } - return 'hello world'; + return 'First\tSecond'; }), }, }); @@ -24,39 +24,48 @@ describe('PasteMarkdownTable', () => { it('return false when no HTML data is provided', () => { data.types = ['text/plain']; - expect(PasteMarkdownTable.isTable(data)).toBe(false); + expect(new PasteMarkdownTable(data).isTable()).toBe(false); }); it('returns false when no text data is provided', () => { data.types = ['text/html']; - expect(PasteMarkdownTable.isTable(data)).toBe(false); + expect(new PasteMarkdownTable(data).isTable()).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); + expect(new PasteMarkdownTable(data).isTable()).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); + expect(new PasteMarkdownTable(data).isTable()).toBe(false); }); - }); - describe('convertToTableMarkdown', () => { - let converter; + it('returns false when the number of rows are not consistent', () => { + data.types = ['text/html', 'text/plain']; + data.getData = jest.fn().mockImplementation(mimeType => { + if (mimeType === 'text/html') { + return '<table><tr><td>def test<td></tr></table>'; + } + return "def test\n 'hello'\n"; + }); - beforeEach(() => { - converter = new PasteMarkdownTable(data); + expect(new PasteMarkdownTable(data).isTable()).toBe(false); }); + }); + describe('convertToTableMarkdown', () => { it('returns a Markdown table', () => { + data.types = ['text/html', 'text/plain']; data.getData = jest.fn().mockImplementation(type => { - if (type === 'text/plain') { + if (type === 'text/html') { + return '<table><tr><td>First</td><td>Last</td><tr><td>John</td><td>Doe</td><tr><td>Jane</td><td>Doe</td></table>'; + } else if (type === 'text/plain') { return 'First\tLast\nJohn\tDoe\nJane\tDoe'; } @@ -70,12 +79,18 @@ describe('PasteMarkdownTable', () => { '| Jane | Doe |', ].join('\n'); + const converter = new PasteMarkdownTable(data); + + expect(converter.isTable()).toBe(true); expect(converter.convertToTableMarkdown()).toBe(expected); }); it('returns a Markdown table with rows normalized', () => { + data.types = ['text/html', 'text/plain']; data.getData = jest.fn().mockImplementation(type => { - if (type === 'text/plain') { + if (type === 'text/html') { + return '<table><tr><td>First</td><td>Last</td><tr><td>John</td><td>Doe</td><tr><td>Jane</td><td>/td></table>'; + } else if (type === 'text/plain') { return 'First\tLast\nJohn\tDoe\nJane'; } @@ -89,6 +104,9 @@ describe('PasteMarkdownTable', () => { '| Jane | |', ].join('\n'); + const converter = new PasteMarkdownTable(data); + + expect(converter.isTable()).toBe(true); expect(converter.convertToTableMarkdown()).toBe(expected); }); }); |