From 083af321880d4e5ee81bf6902052a5d87f11fa87 Mon Sep 17 00:00:00 2001 From: Bob Qiu Date: Tue, 20 Oct 2026 10:30:54 +0800 Subject: [PATCH] feat: enhance undiscardable warning tests for git sync functionality --- .../skills/write-insomnia-test/reference.md | 2 +- ...h-kind-of-real-edit-is-not-flagged.spec.ts | 78 +++++++++++++++++++ .../staged-file-shows-no-warning.spec.ts | 41 ++++++++-- 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 packages/insomnia-test/tests/git-sync/undiscardable-change/each-kind-of-real-edit-is-not-flagged.spec.ts diff --git a/.claude/skills/write-insomnia-test/reference.md b/.claude/skills/write-insomnia-test/reference.md index 627e7c7490..50d577ac63 100644 --- a/.claude/skills/write-insomnia-test/reference.md +++ b/.claude/skills/write-insomnia-test/reference.md @@ -1252,7 +1252,7 @@ deleteBranch(branch: string, switchToBranch = "master"): Promise // check ```ts // enums/git-change-list.ts — GitChangeList.Staged = "Staged changes" | GitChangeList.Unstaged = "Unstaged changes" openChangeDiff(list: GitChangeList, fileName: string): Promise // clicks the row and waits for the diff pane (Stage/Unstage this file button); the warning flag arrives with the diff, so once this resolves its presence/absence is settled -isUndiscardableWarningVisibleInDiff(): Promise // "This change is only Insomnia internally reformatting the file…" banner above the diff +isUndiscardableWarningVisible(): Promise // "This change is only Insomnia internally reformatting the file…" banner above the diff openDiscardConfirmation(fileName: string): Promise // clicks Discard on an unstaged row, waits for the "Discard Changes" dialog, does not confirm getDiscardConfirmationText(): Promise // the dialog's text isUndiscardableWarningVisibleInDiscardDialog(): Promise diff --git a/packages/insomnia-test/tests/git-sync/undiscardable-change/each-kind-of-real-edit-is-not-flagged.spec.ts b/packages/insomnia-test/tests/git-sync/undiscardable-change/each-kind-of-real-edit-is-not-flagged.spec.ts new file mode 100644 index 0000000000..24dc490e74 --- /dev/null +++ b/packages/insomnia-test/tests/git-sync/undiscardable-change/each-kind-of-real-edit-is-not-flagged.spec.ts @@ -0,0 +1,78 @@ +import { faker } from "@faker-js/faker"; + +import { GitChangeList } from "../../../enums/git-change-list"; +import { HttpMethod } from "../../../enums/http-method"; +import { ProjectType } from "../../../enums/project-types"; +import { HTTP_SERVER } from "../../../misc/constants"; +import { + DEFAULT_TIMEOUT, + expect, + GIT_CREDENTIAL, + pushServerFile, + test, +} from "../../../misc/git-fixtures"; +import { Collection } from "../../../models/collection"; +import { Project } from "../../../models/project"; +import { buildReorderedCollectionFile } from "./helpers"; + +test("Verify each kind of real edit on a reordered file is not flagged as only reformatting", async ({ + user, +}) => { + const { gitSyncFlow, httpRequestFlow, preferencesFlow, workspaceFlow } = + user.flowManager; + const { gitSyncPage, httpRequestPage } = user.pageManager; + + const fileName = `${faker.string.alpha(10).toLowerCase()}.yaml`; + const collectionName = faker.string.alpha(10); + const { content, requestName } = buildReorderedCollectionFile(collectionName); + await pushServerFile({ path: fileName, content }); + await preferencesFlow.addGitCredential(GIT_CREDENTIAL); + await workspaceFlow.create( + new Project(faker.string.alphanumeric(10), ProjectType.Git), + GIT_CREDENTIAL.name, + ); + const request = await httpRequestFlow.get( + requestName, + new Collection(collectionName), + ); + const edits = [ + () => workspaceFlow.rename(request!, faker.string.alphanumeric(10)), + () => httpRequestPage.setUrl(`${HTTP_SERVER}/${faker.string.alpha(10)}`), + () => httpRequestPage.setMethod(HttpMethod.Post), + () => + httpRequestPage.setHeaders([ + { name: faker.string.alpha(8), value: faker.string.alpha(8) }, + ]), + ]; + const warningsPerEdit: boolean[] = []; + for (const edit of edits) { + await edit(); + await expect + .poll(async () => (await gitSyncFlow.getChanges()).unstaged, { + timeout: DEFAULT_TIMEOUT, + }) + .toContain(fileName); + await gitSyncPage.openCommitDialog(); + await gitSyncPage.openChangeDiff(GitChangeList.Unstaged, fileName); + warningsPerEdit.push( + await gitSyncPage.isUndiscardableWarningVisible(), + ); + await gitSyncPage.closeCommitDialog(); + await gitSyncFlow.discardChangeAfterReview(fileName); + await expect + .poll( + async () => { + await gitSyncPage.openCommitDialog(); + await gitSyncPage.openChangeDiff(GitChangeList.Unstaged, fileName); + const hasWarning = + await gitSyncPage.isUndiscardableWarningVisible(); + await gitSyncPage.closeCommitDialog(); + return hasWarning; + }, + { timeout: DEFAULT_TIMEOUT }, + ) + .toBe(true); + } + + expect(warningsPerEdit).toEqual(edits.map(() => false)); +}); diff --git a/packages/insomnia-test/tests/git-sync/undiscardable-change/staged-file-shows-no-warning.spec.ts b/packages/insomnia-test/tests/git-sync/undiscardable-change/staged-file-shows-no-warning.spec.ts index b70144b76e..6524e0faf9 100644 --- a/packages/insomnia-test/tests/git-sync/undiscardable-change/staged-file-shows-no-warning.spec.ts +++ b/packages/insomnia-test/tests/git-sync/undiscardable-change/staged-file-shows-no-warning.spec.ts @@ -3,18 +3,20 @@ import { faker } from '@faker-js/faker'; import { GitChangeList } from '../../../enums/git-change-list'; import { ProjectType } from '../../../enums/project-types'; import { DEFAULT_TIMEOUT, expect, GIT_CREDENTIAL, pushServerFile, test } from '../../../misc/git-fixtures'; +import { Collection } from '../../../models/collection'; import { Project } from '../../../models/project'; import { buildReorderedCollectionFile } from './helpers'; -test('Verify a staged hand-reordered file shows no undiscardable warning', async ({ user }) => { - const { gitSyncFlow, preferencesFlow, workspaceFlow } = user.flowManager; +test('Verify a staged hand-reordered file shows no undiscardable warning, including for a real edit made after staging', async ({ + user, +}) => { + const { gitSyncFlow, httpRequestFlow, preferencesFlow, workspaceFlow } = user.flowManager; const { gitSyncPage } = user.pageManager; const fileName = `${faker.string.alpha(10).toLowerCase()}.yaml`; - await pushServerFile({ - path: fileName, - content: buildReorderedCollectionFile(faker.string.alpha(10)).content, - }); + const collectionName = faker.string.alpha(10); + const { content, requestName } = buildReorderedCollectionFile(collectionName); + await pushServerFile({ path: fileName, content }); await preferencesFlow.addGitCredential(GIT_CREDENTIAL); await workspaceFlow.create(new Project(faker.string.alphanumeric(10), ProjectType.Git), GIT_CREDENTIAL.name); await expect @@ -26,5 +28,30 @@ test('Verify a staged hand-reordered file shows no undiscardable warning', async await gitSyncPage.openCommitDialog(); await gitSyncPage.openChangeDiff(GitChangeList.Staged, fileName); - expect(await gitSyncPage.isUndiscardableWarningVisible()).toBe(false); + const hasStagedWarning = await gitSyncPage.isUndiscardableWarningVisible(); + await gitSyncPage.closeCommitDialog(); + + const request = await httpRequestFlow.get(requestName, new Collection(collectionName)); + await workspaceFlow.rename(request!, faker.string.alphanumeric(10)); + await expect + .poll(async () => (await gitSyncFlow.getChanges()).unstaged, { + timeout: DEFAULT_TIMEOUT, + }) + .toContain(fileName); + await gitSyncPage.openCommitDialog(); + await gitSyncPage.openChangeDiff(GitChangeList.Unstaged, fileName); + const hasUnstagedWarning = await gitSyncPage.isUndiscardableWarningVisible(); + await gitSyncPage.openDiscardConfirmation(fileName); + const hasDiscardDialogWarning = await gitSyncPage.isUndiscardableWarningVisibleInDiscardDialog(); + await gitSyncPage.confirmDiscard(); + + expect(hasStagedWarning).toBe(false); + expect(hasUnstagedWarning).toBe(false); + expect(hasDiscardDialogWarning).toBe(false); + await expect + .poll(async () => (await gitSyncPage.getUnstagedChanges()).includes(fileName), { + timeout: DEFAULT_TIMEOUT, + }) + .toBe(false); + expect(await gitSyncPage.getStagedChanges()).toContain(fileName); });