Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
ui/tests: pretend the platform is Macintosh
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwhite committed Jan 13, 2022
1 parent 1fc6cd5 commit f90f73d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ui/tests/helpers/xterm.ts
@@ -1,5 +1,17 @@
import { triggerEvent, triggerKeyEvent, focus } from '@ember/test-helpers';

// At the time of writing, xterm.js only implements the Macintosh “select all”
// keyboard shortcut (cmd+a), not the Linux and Windows equivalent (ctrl+a).
// What follows is a dreadful hack to make `getTerminalText` work in Linux CI.
// Note: this needs to happen before xterm is required, so you’ll find an
// import in `tests/test-helper.js`.
Object.defineProperty(navigator, 'platform', {
value: 'Macintosh',
configurable: true,
enumerable: true,
writable: false,
});

/**
* Returns the text from an xterm.js terminal element.
*
Expand All @@ -10,9 +22,8 @@ import { triggerEvent, triggerKeyEvent, focus } from '@ember/test-helpers';
export async function getTerminalText(): Promise<string> {
await focus('.xterm-helper-textarea');

// Trigger cmd+a and ctrl+a to select all
// Trigger cmd+a to select all
await triggerKeyEvent('.xterm-helper-textarea', 'keydown', 65, { metaKey: true });
await triggerKeyEvent('.xterm-helper-textarea', 'keydown', 65, { ctrlKey: true });

let clipboardData = new DataTransfer();
await triggerEvent('.xterm', 'copy', { clipboardData });
Expand Down
1 change: 1 addition & 0 deletions ui/tests/test-helper.js
Expand Up @@ -6,6 +6,7 @@ import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';
import { setup as setupA11yTesting } from './helpers/a11y';
import './helpers/flash-message';
import './helpers/xterm';

setApplication(Application.create(config.APP));

Expand Down

0 comments on commit f90f73d

Please sign in to comment.