Skip to content

Commit

Permalink
test: improve e2e tests using expecthelper
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Nov 23, 2024
1 parent 3de4f4e commit a380b84
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions e2e/codecept.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exports.config = {
osVersion: "11",
},
},
ExpectHelper: {},
},

multiple: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/steps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type IndexPage = typeof import('./utils/IndexPage');

declare namespace CodeceptJS {
interface SupportObject { I: I, current: any, util: util, IndexPage: IndexPage }
interface Methods extends WebDriver {}
interface Methods extends WebDriver, ExpectHelper {}
interface I extends WithTranslation<Methods> {}
namespace Translation {
interface Actions {}
Expand Down
10 changes: 7 additions & 3 deletions e2e/tests/pages/user/project/version/NewVersionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ Feature("New Version Page");

Scenario("Test New Version", async ({ I, util }) => {
await util.login();
util.openHangarPage("/e2e_user/e2e_test/versions/new");

const projectName = "e2e_test-" + util.randomNumber();
await util.createProject(projectName, process.env.E2E_USER_ID);
util.openHangarPage("/e2e_user/" + projectName + "/versions/new");

const name = "1." + util.randomNumber() + "." + util.randomNumber();

Expand Down Expand Up @@ -79,6 +82,7 @@ Scenario("Test New Version", async ({ I, util }) => {
I.seeElement(locate("span").withText("1.18.2, 1.19.4"));
await I.seeElement(locate(".tags").withText("e2etest"));

await util.deleteVersion("e2e_test", name);
await util.deleteChannel("e2e_test", "e2etest");
await util.deleteVersion(projectName, name);
await util.deleteChannel(projectName, "e2etest");
await util.deleteProject(projectName);
});
27 changes: 23 additions & 4 deletions e2e/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = new (class {
if (result.status != 204) {
console.log(await result.text());
}
expect(result.status, "project deletion to return 200").to.equal(204);
await I.expectEqual(result.status, 204, "project deletion to return 204");
}

public async deleteOrg(name: string) {
Expand All @@ -86,7 +86,7 @@ module.exports = new (class {
if (result.status != 200) {
console.log(await result.text());
}
expect(result.status, "org deletion to return 200").to.equal(200);
await I.expectEqual(result.status, 200, "org deletion to return 200");
}

public async deleteVersion(name: string, project: string) {
Expand All @@ -98,7 +98,7 @@ module.exports = new (class {
if (result.status != 200) {
console.log(await result.text());
}
expect(result.status, "org deletion to return 200").to.equal(200);
await I.expectEqual(result.status, 200, "version deletion to return 200");
}

public async deleteChannel(project: string, channel: string) {
Expand All @@ -109,6 +109,25 @@ module.exports = new (class {
if (result.status != 200) {
console.log(await result.text());
}
expect(result.status, "org deletion to return 200").to.equal(200);
await I.expectEqual(result.status, 200, "channel deletion to return 200");
}

public async createProject(project: string, owner_id: number) {
const result = await fetch(this.url + "/api/internal/projects/create", {
method: "POST",
headers: { Authorization: "Bearer " + (await this.getJwt()), "Content-Type": "application/json" },
body: JSON.stringify({
category: "admin_tools",
settings: { license: { type: "Unspecified" }, donation: {}, keywords: [], links: [], tags: [] },
ownerId: owner_id,
name: project,
description: "E2E Test Project",
pageContent: "# " + project + " \nWelcome to your new project!",
}),
});
if (result.status != 200) {
console.log(await result.text());
}
await I.expectEqual(result.status, 200, "project creation to return 200");
}
})();

0 comments on commit a380b84

Please sign in to comment.