diff options
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/behaviors/markdown/paste_markdown_table_spec.js | 95 | ||||
-rw-r--r-- | spec/frontend/fixtures/issues.rb | 9 |
2 files changed, 104 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); + }); + }); +}); diff --git a/spec/frontend/fixtures/issues.rb b/spec/frontend/fixtures/issues.rb index 7e524990863..9a194e5ca84 100644 --- a/spec/frontend/fixtures/issues.rb +++ b/spec/frontend/fixtures/issues.rb @@ -23,6 +23,15 @@ describe Projects::IssuesController, '(JavaScript fixtures)', type: :controller remove_repository(project) end + it 'issues/new-issue.html' do + get :new, params: { + namespace_id: project.namespace.to_param, + project_id: project + } + + expect(response).to be_successful + end + it 'issues/open-issue.html' do render_issue(create(:issue, project: project)) end |