electron/spec/api-clipboard-spec.js

97 строки
3.3 KiB
JavaScript
Исходник Обычный вид История

2016-03-25 23:03:49 +03:00
const assert = require('assert')
const path = require('path')
2016-01-12 05:40:23 +03:00
2016-03-25 23:03:49 +03:00
const clipboard = require('electron').clipboard
const nativeImage = require('electron').nativeImage
2016-01-12 05:40:23 +03:00
2016-03-25 23:03:49 +03:00
describe('clipboard module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
2016-03-25 23:03:49 +03:00
describe('clipboard.readImage()', function () {
it('returns NativeImage intance', function () {
var p = path.join(fixtures, 'assets', 'logo.png')
var i = nativeImage.createFromPath(p)
clipboard.writeImage(p)
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
})
})
2016-03-25 23:03:49 +03:00
describe('clipboard.readText()', function () {
it('returns unicode string correctly', function () {
var text = '千江有水千江月,万里无云万里天'
clipboard.writeText(text)
assert.equal(clipboard.readText(), text)
})
})
2016-05-27 00:23:50 +03:00
describe('clipboard.readHTML()', function () {
2016-03-25 23:03:49 +03: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-05-27 00:23:50 +03:00
clipboard.writeHTML(text)
assert.equal(clipboard.readHTML(), markup)
2016-03-25 23:03:49 +03:00
})
})
2016-05-27 00:23:50 +03:00
describe('clipboard.readRTF', function () {
2016-03-25 23:03:49 +03: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}'
2016-05-27 00:23:50 +03:00
clipboard.writeRTF(rtf)
assert.equal(clipboard.readRTF(), rtf)
2016-03-25 23:03:49 +03:00
})
})
2016-06-25 01:10:32 +03:00
describe('clipboard.readBookmark', function () {
it('returns title and url', function () {
if (process.platform === 'linux') return
2016-06-25 01:10:32 +03:00
clipboard.writeBookmark('a title', 'http://electron.atom.io')
assert.deepEqual(clipboard.readBookmark(), {
title: 'a title',
url: 'http://electron.atom.io'
})
clipboard.writeText('no bookmark')
assert.deepEqual(clipboard.readBookmark(), {
title: '',
url: ''
2016-06-25 01:10:32 +03:00
})
})
})
2016-03-25 23:03:49 +03: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-06-25 01:14:28 +03:00
var bookmark = {title: 'a title', url: 'test'}
2016-01-12 05:40:23 +03:00
clipboard.write({
2016-03-25 23:03:49 +03:00
text: 'test',
2016-01-12 05:40:23 +03:00
html: '<b>Hi</b>',
rtf: '{\\rtf1\\utf8 text}',
2016-06-25 01:14:28 +03:00
bookmark: 'a title',
2016-01-12 05:40:23 +03:00
image: p
2016-03-25 23:03:49 +03:00
})
assert.equal(clipboard.readText(), text)
2016-05-27 00:23:50 +03:00
assert.equal(clipboard.readHTML(), markup)
assert.equal(clipboard.readRTF(), rtf)
2016-03-25 23:03:49 +03:00
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
if (process.platform !== 'linux') {
assert.deepEqual(clipboard.readBookmark(), bookmark)
}
2016-03-25 23:03:49 +03:00
})
})
2016-10-25 07:59:04 +03:00
describe('clipboard.read/writeFindText(text)', function () {
it('reads and write text to the find pasteboard', function () {
if (process.platform !== 'darwin') return
2016-10-25 07:59:04 +03:00
clipboard.writeFindText('find this')
assert.equal(clipboard.readFindText(), 'find this')
})
})
2016-03-25 23:03:49 +03:00
})