mirror of
https://github.com/Kong/insomnia.git
synced 2026-11-05 04:23:55 -05:00
feat: enhance undiscardable warning tests for git sync functionality
This commit is contained in:
3 files changed
+113
-8
No files matched your search
@@ -1252,7 +1252,7 @@ deleteBranch(branch: string, switchToBranch = "master"): Promise<void> // check
|
||||
```ts
|
||||
// enums/git-change-list.ts — GitChangeList.Staged = "Staged changes" | GitChangeList.Unstaged = "Unstaged changes"
|
||||
openChangeDiff(list: GitChangeList, fileName: string): Promise<void> // 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<boolean> // "This change is only Insomnia internally reformatting the file…" banner above the diff
|
||||
isUndiscardableWarningVisible(): Promise<boolean> // "This change is only Insomnia internally reformatting the file…" banner above the diff
|
||||
openDiscardConfirmation(fileName: string): Promise<void> // clicks Discard on an unstaged row, waits for the "Discard Changes" dialog, does not confirm
|
||||
getDiscardConfirmationText(): Promise<string> // the dialog's text
|
||||
isUndiscardableWarningVisibleInDiscardDialog(): Promise<boolean>
|
||||
|
||||
+78
@@ -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));
|
||||
});
|
||||
+34
-7
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user