Files
nomad/ui/tests/integration/util/exec-command-editor-xterm-adapter-test.js
Buck Doyle 27df92a967 UI: add exec terminal (#6697)
This connects Xterm.js to a Nomad exec websocket so people
can interact on clients via live sessions. There are buttons on
job, allocation, task group, and task detail pages that open a
popup that lets them edit their shell command and start a
session.

More is to come, as recorded in issues.
2020-03-24 18:22:16 -05:00

54 lines
1.8 KiB
JavaScript

import ExecCommandEditorXtermAdapter from 'nomad-ui/utils/classes/exec-command-editor-xterm-adapter';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { Terminal } from 'xterm-vendor';
module('Integration | Utility | exec-command-editor-xterm-adapter', function(hooks) {
setupRenderingTest(hooks);
test('it can wrap to a previous line while backspacing', async function(assert) {
let done = assert.async();
await render(hbs`
<div id='terminal'></div>
`);
let terminal = new Terminal({ cols: 10 });
terminal.open(document.getElementById('terminal'));
terminal.write('/bin/long-command');
new ExecCommandEditorXtermAdapter(
terminal,
command => {
assert.equal(command, '/bin/long');
done();
},
'/bin/long-command'
);
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Backspace' } });
await settled();
assert.equal(
terminal.buffer
.getLine(0)
.translateToString()
.trim(),
'/bin/long'
);
await terminal.simulateCommandKeyEvent({ domEvent: { key: 'Enter' } });
});
});