Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

test: replace settings tests with two intent-based ones; fix dismissed update returning on reload

Anmol Kapil93da97a4d89e
diff --git a/e2e/ui.spec.ts b/e2e/ui.spec.ts
index 63bf4c2..bb91ef6 100644
--- a/e2e/ui.spec.ts
+++ b/e2e/ui.spec.ts
@@ -1,5 +1,6 @@
-import { access, writeFile } from 'node:fs/promises'
+import { writeFile } from 'node:fs/promises'
import { join } from 'node:path'
+import type { Locator, Page } from '@playwright/test'
import { BLOCK, expect, interfacesEnv, NETWORKS, test } from './fixtures'
// G. A handful of journeys through the real UI, to prove the screens are wired to the main
@@ -104,60 +105,88 @@ test.describe('UI journeys @smoke', () => {
plexo.page.getByRole('button', { name: /Reveal in Finder|Show in folder/ })
).toBeVisible()
})
+})
- test('theme choice survives a restart', async ({ plexo }) => {
- const themeSource = (): Promise<string> =>
- plexo.evaluateMain(({ nativeTheme }) => nativeTheme.themeSource, undefined)
- const next = (await themeSource()) === 'light' ? 'dark' : 'light'
- await plexo.page.getByRole('button', { name: `Switch to ${next} theme` }).click()
- await expect.poll(themeSource).toBe(next)
- await plexo.relaunch()
- expect(await themeSource()).toBe(next)
- })
-
- test('renaming a network survives a restart', async ({ plexo }) => {
- const page = plexo.page
- await page.getByRole('button', { name: 'Edit network' }).first().click()
- await page.getByRole('textbox', { name: 'Name' }).fill('Office fibre')
- await page.getByRole('button', { name: 'Done' }).click()
- await expect(page.getByText('Office fibre')).toBeVisible()
-
- await plexo.relaunch()
- await expect(plexo.page.getByText('Office fibre')).toBeVisible()
+// What a user sets is still set after they reload or restart — checked only through what they see.
+test.describe('settings @smoke', () => {
+ test.describe('with an update available', () => {
+ test.use({ appEnv: { PLEXO_FORCE_UPDATE_VERSION: '9.9.9' } })
+
+ test('every choice survives a reload and a restart, even made right before', async ({
+ plexo,
+ dirs
+ }) => {
+ const page = (): Page => plexo.page
+ await page().getByRole('button', { name: 'Not now' }).click()
+
+ const themeToggle = page().getByRole('button', { name: /^Switch to (dark|light) theme$/ })
+ // After switching, the toggle offers to switch back.
+ const labelAfterSwitch = (await themeToggle.getAttribute('aria-label'))!.includes('dark')
+ ? 'Switch to light theme'
+ : 'Switch to dark theme'
+ await themeToggle.click()
+
+ await page().getByRole('button', { name: '4×' }).click()
+
+ await stubNativeUi(plexo, dirs.dest)
+ await page().getByRole('button', { name: 'Browse…' }).click()
+
+ await page().getByRole('button', { name: 'Edit network' }).first().click()
+ await page().getByRole('textbox', { name: 'Name' }).fill('Office fibre')
+ await page().getByRole('button', { name: 'Violet' }).click()
+ await page().getByRole('button', { name: 'Done' }).click()
+
+ const expectAllKept = async (): Promise<void> => {
+ // Waiting on the titlebar indicator first means the update check has answered, so the
+ // dialog's absence below is a real "stayed dismissed", not "not checked yet".
+ await expect(page().getByRole('link', { name: 'Update available: 9.9.9' })).toBeVisible()
+ await expect(page().getByRole('alertdialog')).toBeHidden()
+ await expect(page().getByRole('button', { name: labelAfterSwitch })).toBeVisible()
+ await expect(page().getByRole('button', { name: '4×' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true'
+ )
+ await expect(page().getByText(dirs.dest)).toBeVisible()
+ await expect(page().getByText('Office fibre')).toBeVisible()
+ await page().getByRole('button', { name: 'Edit network' }).first().click()
+ await expect(page().getByRole('button', { name: 'Violet' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true'
+ )
+ await page().keyboard.press('Escape')
+ }
+
+ // No waiting for saves: a user doesn't either.
+ await page().reload()
+ await expectAllKept()
+ await plexo.relaunch()
+ await expectAllKept()
+ })
})
- test('streams and destination folder survive a restart', async ({ plexo, dirs }) => {
- await stubNativeUi(plexo, dirs.dest)
- await plexo.page.getByRole('button', { name: 'Browse…' }).click()
- await plexo.page.getByRole('button', { name: '4×' }).click()
- await expect(plexo.page.getByText(dirs.dest)).toBeVisible()
+ test('a broken settings file falls back to defaults', async ({ plexo, dirs }) => {
+ const settingsPath = join(dirs.userData, 'app-settings.json')
+ const toField = (): Locator => plexo.page.getByText(/Downloads$/)
- await plexo.relaunch()
- await expect(plexo.page.getByRole('button', { name: '4×' })).toHaveAttribute(
+ await plexo.quit()
+ await writeFile(settingsPath, '{"streamsPerNetwork": 4,')
+ await plexo.launch()
+ await expect(plexo.page.getByRole('button', { name: '2×' })).toHaveAttribute(
'aria-pressed',
'true'
)
- await expect(plexo.page.getByText(dirs.dest)).toBeVisible()
- })
- test('a corrupt app-settings.json does not break the app', async ({ plexo, dirs }) => {
await plexo.quit()
- await writeFile(join(dirs.userData, 'app-settings.json'), '{"networkPreferences": {"a": [')
- await plexo.launch()
- await expect(plexo.page.getByRole('button', { name: 'Edit network' }).first()).toBeVisible()
- })
-
- test('names from the old network-preferences.json are moved into app-settings.json', async ({
- plexo,
- dirs
- }) => {
- await plexo.quit()
- const [id] = Object.keys(NETWORKS)
- const legacyPath = join(dirs.userData, 'network-preferences.json')
- await writeFile(legacyPath, JSON.stringify({ [id]: { customName: 'Office fibre' } }))
+ await writeFile(
+ settingsPath,
+ JSON.stringify({ streamsPerNetwork: 3, destinationDir: join(dirs.dest, 'unplugged') })
+ )
await plexo.launch()
- await expect(plexo.page.getByText('Office fibre')).toBeVisible()
- await expect(access(legacyPath)).rejects.toThrow()
+ await expect(plexo.page.getByRole('button', { name: '2×' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true'
+ )
+ await expect(toField()).toBeVisible()
})
})
diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.ts
index 72262e8..a6c52a4 100644
--- a/src/main/ipc/handlers.ts
+++ b/src/main/ipc/handlers.ts
@@ -191,12 +191,17 @@ export function registerIpcHandlers(getWindow: () => BrowserWindow | null): Down
const info = testKnobs.forceUpdateVersion
? { version: testKnobs.forceUpdateVersion, url: UPDATE_PAGE_URL }
: await checkForUpdate(app.getVersion())
- if (!info) return null
- const { dismissedUpdateVersion: dismissedVersion } = await loadSettings()
- return { ...info, dismissed: info.version === dismissedVersion }
+ return info
})()
- handle('checkForUpdate', async () => updateCheckPromise)
+ // Dismissal is read per call, not cached with the check — a reload after "Not now" must not
+ // bring the dialog back.
+ handle('checkForUpdate', async () => {
+ const info = await updateCheckPromise
+ if (!info) return null
+ const { dismissedUpdateVersion } = await loadSettings()
+ return { ...info, dismissed: info.version === dismissedUpdateVersion }
+ })
return manager
}