pulsar/spec/clipboard-spec.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-03-20 23:42:43 +03:00
describe('Clipboard', () => {
describe('write(text, metadata) and read()', () => {
it('writes and reads text to/from the native clipboard', () => {
2019-05-31 20:50:30 +03:00
expect(atom.clipboard.read()).toBe('initial clipboard content');
atom.clipboard.write('next');
expect(atom.clipboard.read()).toBe('next');
});
2019-03-20 23:42:43 +03:00
it('returns metadata if the item on the native clipboard matches the last written item', () => {
2019-05-31 20:50:30 +03:00
atom.clipboard.write('next', { meta: 'data' });
expect(atom.clipboard.read()).toBe('next');
expect(atom.clipboard.readWithMetadata().text).toBe('next');
expect(atom.clipboard.readWithMetadata().metadata).toEqual({
meta: 'data'
});
});
});
2019-03-20 23:42:43 +03:00
describe('line endings', () => {
2019-05-31 20:50:30 +03:00
let originalPlatform = process.platform;
2019-03-20 23:42:43 +03:00
2019-05-31 20:50:30 +03:00
const eols = new Map([
['win32', '\r\n'],
['darwin', '\n'],
['linux', '\n']
]);
2019-03-20 23:42:43 +03:00
for (let [platform, eol] of eols) {
it(`converts line endings to the OS's native line endings on ${platform}`, () => {
2019-05-31 20:50:30 +03:00
Object.defineProperty(process, 'platform', { value: platform });
2019-03-20 23:42:43 +03:00
2019-05-31 20:50:30 +03:00
atom.clipboard.write('next\ndone\r\n\n', { meta: 'data' });
expect(atom.clipboard.readWithMetadata()).toEqual({
text: `next${eol}done${eol}${eol}`,
metadata: { meta: 'data' }
});
2019-03-20 23:42:43 +03:00
2019-05-31 20:50:30 +03:00
Object.defineProperty(process, 'platform', { value: originalPlatform });
});
2019-03-20 23:42:43 +03:00
}
2019-05-31 20:50:30 +03:00
});
});