You've already forked mattermost-webapp
mirror of
https://github.com/zerotier/mattermost-webapp.git
synced 2026-05-22 16:23:25 -07:00
2fbd02760e
* Converts Google Sheets pasted content to Markdown table * Makes pasting tables more reliable and supports Excel * Adds a test for pasting markdown * Handle pasting a table with content already in the input * Handle posting tables in a comment * Write test to check that existing message is preserved * Format tables with GitHub Markdown * Refactor util functions and add unit tests
56 lines
1.8 KiB
React
56 lines
1.8 KiB
React
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {parseTable, getTable, formatMarkdownTableMessage} from 'utils/paste';
|
|
|
|
const validClipboardData = {
|
|
items: [1],
|
|
types: ['text/html'],
|
|
getData: () => {
|
|
return '<table><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr></table>';
|
|
},
|
|
};
|
|
|
|
const validTable = parseTable(validClipboardData.getData());
|
|
|
|
describe('Paste', () => {
|
|
describe('Paste.getTable', () => {
|
|
test('returns false without html in the clipboard', () => {
|
|
const badClipboardData = {
|
|
items: [1],
|
|
types: ['text/plain'],
|
|
};
|
|
|
|
expect(getTable(badClipboardData)).toBe(false);
|
|
});
|
|
|
|
test('returns false without table in the clipboard', () => {
|
|
const badClipboardData = {
|
|
items: [1],
|
|
types: ['text/html'],
|
|
getData: () => '<p>There is no table here</p>',
|
|
};
|
|
|
|
expect(getTable(badClipboardData)).toBe(false);
|
|
});
|
|
|
|
test('returns table from valid clipboard data', () => {
|
|
expect(getTable(validClipboardData)).toEqual(validTable);
|
|
});
|
|
});
|
|
|
|
describe('Paste.formatMarkdownTableMessage', () => {
|
|
const markdownTable = '|test | test|\n|--- | ---|\n|test | test|\n';
|
|
|
|
test('returns a markdown table when valid html table provided', () => {
|
|
expect(formatMarkdownTableMessage(validTable)).toBe(markdownTable);
|
|
});
|
|
|
|
test('returns a markdown table under a message when one is provided', () => {
|
|
const testMessage = 'test message';
|
|
|
|
expect(formatMarkdownTableMessage(validTable, testMessage)).toBe(`${testMessage}\n\n${markdownTable}`);
|
|
});
|
|
});
|
|
});
|