Repository navigation
Expand file tree
/
Copy pathindex.test.js
More file actions
96 lines (79 loc) · 3.17 KB
/
Copy pathindex.test.js
File metadata and controls
96 lines (79 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const assert = require('node:assert/strict');
const test = require('node:test');
const plugin = require('./index');
function createReactMock() {
return {
PureComponent: class PureComponent {
constructor(props) {
this.props = props;
}
},
createElement(type, props) {
return {type, props};
}
};
}
test('uses the active tab title as the document title', () => {
const React = createReactMock();
const Header = function Header() {};
const DecoratedHeader = plugin.decorateHeader(Header, {React});
const component = new DecoratedHeader({
tabs: [
{title: 'first project', isActive: false},
{title: 'active project', isActive: true}
]
});
global.document = {title: 'Hyper'};
component.componentDidMount();
assert.equal(document.title, 'active project');
assert.deepEqual(component.render(), {type: Header, props: component.props});
});
test('updates the title when the active tab changes', () => {
const React = createReactMock();
const DecoratedHeader = plugin.decorateHeader(function Header() {}, {React});
const component = new DecoratedHeader({tabs: [{title: 'one', isActive: true}]});
global.document = {title: 'Hyper'};
component.componentDidMount();
component.props = {tabs: [{title: 'two', isActive: true}]};
component.componentDidUpdate();
assert.equal(document.title, 'two');
});
test('falls back to Hyper when no active title is available', () => {
const React = createReactMock();
const DecoratedHeader = plugin.decorateHeader(function Header() {}, {React});
const component = new DecoratedHeader({tabs: [{title: '', isActive: true}]});
global.document = {title: 'previous title'};
component.componentDidMount();
assert.equal(document.title, 'Hyper');
});
test('restores the default title when unloaded', () => {
const React = createReactMock();
const DecoratedHeader = plugin.decorateHeader(function Header() {}, {React});
const component = new DecoratedHeader({tabs: [{title: 'project', isActive: true}]});
global.document = {title: 'project'};
component.componentWillUnmount();
assert.equal(document.title, 'Hyper');
});
test('locks each terminal to the launcher profile until it exits', () => {
const React = createReactMock();
const Term = plugin.decorateTerm(function Term() {}, {React});
const titles = [];
const component = new Term({onTitle: title => titles.push(title)});
const onTitle = component.render().props.onTitle;
onTitle('__MULTICLI_TITLE_LOCK__:vivi');
onTitle('Task generated by Codex | project');
assert.deepEqual(titles, ['vivi']);
const otherTitles = [];
const other = new Term({onTitle: title => otherTitles.push(title)});
other.render().props.onTitle('__MULTICLI_TITLE_LOCK__:nino');
assert.deepEqual(otherTitles, ['nino']);
assert.deepEqual(titles, ['vivi']);
onTitle('__MULTICLI_TITLE_UNLOCK__');
onTitle('shell directory');
assert.deepEqual(titles, ['vivi', 'Hyper', 'shell directory']);
});
test('enables the launcher title protocol without losing existing environment', () => {
assert.deepEqual(plugin.decorateConfig({env: {EXAMPLE: 'preserved'}}).env,
{EXAMPLE: 'preserved', NINI_AGENTS_HYPER_TITLE_LOCK: '1'});
});