electron/spec/api-clipboard-spec.js

64 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-02-17 00:46:49 +00:00
const assert = require('assert');
const path = require('path');
2016-01-12 02:40:23 +00:00
2016-02-17 00:46:49 +00:00
const clipboard = require('electron').clipboard;
const nativeImage = require('electron').nativeImage;
2016-01-12 02:40:23 +00:00
describe('clipboard module', function() {
var fixtures = path.resolve(__dirname, 'fixtures');
2016-01-12 02:40:23 +00:00
describe('clipboard.readImage()', function() {
2016-02-17 01:39:11 +00:00
it('returns NativeImage intance', function() {
var p = path.join(fixtures, 'assets', 'logo.png');
var i = nativeImage.createFromPath(p);
2016-01-12 02:40:23 +00:00
clipboard.writeImage(p);
2016-02-17 01:39:11 +00:00
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
2016-01-12 02:40:23 +00:00
});
});
2016-01-12 02:40:23 +00:00
describe('clipboard.readText()', function() {
2016-02-17 01:39:11 +00:00
it('returns unicode string correctly', function() {
var text = '千江有水千江月,万里无云万里天';
2016-01-12 02:40:23 +00:00
clipboard.writeText(text);
2016-02-17 01:39:11 +00:00
assert.equal(clipboard.readText(), text);
2016-01-12 02:40:23 +00:00
});
});
2016-01-12 02:40:23 +00:00
describe('clipboard.readHtml()', function() {
2016-02-17 01:39:11 +00:00
it('returns markup correctly', function() {
var text = '<string>Hi</string>';
var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><string>Hi</string>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><string>Hi</string>' : '<string>Hi</string>';
2016-01-12 02:40:23 +00:00
clipboard.writeHtml(text);
2016-02-17 01:39:11 +00:00
assert.equal(clipboard.readHtml(), markup);
2016-01-12 02:40:23 +00:00
});
});
describe('clipboard.readRtf', function() {
2016-02-17 01:39:11 +00:00
it('returns rtf text correctly', function() {
var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}";
clipboard.writeRtf(rtf);
2016-02-17 01:39:11 +00:00
assert.equal(clipboard.readRtf(), rtf);
});
});
2016-02-17 01:39:11 +00:00
describe('clipboard.write()', function() {
it('returns data correctly', function() {
var text = 'test';
var rtf = '{\\rtf1\\utf8 text}';
var p = path.join(fixtures, 'assets', 'logo.png');
var i = nativeImage.createFromPath(p);
var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>';
2016-01-12 02:40:23 +00:00
clipboard.write({
text: "test",
html: '<b>Hi</b>',
rtf: '{\\rtf1\\utf8 text}',
2016-01-12 02:40:23 +00:00
image: p
});
assert.equal(clipboard.readText(), text);
assert.equal(clipboard.readHtml(), markup);
assert.equal(clipboard.readRtf(), rtf);
2016-02-17 01:39:11 +00:00
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
2016-01-12 02:40:23 +00:00
});
});
});