|
|
@@ -15,7 +15,7 @@ async function freePort() {
|
|
|
return port
|
|
|
}
|
|
|
|
|
|
-test('the real desktop workspace downloads in place and waits for an explicit restart', { timeout: 60000 }, async () => {
|
|
|
+test('the desktop update icon appears beside the bell only for updates and waits for an explicit restart', { timeout: 60000 }, async () => {
|
|
|
const root = resolve(import.meta.dirname, '..'), home = await mkdtemp(join(tmpdir(), 'yaoyao-inline-update-'))
|
|
|
const port = await freePort(), upstream = await freePort(), origin = `http://127.0.0.1:${port}`
|
|
|
await mkdir(join(home, 'server'))
|
|
|
@@ -32,8 +32,8 @@ test('the real desktop workspace downloads in place and waits for an explicit re
|
|
|
await app.evaluate(({ app }, root) => {
|
|
|
const { createRequire } = process.getBuiltinModule('node:module')
|
|
|
const { autoUpdater } = createRequire(root + '/package.json')(root + '/.desktop-build-client/electron-updater.cjs')
|
|
|
- globalThis.inlineFixture = { installs: 0 }
|
|
|
- autoUpdater.checkForUpdates = async () => ({ isUpdateAvailable: true, updateInfo: { version: '99.0.0' } })
|
|
|
+ globalThis.inlineFixture = { installs: 0, available: false }
|
|
|
+ autoUpdater.checkForUpdates = async () => ({ isUpdateAvailable: inlineFixture.available, updateInfo: { version: '99.0.0' } })
|
|
|
autoUpdater.downloadUpdate = () => new Promise(resolve => {
|
|
|
inlineFixture.ready = () => resolve([])
|
|
|
inlineFixture.stage = () => autoUpdater.emit('update-downloaded')
|
|
|
@@ -49,36 +49,63 @@ test('the real desktop workspace downloads in place and waits for an explicit re
|
|
|
await page.waitForURL(origin + '/**')
|
|
|
await page.goto(origin + '/conversations')
|
|
|
await expect(page.locator('.desktop-sidebar .sidebar-account-switcher__main')).toBeVisible()
|
|
|
+ const entry = page.locator('.desktop-sidebar .desktop-update-entry')
|
|
|
+ await page.evaluate(() => window.yaoyaoDesktop.openUpdates())
|
|
|
+ await expect(entry).toHaveCount(0)
|
|
|
+ await expect(page.locator('#desktop-update-entry')).toHaveCount(0)
|
|
|
+ // Older servers receive the local updater script through the real main
|
|
|
+ // process. Its entry must follow the same bell placement and visibility.
|
|
|
+ await page.route(origin + '/legacy-update', route => route.fulfill({ contentType: 'text/html', body: '<aside class="desktop-sidebar"><div class="bot-list-header"><button class="unread-entry">铃铛</button><button>搜索</button></div></aside>' }))
|
|
|
+ await page.goto(origin + '/legacy-update')
|
|
|
+ await expect(page.locator('#desktop-update-entry')).toBeHidden()
|
|
|
+ await page.evaluate(() => window.yaoyaoDesktop.openUpdates())
|
|
|
+ await expect(page.locator('#desktop-update-entry')).toBeHidden()
|
|
|
+ await app.evaluate(() => { inlineFixture.available = true })
|
|
|
await page.evaluate(() => window.yaoyaoDesktop.updateAction('check'))
|
|
|
- const footer = page.locator('.desktop-sidebar .desktop-update-entry')
|
|
|
- await expect(footer.getByRole('button', { name: '可更新', exact: true })).toBeVisible()
|
|
|
+ await expect(page.locator('.unread-entry + #desktop-update-entry').getByRole('button', { name: '可更新', exact: true })).toBeVisible()
|
|
|
+ await page.goto(origin + '/conversations')
|
|
|
+ await expect(entry.getByRole('button', { name: '可更新', exact: true })).toBeVisible()
|
|
|
await expect(page.locator('#desktop-update-entry')).toHaveCount(0)
|
|
|
+ assert.equal(await entry.evaluate(element => element.previousElementSibling.classList.contains('unread-entry')), true)
|
|
|
+ await expect(page.locator('.sidebar-footer .desktop-update-entry')).toHaveCount(0)
|
|
|
assert.equal(app.windows().length, 1)
|
|
|
const output = join(root, 'test-results/desktop/inline-workspace'); await mkdir(output, { recursive: true })
|
|
|
await page.screenshot({ path: join(output, 'available.png') })
|
|
|
- await footer.getByRole('button', { name: '可更新', exact: true }).click()
|
|
|
- await expect(footer.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '37')
|
|
|
+ await entry.getByRole('button', { name: '可更新', exact: true }).click()
|
|
|
+ await expect(entry.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '37')
|
|
|
+ await expect(page.locator('#desktop-update-entry')).toHaveCount(0)
|
|
|
+ await page.screenshot({ path: join(output, 'downloading.png') })
|
|
|
await page.locator('.desktop-sidebar .sidebar-account-switcher__main').click()
|
|
|
- const menu = page.locator('.workspace-settings-menu .desktop-update-entry')
|
|
|
- await expect(menu).toContainText('正在下载 · 37%')
|
|
|
- await page.screenshot({ path: join(output, 'downloading-menu.png') })
|
|
|
+ await expect(page.locator('.workspace-settings-menu .desktop-update-entry')).toHaveCount(0)
|
|
|
+ await expect(page.locator('.desktop-update-check')).toBeDisabled()
|
|
|
await page.keyboard.press('Escape')
|
|
|
- await expect(menu).toHaveCount(0)
|
|
|
await app.evaluate(() => inlineFixture.stage())
|
|
|
- await expect(footer).toContainText('正在准备…')
|
|
|
+ await expect(entry).toContainText('正在准备…')
|
|
|
await page.reload()
|
|
|
- await expect(footer).toContainText('正在准备…')
|
|
|
- await expect(footer.getByRole('button')).toBeDisabled()
|
|
|
+ await expect(entry).toContainText('正在准备…')
|
|
|
+ await expect(entry.getByRole('button')).toBeDisabled()
|
|
|
await app.evaluate(() => inlineFixture.ready())
|
|
|
- await expect(footer.getByRole('button', { name: '重新启动', exact: true })).toBeEnabled()
|
|
|
+ await expect(entry.getByRole('button', { name: '重新启动', exact: true })).toBeEnabled()
|
|
|
+ await expect(entry).toHaveClass(/desktop-update-entry--ready/)
|
|
|
assert.equal(await app.evaluate(() => inlineFixture.installs), 0)
|
|
|
assert.equal(app.windows().length, 1)
|
|
|
await page.screenshot({ path: join(output, 'ready.png') })
|
|
|
await page.evaluate(() => document.documentElement.classList.add('dark'))
|
|
|
await page.screenshot({ path: join(output, 'ready-dark.png') })
|
|
|
- await footer.getByRole('button', { name: '重新启动', exact: true }).click()
|
|
|
+ await page.goto(origin + '/legacy-update')
|
|
|
+ await expect(page.locator('.unread-entry + #desktop-update-entry').getByRole('button', { name: '重新启动', exact: true })).toBeVisible()
|
|
|
+ await expect(page.locator('#desktop-update-icon')).toBeVisible()
|
|
|
+ await expect(page.locator('#desktop-update-ring')).toBeHidden()
|
|
|
+ await page.goto(origin + '/chat')
|
|
|
+ await expect(page.locator('.sidebar-status-actions .desktop-update-entry')).toBeVisible()
|
|
|
+ await expect(page.locator('#desktop-update-entry')).toHaveCount(0)
|
|
|
+ await page.screenshot({ path: join(output, 'ready-chat.png') })
|
|
|
+ await page.getByRole('button', { name: '折叠侧边栏', exact: true }).click()
|
|
|
+ await expect(entry.getByRole('button', { name: '重新启动', exact: true })).toBeVisible()
|
|
|
+ await page.screenshot({ path: join(output, 'ready-collapsed.png') })
|
|
|
+ await entry.getByRole('button', { name: '重新启动', exact: true }).click()
|
|
|
await expect.poll(() => app.evaluate(() => inlineFixture.installs)).toBe(1)
|
|
|
- await expect(footer.getByRole('button', { name: '正在重启…', exact: true })).toBeDisabled()
|
|
|
+ await expect(entry.getByRole('button', { name: '正在重启…', exact: true })).toBeDisabled()
|
|
|
assert.equal((await fetch(origin + '/healthz')).status, 200)
|
|
|
} finally {
|
|
|
await app?.close().catch(() => {})
|