pinokiod 8.3.28 → 8.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/shell.js +3 -0
- package/kernel/shell_size.js +99 -0
- package/kernel/shells.js +2 -0
- package/package.json +1 -1
- package/server/index.js +2 -0
- package/server/public/agent-bar-about.css +67 -0
- package/server/public/agent-bar-about.js +205 -0
- package/server/public/agent-bar-compose.js +4 -1
- package/server/public/agent-bar-modes.css +78 -0
- package/server/public/agent-bar-modes.js +97 -0
- package/server/public/agent-bar-panel.js +38 -12
- package/server/public/agent-bar.css +7 -5
- package/server/public/agent-bar.js +42 -9
- package/server/public/home-actions-menu.css +188 -0
- package/server/public/home-actions-menu.js +135 -0
- package/server/public/home-shell.css +121 -0
- package/server/public/home-shell.js +290 -0
- package/server/views/app.ejs +1 -1
- package/server/views/index.ejs +40 -1
- package/server/views/partials/home_action_modal.ejs +1 -1
- package/server/views/partials/home_ask_button.ejs +15 -0
- package/server/views/partials/home_shell_button.ejs +21 -0
- package/server/views/partials/main_sidebar.ejs +5 -1
- package/server/views/pre.ejs +1 -1
- package/test/agent-bar-about.test.js +252 -0
- package/test/agent-bar-modes.test.js +191 -0
- package/test/home-actions-menu.test.js +187 -0
- package/test/home-shell.test.js +358 -0
- package/test/shell-size.test.js +166 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// An Ask pointed at one app, from home (server/public/agent-bar-about.js): the
|
|
2
|
+
// button on each row of My Apps points the bar at the top of the page at that
|
|
3
|
+
// app, and a send then starts the agent in the app's folder, without opening
|
|
4
|
+
// the app's page.
|
|
5
|
+
//
|
|
6
|
+
// The real agent-bar.js, agent-bar-compose.js and agent-bar-about.js run here
|
|
7
|
+
// in a page that has only what they look for. Layout is not covered.
|
|
8
|
+
const assert = require('node:assert/strict')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const path = require('node:path')
|
|
11
|
+
const test = require('node:test')
|
|
12
|
+
const ejs = require('ejs')
|
|
13
|
+
const { JSDOM } = require('jsdom')
|
|
14
|
+
|
|
15
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
16
|
+
const BUTTON = path.resolve(__dirname, '../server/views/partials/home_ask_button.ejs')
|
|
17
|
+
const button = (data) => ejs.renderFile(BUTTON, data)
|
|
18
|
+
|
|
19
|
+
async function settle(window) {
|
|
20
|
+
for (let i = 0; i < 8; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('the row button carries the app\'s folder name, path, name and icon', async () => {
|
|
24
|
+
const html = await button({ folder: '/home/api/demo.git', name: 'Demo "App"', icon: '/asset/api/demo.git/icon.png' })
|
|
25
|
+
const node = new JSDOM(html).window.document.querySelector('button.home-ask-button')
|
|
26
|
+
assert.ok(node)
|
|
27
|
+
assert.equal(node.dataset.askApp, 'demo.git')
|
|
28
|
+
assert.equal(node.dataset.askFolder, '/home/api/demo.git')
|
|
29
|
+
assert.equal(node.dataset.askName, 'Demo "App"')
|
|
30
|
+
assert.equal(node.dataset.askIcon, '/asset/api/demo.git/icon.png')
|
|
31
|
+
assert.equal(node.getAttribute('aria-label'), 'Ask Pinokio about Demo "App"')
|
|
32
|
+
assert.ok(node.classList.contains('home-icon-btn'))
|
|
33
|
+
// a Windows path names the app the same way
|
|
34
|
+
const win = new JSDOM(await button({ folder: 'C:\\pinokio\\api\\demo', name: 'Demo' })).window.document.querySelector('button')
|
|
35
|
+
assert.equal(win.dataset.askApp, 'demo')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('no folder, no button', async () => {
|
|
39
|
+
assert.equal((await button({ folder: undefined, name: 'Demo' })).trim(), '')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
async function home(t, options = {}) {
|
|
43
|
+
const posts = []
|
|
44
|
+
const delivered = []
|
|
45
|
+
const rowClicks = []
|
|
46
|
+
const dom = new JSDOM('<!doctype html><body class="is-home main-sidebar-page">'
|
|
47
|
+
+ '<header class="navheader"><h1><div class="flexible"></div></h1></header>'
|
|
48
|
+
+ '<div class="home-app-line" id="demo" role="link" tabindex="0"><div class="menu-btns">'
|
|
49
|
+
+ await button({ folder: '/home/api/demo', name: 'Demo App', icon: '/icon.png' })
|
|
50
|
+
+ '</div></div>'
|
|
51
|
+
+ '<div class="home-app-line" id="other" role="link" tabindex="0"><div class="menu-btns">'
|
|
52
|
+
+ await button({ folder: '/home/api/other', name: 'Other' })
|
|
53
|
+
+ '</div></div></body>', {
|
|
54
|
+
url: 'http://127.0.0.1:42000/home',
|
|
55
|
+
runScripts: 'outside-only',
|
|
56
|
+
pretendToBeVisual: true,
|
|
57
|
+
beforeParse(window) {
|
|
58
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
59
|
+
window.Element.prototype.animate = () => ({ cancel() {}, finished: Promise.resolve(), addEventListener() {} })
|
|
60
|
+
window.fetch = async (url, init) => {
|
|
61
|
+
const address = String(url)
|
|
62
|
+
if (address.split('?')[0] === '/api/plugin/menu') {
|
|
63
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }], projectShell: { items: [] } }) }
|
|
64
|
+
}
|
|
65
|
+
if (address === '/brain/ask') {
|
|
66
|
+
const body = JSON.parse(init.body)
|
|
67
|
+
posts.push(body)
|
|
68
|
+
if (options.refuse) return { ok: false, json: async () => ({ ok: false, error: 'App not found.' }) }
|
|
69
|
+
const cwd = body.app ? `/home/api/${body.app}` : '/home/brain'
|
|
70
|
+
return { ok: true, json: async () => ({ ok: true, id: 's1', cwd, url: `/run/plugin/codex/pinokio.js?cwd=${encodeURIComponent(cwd)}&chrome=full&session=s1&prompt=read` }) }
|
|
71
|
+
}
|
|
72
|
+
return { ok: false, json: async () => ({}) }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
t.after(() => dom.window.close())
|
|
77
|
+
const { window } = dom
|
|
78
|
+
const { document } = window
|
|
79
|
+
document.addEventListener('click', (event) => {
|
|
80
|
+
if (event.target.closest('.home-app-line')) rowClicks.push('click')
|
|
81
|
+
})
|
|
82
|
+
window.eval(script('agent-bar.js'))
|
|
83
|
+
if (options.compose !== false) window.eval(script('agent-bar-compose.js'))
|
|
84
|
+
window.eval(script('agent-bar-about.js'))
|
|
85
|
+
const bar = window.PinokioAgentBar
|
|
86
|
+
await bar.ready
|
|
87
|
+
bar.deliver = (info) => { delivered.push(info); return true }
|
|
88
|
+
bar.attachments.paths = async (appId) => (options.files ? options.files.map((name) => `/home/api/${appId}/.pinokio-temp/uploads/${name}`) : [])
|
|
89
|
+
await settle(window)
|
|
90
|
+
const root = document.querySelector('.agent-bar')
|
|
91
|
+
const input = root.querySelector('.agent-bar__input')
|
|
92
|
+
return {
|
|
93
|
+
window,
|
|
94
|
+
document,
|
|
95
|
+
bar,
|
|
96
|
+
root,
|
|
97
|
+
input,
|
|
98
|
+
posts,
|
|
99
|
+
delivered,
|
|
100
|
+
rowClicks,
|
|
101
|
+
label: () => root.querySelector('.agent-bar__scope-label').textContent,
|
|
102
|
+
chip: () => root.querySelector('.agent-bar__about'),
|
|
103
|
+
settle: () => settle(window),
|
|
104
|
+
async click(node) {
|
|
105
|
+
node.dispatchEvent(new window.MouseEvent('click', { bubbles: true, cancelable: true }))
|
|
106
|
+
await settle(window)
|
|
107
|
+
},
|
|
108
|
+
askButton: (id) => document.querySelector(`#${id} .home-ask-button`),
|
|
109
|
+
async send(text) {
|
|
110
|
+
input.value = text
|
|
111
|
+
root.querySelector('.agent-bar__go').click()
|
|
112
|
+
await settle(window)
|
|
113
|
+
await settle(window)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
test('a click on a row\'s button points the bar at that app and does not open the app', async (t) => {
|
|
119
|
+
const p = await home(t)
|
|
120
|
+
assert.equal(p.root.dataset.about, '')
|
|
121
|
+
assert.equal(p.label(), 'Ask')
|
|
122
|
+
await p.click(p.askButton('demo'))
|
|
123
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
124
|
+
assert.equal(p.root.dataset.item, 'ask')
|
|
125
|
+
assert.equal(p.label(), 'Ask · Demo App')
|
|
126
|
+
assert.equal(p.bar.hint(), 'Ask Pinokio about Demo App…')
|
|
127
|
+
assert.equal(p.bar.greeting(), 'Ask Pinokio about Demo App')
|
|
128
|
+
// the cursor is in the text
|
|
129
|
+
assert.equal(p.document.activeElement, p.input)
|
|
130
|
+
assert.deepEqual(p.rowClicks, [])
|
|
131
|
+
assert.deepEqual(p.posts, [])
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('the remembered agent is shown as soon as the page opens, before the bar is used', async (t) => {
|
|
135
|
+
const p = await home(t)
|
|
136
|
+
assert.equal(p.bar.tool().value, 'codex')
|
|
137
|
+
assert.match(p.root.querySelector('.agent-bar__agent').textContent, /Codex/)
|
|
138
|
+
assert.equal(p.root.dataset.engaged, 'false')
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('the click is the first thing done in the bar: the remembered agent is shown, not only used', async (t) => {
|
|
142
|
+
const p = await home(t)
|
|
143
|
+
await p.click(p.askButton('demo'))
|
|
144
|
+
assert.equal(p.bar.tool().value, 'codex')
|
|
145
|
+
assert.match(p.root.querySelector('.agent-bar__agent').textContent, /Codex/)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('the open view has a chip with the app\'s name and icon; its x makes it an ordinary Ask', async (t) => {
|
|
149
|
+
const p = await home(t)
|
|
150
|
+
await p.click(p.askButton('demo'))
|
|
151
|
+
const chip = p.chip()
|
|
152
|
+
assert.ok(chip)
|
|
153
|
+
assert.equal(chip.hidden, false)
|
|
154
|
+
assert.equal(chip.querySelector('.agent-bar__about-name').textContent, 'Demo App')
|
|
155
|
+
assert.equal(chip.querySelector('.agent-bar__about-icon').getAttribute('src'), '/icon.png')
|
|
156
|
+
// at the left of the bottom row
|
|
157
|
+
assert.ok(chip.nextSibling.classList.contains('agent-compose__grow'))
|
|
158
|
+
await p.click(chip.querySelector('.agent-bar__about-x'))
|
|
159
|
+
assert.equal(p.root.dataset.about, '')
|
|
160
|
+
assert.equal(p.label(), 'Ask')
|
|
161
|
+
assert.equal(p.bar.hint(), 'Ask Pinokio anything…')
|
|
162
|
+
assert.equal(p.bar.greeting(), '')
|
|
163
|
+
assert.equal(chip.hidden, true)
|
|
164
|
+
assert.equal(p.document.activeElement, p.input)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('another row\'s button points the bar at the other app', async (t) => {
|
|
168
|
+
const p = await home(t)
|
|
169
|
+
await p.click(p.askButton('demo'))
|
|
170
|
+
await p.click(p.askButton('other'))
|
|
171
|
+
assert.equal(p.root.dataset.about, 'other')
|
|
172
|
+
assert.equal(p.label(), 'Ask · Other')
|
|
173
|
+
// no icon: the chip shows the name alone
|
|
174
|
+
assert.equal(p.chip().querySelector('.agent-bar__about-icon').hidden, true)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('a send asks about the app, in the app\'s folder, and the bar is an ordinary Ask again', async (t) => {
|
|
178
|
+
const p = await home(t)
|
|
179
|
+
await p.click(p.askButton('demo'))
|
|
180
|
+
await p.send('why does it crash')
|
|
181
|
+
assert.deepEqual(p.posts, [{ app: 'demo', prompt: 'why does it crash', tool: 'codex', files: [] }])
|
|
182
|
+
assert.equal(p.delivered.length, 1)
|
|
183
|
+
assert.equal(p.delivered[0].type, 'ask')
|
|
184
|
+
assert.equal(p.delivered[0].cwd, '/home/api/demo')
|
|
185
|
+
assert.match(p.delivered[0].url, /^\/run\/plugin\/codex\/pinokio\.js\?cwd=%2Fhome%2Fapi%2Fdemo&/)
|
|
186
|
+
assert.equal(p.delivered[0].prompt, 'why does it crash')
|
|
187
|
+
await p.settle()
|
|
188
|
+
assert.equal(p.root.dataset.about, '')
|
|
189
|
+
assert.equal(p.label(), 'Ask')
|
|
190
|
+
assert.equal(p.chip().hidden, true)
|
|
191
|
+
assert.equal(p.input.value, '')
|
|
192
|
+
// the next send is the shared Ask
|
|
193
|
+
await p.send('hello')
|
|
194
|
+
assert.deepEqual(p.posts[1], { prompt: 'hello', tool: 'codex', uploadToken: '' })
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('attached files go to the app and are named in the request', async (t) => {
|
|
198
|
+
const p = await home(t, { files: ['shot.png'] })
|
|
199
|
+
await p.click(p.askButton('demo'))
|
|
200
|
+
await p.send('')
|
|
201
|
+
assert.deepEqual(p.posts, [{ app: 'demo', prompt: '', tool: 'codex', files: ['/home/api/demo/.pinokio-temp/uploads/shot.png'] }])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('with nothing typed the agent just starts in the app\'s folder', async (t) => {
|
|
205
|
+
const p = await home(t)
|
|
206
|
+
await p.click(p.askButton('demo'))
|
|
207
|
+
await p.send('')
|
|
208
|
+
assert.deepEqual(p.posts, [])
|
|
209
|
+
assert.equal(p.delivered.length, 1)
|
|
210
|
+
assert.equal(p.delivered[0].cwd, '/home/api/demo')
|
|
211
|
+
assert.match(p.delivered[0].url, /^\/run\/plugin\/codex\/pinokio\.js\?cwd=%2Fhome%2Fapi%2Fdemo&session=[^&]+$/)
|
|
212
|
+
assert.equal(p.root.dataset.about, '')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('a refused send says why and stays pointed at the app', async (t) => {
|
|
216
|
+
const p = await home(t, { refuse: true })
|
|
217
|
+
await p.click(p.askButton('demo'))
|
|
218
|
+
await p.send('hello')
|
|
219
|
+
assert.deepEqual(p.delivered, [])
|
|
220
|
+
assert.match(p.root.querySelector('.agent-bar__note').textContent, /App not found\./)
|
|
221
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
222
|
+
assert.equal(p.input.value, 'hello')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('another mode drops the app; coming back to Ask is an ordinary Ask', async (t) => {
|
|
226
|
+
const p = await home(t)
|
|
227
|
+
await p.click(p.askButton('demo'))
|
|
228
|
+
p.bar.choose('create_app')
|
|
229
|
+
await p.settle()
|
|
230
|
+
assert.equal(p.root.dataset.about, '')
|
|
231
|
+
assert.equal(p.chip().hidden, true)
|
|
232
|
+
p.bar.choose('ask')
|
|
233
|
+
await p.settle()
|
|
234
|
+
assert.equal(p.root.dataset.about, '')
|
|
235
|
+
assert.equal(p.label(), 'Ask')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('an ordinary Ask is unchanged', async (t) => {
|
|
239
|
+
const p = await home(t)
|
|
240
|
+
await p.send('hello')
|
|
241
|
+
assert.deepEqual(p.posts, [{ prompt: 'hello', tool: 'codex', uploadToken: '' }])
|
|
242
|
+
assert.equal(p.delivered[0].cwd, '/home/brain')
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
test('without the compose view the bar still says which app and sends about it', async (t) => {
|
|
246
|
+
const p = await home(t, { compose: false })
|
|
247
|
+
await p.click(p.askButton('demo'))
|
|
248
|
+
assert.equal(p.chip(), null)
|
|
249
|
+
assert.equal(p.label(), 'Ask · Demo App')
|
|
250
|
+
await p.send('hi')
|
|
251
|
+
assert.equal(p.posts[0].app, 'demo')
|
|
252
|
+
})
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// The agent bar's row of modes (server/public/agent-bar-modes.js): in the open
|
|
2
|
+
// view on a desktop every mode is named along the top of the box, the one in use
|
|
3
|
+
// is marked, and a click on another switches to it.
|
|
4
|
+
//
|
|
5
|
+
// The real agent-bar.js, agent-bar-compose.js and agent-bar-modes.js run here in
|
|
6
|
+
// a page that has only a top bar. This page lays nothing out, so widths are
|
|
7
|
+
// given by the test where a case is about room.
|
|
8
|
+
const assert = require('node:assert/strict')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const path = require('node:path')
|
|
11
|
+
const test = require('node:test')
|
|
12
|
+
const { JSDOM } = require('jsdom')
|
|
13
|
+
|
|
14
|
+
const publicDir = path.resolve(__dirname, '../server/public')
|
|
15
|
+
const read = (name) => fs.readFileSync(path.join(publicDir, name), 'utf8')
|
|
16
|
+
const barScript = read('agent-bar.js')
|
|
17
|
+
const appScript = read('agent-bar-app.js')
|
|
18
|
+
const composeScript = read('agent-bar-compose.js')
|
|
19
|
+
const modesScript = read('agent-bar-modes.js')
|
|
20
|
+
|
|
21
|
+
const PHONE = '(max-width: 768px)'
|
|
22
|
+
const HOME_PAGE = '<!doctype html><body><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
|
|
23
|
+
const APP_PAGE = '<!doctype html><body class="app-page"><header class="navheader"><h1>'
|
|
24
|
+
+ '<div class="app-header-identity"><span class="app-header-identity-title">Demo App</span></div>'
|
|
25
|
+
+ '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button><div class="flexible"></div></h1></header>'
|
|
26
|
+
+ '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-scroller"></div></aside><main id="page"></main>'
|
|
27
|
+
+ '<div class="mobile-bottom-nav"><div class="mobile-bottom-nav__identity"></div></div></div></body>'
|
|
28
|
+
|
|
29
|
+
async function settle(window) {
|
|
30
|
+
for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function page(t, options = {}) {
|
|
34
|
+
const media = new Set(options.media || [])
|
|
35
|
+
const dom = new JSDOM(options.app ? APP_PAGE : HOME_PAGE, {
|
|
36
|
+
url: `http://127.0.0.1:42000/${options.app ? 'p/demo' : 'home'}`,
|
|
37
|
+
runScripts: 'outside-only',
|
|
38
|
+
pretendToBeVisual: true,
|
|
39
|
+
beforeParse(window) {
|
|
40
|
+
window.matchMedia = (query) => ({ matches: media.has(query), addEventListener() {}, removeEventListener() {} })
|
|
41
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
42
|
+
return { left: 300, top: 8, right: 900, bottom: 608, width: 600, height: 600, x: 300, y: 8 }
|
|
43
|
+
}
|
|
44
|
+
window.fetch = async (url) => {
|
|
45
|
+
if (String(url) === '/info/shells') return { ok: true, json: async () => [] }
|
|
46
|
+
if (String(url).split('?')[0] === '/api/plugin/menu') {
|
|
47
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
|
|
48
|
+
}
|
|
49
|
+
if (String(url) === '/pinokio/install/exists') return { ok: true, json: async () => ({ exists: false }) }
|
|
50
|
+
return { ok: false, json: async () => ({ ok: false, error: 'not sent in this test' }) }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
t.after(() => dom.window.close())
|
|
55
|
+
const { window } = dom
|
|
56
|
+
window.eval(barScript)
|
|
57
|
+
if (options.app) window.eval(appScript)
|
|
58
|
+
window.eval(composeScript)
|
|
59
|
+
window.eval(modesScript)
|
|
60
|
+
await window.PinokioAgentBar.ready
|
|
61
|
+
await settle(window)
|
|
62
|
+
const { document } = window
|
|
63
|
+
const root = document.querySelector('.agent-bar')
|
|
64
|
+
const input = root.querySelector('.agent-bar__input')
|
|
65
|
+
const items = () => Array.from(root.querySelectorAll('.agent-bar-modes__item'))
|
|
66
|
+
// nothing is laid out here, so every width reads 0: the box is given one
|
|
67
|
+
const field = root.querySelector('.agent-bar__field')
|
|
68
|
+
const box = { width: 600 }
|
|
69
|
+
Object.defineProperty(field, 'clientWidth', { configurable: true, get: () => box.width })
|
|
70
|
+
return {
|
|
71
|
+
window,
|
|
72
|
+
root,
|
|
73
|
+
input,
|
|
74
|
+
items,
|
|
75
|
+
field,
|
|
76
|
+
box,
|
|
77
|
+
checked: () => items().filter((item) => item.getAttribute('aria-checked') === 'true').map((item) => item.textContent),
|
|
78
|
+
async focus() {
|
|
79
|
+
input.focus()
|
|
80
|
+
await settle(window)
|
|
81
|
+
},
|
|
82
|
+
async click(label) {
|
|
83
|
+
items().find((item) => item.textContent === label).click()
|
|
84
|
+
await settle(window)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
test('the open view names every mode and marks the one in use', async (t) => {
|
|
90
|
+
const p = await page(t)
|
|
91
|
+
await p.focus()
|
|
92
|
+
assert.equal(p.root.dataset.compose, 'place')
|
|
93
|
+
assert.deepEqual(p.items().map((item) => item.textContent), ['Ask', 'Create app', 'Create plugin', 'Download'])
|
|
94
|
+
assert.deepEqual(p.checked(), ['Ask'])
|
|
95
|
+
assert.equal(p.root.dataset.modes, 'row')
|
|
96
|
+
// the row is the first row of the box, before the text
|
|
97
|
+
const row = p.root.querySelector('.agent-bar-modes')
|
|
98
|
+
assert.equal(row.parentNode, p.field)
|
|
99
|
+
assert.ok(row.compareDocumentPosition(p.root.querySelector('.agent-bar__top')) & p.window.Node.DOCUMENT_POSITION_FOLLOWING)
|
|
100
|
+
assert.equal(p.root.querySelector('.agent-compose__controls .agent-bar-modes'), null, 'it is not among the controls')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('a click on another mode switches to it and keeps the cursor in the text', async (t) => {
|
|
104
|
+
const p = await page(t)
|
|
105
|
+
await p.focus()
|
|
106
|
+
await p.click('Create app')
|
|
107
|
+
assert.equal(p.root.dataset.item, 'create_app')
|
|
108
|
+
assert.deepEqual(p.checked(), ['Create app'])
|
|
109
|
+
assert.equal(p.input.placeholder, 'What should this app do?')
|
|
110
|
+
assert.equal(p.root.querySelector('.agent-bar__footer').hidden, false, 'the folder row is shown')
|
|
111
|
+
assert.equal(p.window.document.activeElement, p.input)
|
|
112
|
+
assert.equal(p.root.dataset.compose, 'place', 'the view stays open')
|
|
113
|
+
|
|
114
|
+
await p.click('Download')
|
|
115
|
+
assert.equal(p.root.dataset.item, 'download')
|
|
116
|
+
assert.deepEqual(p.checked(), ['Download'])
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('what was typed is kept when the mode changes', async (t) => {
|
|
120
|
+
const p = await page(t)
|
|
121
|
+
await p.focus()
|
|
122
|
+
p.input.value = 'a draft'
|
|
123
|
+
p.input.dispatchEvent(new p.window.Event('input', { bubbles: true }))
|
|
124
|
+
await settle(p.window)
|
|
125
|
+
await p.click('Create app')
|
|
126
|
+
assert.equal(p.input.value, 'a draft')
|
|
127
|
+
await p.click('Ask')
|
|
128
|
+
assert.equal(p.input.value, 'a draft')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('a mode chosen from the chip\'s menu marks the row too', async (t) => {
|
|
132
|
+
const p = await page(t)
|
|
133
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
134
|
+
await settle(p.window)
|
|
135
|
+
p.root.querySelectorAll('.agent-bar__menu .agent-bar__row')[2].click()
|
|
136
|
+
await settle(p.window)
|
|
137
|
+
assert.deepEqual(p.checked(), ['Create plugin'])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('send keeps the mode\'s full name', async (t) => {
|
|
141
|
+
const p = await page(t)
|
|
142
|
+
await p.focus()
|
|
143
|
+
await p.click('Create plugin')
|
|
144
|
+
assert.equal(p.root.querySelector('.agent-bar__go-label').textContent, 'Create plugin')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('a press on a name does not take the cursor out of the text', async (t) => {
|
|
148
|
+
const p = await page(t)
|
|
149
|
+
await p.focus()
|
|
150
|
+
const press = new p.window.Event('pointerdown', { bubbles: true, cancelable: true })
|
|
151
|
+
p.items()[1].dispatchEvent(press)
|
|
152
|
+
assert.equal(press.defaultPrevented, true)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('a box too narrow for the four names keeps the chip, whatever the mode', async (t) => {
|
|
156
|
+
const p = await page(t)
|
|
157
|
+
// each name is 80 wide: the four need 320
|
|
158
|
+
Object.defineProperty(p.window.HTMLElement.prototype, 'offsetWidth', {
|
|
159
|
+
configurable: true,
|
|
160
|
+
get() { return this.classList.contains('agent-bar-modes__item') ? 80 : 0 }
|
|
161
|
+
})
|
|
162
|
+
p.box.width = 300
|
|
163
|
+
await p.focus()
|
|
164
|
+
assert.equal(p.root.dataset.modes, 'menu')
|
|
165
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
166
|
+
await settle(p.window)
|
|
167
|
+
p.root.querySelectorAll('.agent-bar__menu .agent-bar__row')[1].click()
|
|
168
|
+
await settle(p.window)
|
|
169
|
+
assert.equal(p.root.dataset.modes, 'menu')
|
|
170
|
+
|
|
171
|
+
// the window is made wider
|
|
172
|
+
p.box.width = 400
|
|
173
|
+
p.window.dispatchEvent(new p.window.Event('resize'))
|
|
174
|
+
await settle(p.window)
|
|
175
|
+
assert.equal(p.root.dataset.modes, 'row')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('a phone keeps the chip and its menu', async (t) => {
|
|
179
|
+
const p = await page(t, { media: [PHONE] })
|
|
180
|
+
await p.focus()
|
|
181
|
+
assert.equal(p.root.dataset.compose, 'screen')
|
|
182
|
+
// the stylesheet shows the row only in the two desktop shapes
|
|
183
|
+
assert.notEqual(p.root.dataset.compose, 'place')
|
|
184
|
+
assert.ok(p.root.querySelector('.agent-bar__scope').closest('.agent-compose__controls'), 'the chip is in the controls row')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('an app page\'s bar, which only asks, has no row', async (t) => {
|
|
188
|
+
const p = await page(t, { app: true })
|
|
189
|
+
assert.equal(p.items().length, 0)
|
|
190
|
+
assert.equal(p.root.classList.contains('agent-bar--modes'), false)
|
|
191
|
+
})
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Home: an app row's actions as a dropdown (server/public/home-actions-menu.js).
|
|
2
|
+
// On a wide window the page opens the row's actions dialog "docked"; the script
|
|
3
|
+
// puts it under the row's button and closes it like a menu. The dialog and its
|
|
4
|
+
// buttons are the page's own.
|
|
5
|
+
//
|
|
6
|
+
// The real script runs here in a page that has only what it looks for. The
|
|
7
|
+
// page's part (opening the dialog) is done by hand. Layout is not covered.
|
|
8
|
+
const assert = require('node:assert/strict')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const path = require('node:path')
|
|
11
|
+
const test = require('node:test')
|
|
12
|
+
const ejs = require('ejs')
|
|
13
|
+
const { JSDOM } = require('jsdom')
|
|
14
|
+
|
|
15
|
+
const script = fs.readFileSync(path.resolve(__dirname, '../server/public/home-actions-menu.js'), 'utf8')
|
|
16
|
+
const MODAL = path.resolve(__dirname, '../server/views/partials/home_action_modal.ejs')
|
|
17
|
+
|
|
18
|
+
const PAGE = '<!doctype html><body class="is-home">'
|
|
19
|
+
+ '<div class="home-app-line line" id="row">'
|
|
20
|
+
+ '<div class="menu-btns"><button class="btn open-actions-modal" id="trigger" data-dialog-id="actions-1" aria-expanded="false"></button></div>'
|
|
21
|
+
+ '<dialog id="actions-1" class="home-actions-dialog">'
|
|
22
|
+
+ '<div class="home-actions-header"><button class="home-actions-close"></button></div>'
|
|
23
|
+
+ '<div class="home-actions-body">'
|
|
24
|
+
+ '<details class="home-run-menu-group" open><summary class="home-run-menu-summary" id="group">Group</summary>'
|
|
25
|
+
+ '<div class="home-run-menu-row"><a class="home-run-command" id="run" href="#">Open Web UI</a><button class="home-run-stop" id="stop"></button></div></details>'
|
|
26
|
+
+ '<button class="home-mode-command" id="settings"><i></i><span>Settings</span></button>'
|
|
27
|
+
+ '</div></dialog>'
|
|
28
|
+
+ '</div>'
|
|
29
|
+
+ '<div id="elsewhere"></div>'
|
|
30
|
+
+ '<div class="swal2-container"><button id="confirm"></button></div>'
|
|
31
|
+
+ '</body>'
|
|
32
|
+
|
|
33
|
+
async function page(t) {
|
|
34
|
+
const dom = new JSDOM(PAGE, {
|
|
35
|
+
url: 'http://127.0.0.1:42000/home',
|
|
36
|
+
runScripts: 'outside-only',
|
|
37
|
+
pretendToBeVisual: true,
|
|
38
|
+
beforeParse(window) {
|
|
39
|
+
// the row's button, and a menu 280 by 300
|
|
40
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
41
|
+
return { left: 200, top: 100, right: 228, bottom: 122, width: 28, height: 22, x: 200, y: 100 }
|
|
42
|
+
}
|
|
43
|
+
Object.defineProperty(window.HTMLElement.prototype, 'offsetWidth', { get() { return 280 } })
|
|
44
|
+
Object.defineProperty(window.HTMLElement.prototype, 'offsetHeight', { get() { return 300 } })
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
t.after(() => dom.window.close())
|
|
48
|
+
const { window } = dom
|
|
49
|
+
const { document } = window
|
|
50
|
+
window.eval(script)
|
|
51
|
+
const dialog = document.getElementById('actions-1')
|
|
52
|
+
const settle = async () => { for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0)) }
|
|
53
|
+
return {
|
|
54
|
+
window,
|
|
55
|
+
document,
|
|
56
|
+
dialog,
|
|
57
|
+
settle,
|
|
58
|
+
isOpen: () => dialog.hasAttribute('open'),
|
|
59
|
+
// what the page does on a wide window, and on a narrow one
|
|
60
|
+
async open(docked = true) {
|
|
61
|
+
dialog.classList.toggle('is-docked', docked)
|
|
62
|
+
dialog.setAttribute('open', '')
|
|
63
|
+
await settle()
|
|
64
|
+
},
|
|
65
|
+
async press(id) {
|
|
66
|
+
document.getElementById(id).dispatchEvent(new window.Event('pointerdown', { bubbles: true }))
|
|
67
|
+
await settle()
|
|
68
|
+
},
|
|
69
|
+
async click(id) {
|
|
70
|
+
document.getElementById(id).dispatchEvent(new window.MouseEvent('click', { bubbles: true, cancelable: true }))
|
|
71
|
+
await settle()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
test('the page is marked, so the opened dialog is drawn as a menu', async (t) => {
|
|
77
|
+
const p = await page(t)
|
|
78
|
+
assert.ok(p.document.body.classList.contains('home-actions-menu'))
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('the opened menu is put under the row\'s button', async (t) => {
|
|
82
|
+
const p = await page(t)
|
|
83
|
+
await p.open()
|
|
84
|
+
assert.equal(p.dialog.style.left, '200px')
|
|
85
|
+
assert.equal(p.dialog.style.top, '128px')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('with no room below, the menu goes above the button', async (t) => {
|
|
89
|
+
const p = await page(t)
|
|
90
|
+
p.window.innerHeight = 400
|
|
91
|
+
p.window.Element.prototype.getBoundingClientRect = function () {
|
|
92
|
+
return { left: 200, top: 340, right: 228, bottom: 362, width: 28, height: 22, x: 200, y: 340 }
|
|
93
|
+
}
|
|
94
|
+
await p.open()
|
|
95
|
+
assert.equal(p.dialog.style.top, '34px')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('a press elsewhere closes the menu; inside it, on its button, or on a question over it does not', async (t) => {
|
|
99
|
+
const p = await page(t)
|
|
100
|
+
await p.open()
|
|
101
|
+
await p.press('settings')
|
|
102
|
+
await p.press('trigger')
|
|
103
|
+
await p.press('confirm')
|
|
104
|
+
assert.equal(p.isOpen(), true)
|
|
105
|
+
await p.press('elsewhere')
|
|
106
|
+
assert.equal(p.isOpen(), false)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('the press that closes the menu does not also open the row under it', async (t) => {
|
|
110
|
+
const p = await page(t)
|
|
111
|
+
const opened = []
|
|
112
|
+
// the page's own rule: a click on a row opens its app, unless it was cancelled or is on a control
|
|
113
|
+
p.document.addEventListener('click', (event) => {
|
|
114
|
+
if (event.defaultPrevented || event.target.closest('button, a, dialog, summary')) return
|
|
115
|
+
if (event.target.closest('.home-app-line')) opened.push('row')
|
|
116
|
+
})
|
|
117
|
+
await p.open()
|
|
118
|
+
await p.press('row')
|
|
119
|
+
assert.equal(p.isOpen(), false)
|
|
120
|
+
await p.click('row')
|
|
121
|
+
assert.deepEqual(opened, [])
|
|
122
|
+
// the click after that is an ordinary one
|
|
123
|
+
await p.press('row')
|
|
124
|
+
await p.click('row')
|
|
125
|
+
assert.deepEqual(opened, ['row'])
|
|
126
|
+
// a button pressed to close the menu still gets its click
|
|
127
|
+
await p.open()
|
|
128
|
+
let clicked = 0
|
|
129
|
+
p.document.getElementById('trigger').addEventListener('click', () => { clicked += 1 })
|
|
130
|
+
await p.press('elsewhere')
|
|
131
|
+
await p.click('trigger')
|
|
132
|
+
assert.equal(clicked, 1)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('picking a command closes the menu, after the page has handled the click', async (t) => {
|
|
136
|
+
for (const id of ['settings', 'run', 'stop']) {
|
|
137
|
+
const p = await page(t)
|
|
138
|
+
await p.open()
|
|
139
|
+
let openWhenHandled = null
|
|
140
|
+
p.document.addEventListener('click', () => { openWhenHandled = p.isOpen() })
|
|
141
|
+
await p.click(id)
|
|
142
|
+
assert.equal(openWhenHandled, true, id)
|
|
143
|
+
assert.equal(p.isOpen(), false, id)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('opening or closing a group of launcher items leaves the menu open', async (t) => {
|
|
148
|
+
const p = await page(t)
|
|
149
|
+
await p.open()
|
|
150
|
+
await p.click('group')
|
|
151
|
+
assert.equal(p.isOpen(), true)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('the page scrolling or the window resizing closes the menu', async (t) => {
|
|
155
|
+
const p = await page(t)
|
|
156
|
+
await p.open()
|
|
157
|
+
p.window.dispatchEvent(new p.window.Event('scroll'))
|
|
158
|
+
assert.equal(p.isOpen(), false)
|
|
159
|
+
await p.open()
|
|
160
|
+
p.window.dispatchEvent(new p.window.Event('resize'))
|
|
161
|
+
assert.equal(p.isOpen(), false)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('a narrow window\'s dialog is left as the page shows it', async (t) => {
|
|
165
|
+
const p = await page(t)
|
|
166
|
+
// a place left over from a wide window is taken off
|
|
167
|
+
await p.open()
|
|
168
|
+
p.dialog.removeAttribute('open')
|
|
169
|
+
await p.open(false)
|
|
170
|
+
assert.equal(p.dialog.style.left, '')
|
|
171
|
+
assert.equal(p.dialog.style.top, '')
|
|
172
|
+
await p.press('elsewhere')
|
|
173
|
+
await p.click('settings')
|
|
174
|
+
assert.equal(p.isOpen(), true)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('the dialog\'s Share section is marked, so the menu can leave it out', async () => {
|
|
178
|
+
const html = await ejs.renderFile(MODAL, {
|
|
179
|
+
id: 'actions-1',
|
|
180
|
+
item: { name: 'Demo', filepath: '/home/api/demo', running: true, menu: [], uri: 'demo', view_url: '/v/demo', url: '/demo' }
|
|
181
|
+
})
|
|
182
|
+
const document = new JSDOM(html).window.document
|
|
183
|
+
const share = document.querySelector('.home-actions-section--share')
|
|
184
|
+
assert.ok(share)
|
|
185
|
+
assert.ok(share.querySelector('.home-share-app'))
|
|
186
|
+
assert.equal(document.querySelectorAll('.home-actions-section--share').length, 1)
|
|
187
|
+
})
|