|
| 1 | +import { expect } from "e2e"; |
| 2 | +import * as Effect from "effect/Effect"; |
| 3 | +import * as FileSystem from "effect/FileSystem"; |
| 4 | +import * as Path from "effect/Path"; |
| 5 | + |
| 6 | +import { MOBILE, MOBILE_T3_HOME } from "../e2e.config.ts"; |
| 7 | +import { run } from "./shell.ts"; |
| 8 | +import { makeState, runPromise } from "./t3.ts"; |
| 9 | +import { IOS, test } from "./t3-mobile.ts"; |
| 10 | + |
| 11 | +// Stand in for the Azure CLI upstream: 60 open work items, so the list's first 50 have a next |
| 12 | +// page. It counts each request for that page and refuses it while `next-page-fails` exists. |
| 13 | +const azureCli = String.raw`#!/usr/bin/env node |
| 14 | +import { appendFileSync, existsSync, readFileSync } from "node:fs"; |
| 15 | +
|
| 16 | +const args = process.argv.slice(2); |
| 17 | +const argument = (name) => args[args.indexOf(name) + 1]; |
| 18 | +const items = Array.from({ length: 60 }, (_, index) => { |
| 19 | + const id = 60 - index; |
| 20 | + return { |
| 21 | + id, |
| 22 | + url: "https://dev.azure.com/scenario/_apis/wit/workItems/" + id, |
| 23 | + fields: { |
| 24 | + "System.Title": "Release check " + id, |
| 25 | + "System.State": "Active", |
| 26 | + "System.TeamProject": "Release", |
| 27 | + "System.WorkItemType": "Task", |
| 28 | + "System.CreatedDate": "2026-10-01T00:00:00Z", |
| 29 | + "System.ChangedDate": new Date(Date.UTC(2026, 9, 2, 0, id)).toISOString(), |
| 30 | + }, |
| 31 | + }; |
| 32 | +}); |
| 33 | +let output; |
| 34 | +switch (argument("--resource")) { |
| 35 | + case "workitemtypes": |
| 36 | + output = { value: [{ name: "Task", states: [ |
| 37 | + { name: "Active", category: "InProgress" }, |
| 38 | + { name: "Closed", category: "Completed" }, |
| 39 | + ] }] }; |
| 40 | + break; |
| 41 | + case "wiql": { |
| 42 | + const { query } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); |
| 43 | + const before = /\[System\.Id\] < (\d+)/.exec(query)?.[1]; |
| 44 | + if (before !== undefined) { |
| 45 | + appendFileSync(new URL("./next-page-requests", import.meta.url), "."); |
| 46 | + if (existsSync(new URL("./next-page-fails", import.meta.url))) { |
| 47 | + console.error("ERROR: The request timed out."); |
| 48 | + process.exit(1); |
| 49 | + } |
| 50 | + } |
| 51 | + output = { workItems: items |
| 52 | + .filter((item) => before === undefined || item.id < Number(before)) |
| 53 | + .map(({ id }) => ({ id })) }; |
| 54 | + break; |
| 55 | + } |
| 56 | + case "workitemsbatch": { |
| 57 | + const { ids } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); |
| 58 | + output = { value: items.filter(({ id }) => ids.includes(id)) }; |
| 59 | + break; |
| 60 | + } |
| 61 | + default: |
| 62 | + if (args[0] === "repos" && args[1] === "show") { |
| 63 | + output = { |
| 64 | + name: "release", |
| 65 | + project: { name: "Release" }, |
| 66 | + webUrl: "https://dev.azure.com/scenario/Release/_git/release", |
| 67 | + remoteUrl: "https://dev.azure.com/scenario/Release/_git/release", |
| 68 | + sshUrl: "git@ssh.dev.azure.com:v3/scenario/Release/release", |
| 69 | + }; |
| 70 | + break; |
| 71 | + } |
| 72 | + process.exit(1); |
| 73 | +} |
| 74 | +console.log(JSON.stringify(output)); |
| 75 | +`; |
| 76 | + |
| 77 | +test( |
| 78 | + "A failed next page of issues waits for Try again instead of loading again on scroll", |
| 79 | + IOS, |
| 80 | + async ({ t3, app, screen }) => { |
| 81 | + const workspace = await t3.project("demo"); |
| 82 | + const { repository, fails, requests } = await runPromise( |
| 83 | + Effect.gen(function* () { |
| 84 | + const path = yield* Path.Path; |
| 85 | + const fs = yield* FileSystem.FileSystem; |
| 86 | + const bin = path.join(MOBILE_T3_HOME, "bin"); |
| 87 | + yield* fs.writeFileString(path.join(bin, "az"), azureCli); |
| 88 | + yield* fs.chmod(path.join(bin, "az"), 0o755); |
| 89 | + yield* fs.writeFileString(path.join(bin, "next-page-fails"), ""); |
| 90 | + yield* fs.writeFileString(path.join(bin, "next-page-requests"), ""); |
| 91 | + return { |
| 92 | + repository: path.join(MOBILE_T3_HOME, "release"), |
| 93 | + fails: path.join(bin, "next-page-fails"), |
| 94 | + requests: path.join(bin, "next-page-requests"), |
| 95 | + }; |
| 96 | + }), |
| 97 | + ); |
| 98 | + const nextPageRequests = () => |
| 99 | + runPromise( |
| 100 | + Effect.flatMap(FileSystem.FileSystem, (fs) => fs.readFileString(requests)).pipe( |
| 101 | + Effect.map((asked) => asked.length), |
| 102 | + ), |
| 103 | + ); |
| 104 | + await runPromise(run("git", ["clone", "--quiet", workspace, repository])); |
| 105 | + await runPromise( |
| 106 | + run( |
| 107 | + "git", |
| 108 | + ["remote", "set-url", "origin", "https://dev.azure.com/scenario/Release/_git/release"], |
| 109 | + { cwd: repository }, |
| 110 | + ), |
| 111 | + ); |
| 112 | + const primary = makeState(MOBILE_T3_HOME, { T3CODE_PORT: String(MOBILE.serverPort) }); |
| 113 | + await runPromise(primary.cli(["project", "add", repository, "--title", "Release"])); |
| 114 | + try { |
| 115 | + // A local simulator keeps the last run's pairing. |
| 116 | + await app.clearState().catch(() => {}); |
| 117 | + await t3.open(); |
| 118 | + // Pull requests and issues share one tab; its title switches between them. |
| 119 | + await screen.getByRole("tab", "PRs").tap({ timeout: 120_000 }); |
| 120 | + await screen.getByLabel("Pull requests, switch list").tap(); |
| 121 | + await screen.getByRole("button", "Issues").tap(); |
| 122 | + await screen.getByRole("button", /Release check 60,/).waitFor({ timeout: 60_000 }); |
| 123 | + |
| 124 | + const lastOfFirstPage = screen.getByRole("button", /Release check 11,/); |
| 125 | + const toTheEnd = async () => { |
| 126 | + await screen.scrollUntilVisible(lastOfFirstPage, { direction: "down", momentum: "fast" }); |
| 127 | + await screen.swipe({ direction: "down" }); |
| 128 | + }; |
| 129 | + const retry = screen.getByRole("button", "Retry loading more issues"); |
| 130 | + await toTheEnd(); |
| 131 | + // Reaching the end asks for the next page, which fails. |
| 132 | + await expect(retry).toBeVisible(); |
| 133 | + expect(await nextPageRequests()).toBe(1); |
| 134 | + await app.screenshot("end-of-the-list-after-the-next-page-failed"); |
| 135 | + |
| 136 | + // Back toward the top and to the end again, without a tap. |
| 137 | + await screen.swipe({ direction: "up" }); |
| 138 | + await screen.swipe({ direction: "up" }); |
| 139 | + await app.screenshot("back-toward-the-top"); |
| 140 | + await toTheEnd(); |
| 141 | + await app.screenshot("end-of-the-list-again"); |
| 142 | + await expect(retry).toBeVisible(); |
| 143 | + expect(await nextPageRequests()).toBe(1); |
| 144 | + |
| 145 | + await runPromise(Effect.flatMap(FileSystem.FileSystem, (fs) => fs.remove(fails))); |
| 146 | + await retry.tap(); |
| 147 | + await expect(screen.getByRole("button", /Release check 10,/)).toBeVisible(); |
| 148 | + await app.screenshot("next-page-after-try-again"); |
| 149 | + } finally { |
| 150 | + await runPromise(primary.cli(["project", "remove", repository, "--force"])); |
| 151 | + } |
| 152 | + }, |
| 153 | +); |
0 commit comments