-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {readTextFromClipboard, writeTextToClipboard} from '../../index'; | ||
import {createFakeWebKitPostMessage} from './fake-post-message'; | ||
|
||
test('read from clipboard', async () => { | ||
createFakeWebKitPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('CLIPBOARD_READ_TEXT'); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'CLIPBOARD_READ_TEXT', | ||
payload: 'some text', | ||
id: msg.id, | ||
}), | ||
}); | ||
|
||
const res = await readTextFromClipboard(); | ||
|
||
expect(res).toEqual('some text'); | ||
}); | ||
|
||
test('write to clipboard', async () => { | ||
createFakeWebKitPostMessage({ | ||
checkMessage: (msg) => { | ||
expect(msg.type).toBe('CLIPBOARD_WRITE_TEXT'); | ||
expect(msg.payload).toBe('some text'); | ||
}, | ||
getResponse: (msg) => ({ | ||
type: 'CLIPBOARD_WRITE_TEXT', | ||
id: msg.id, | ||
}), | ||
}); | ||
|
||
await writeTextToClipboard('some text'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {postMessageToNativeApp} from './post-message'; | ||
|
||
export const readTextFromClipboard = (): Promise<string> => | ||
postMessageToNativeApp({type: 'CLIPBOARD_READ_TEXT'}); | ||
|
||
export const writeTextToClipboard = (text: string): Promise<void> => | ||
postMessageToNativeApp({type: 'CLIPBOARD_WRITE_TEXT', payload: text}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters