Add copy to clipboard buttons in explore and sqllab (#6461)

* Add copy to clipboard buttons in explore and sqllab

* Eslint fixes

* Review changes: deconstruct props, extract function to utils, add tests
This commit is contained in:
leakingoxide
2018-12-07 19:03:33 +01:00
committed by Hugh A. Miles II
parent fc8acf27c8
commit eb408d71c4
5 changed files with 68 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { isTruthy, optionFromValue } from '../../../src/utils/common';
import { isTruthy, optionFromValue, prepareCopyToClipboardTabularData } from '../../../src/utils/common';
describe('utils/common', () => {
describe('isTruthy', () => {
@@ -48,4 +48,17 @@ describe('utils/common', () => {
expect(optionFromValue(5)).toEqual({ value: 5, label: '5' });
});
});
describe('prepareCopyToClipboardTabularData', () => {
it('converts empty array', () => {
const array = [];
expect(prepareCopyToClipboardTabularData(array)).toEqual('');
});
it('converts non empty array', () => {
const array = [
{ column1: 'lorem', column2: 'ipsum' },
{ column1: 'dolor', column2: 'sit', column3: 'amet' },
];
expect(prepareCopyToClipboardTabularData(array)).toEqual('lorem\tipsum\ndolor\tsit\tamet\n');
});
});
});