Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moneexa committed Nov 21, 2023
1 parent 397a676 commit 3ff38e1
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 423 deletions.
106 changes: 3 additions & 103 deletions cypress/e2e/adrManagerTest/AddNewAdr.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,117 +4,17 @@ context("Adding a new ADR to a repo", () => {
it("Create a new ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))
cy.visit(TEST_BASE_URL);

// add the ADR-Manager repo
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql', (req) => {
const authToken = window.localStorage.getItem("authId");

if (!authToken) {
// Handle missing authentication token
req.reply({
statusCode: 401,
body: { error: 'Unauthorized' },
});
return;
}

const { body } = req;
const expectedQuery = `query {
user(login: "Moneexa") {
repositories(first: 5, after: null, orderBy: { field: UPDATED_AT, direction: DESC }) {
nodes {
id
resourcePath
updatedAt
description
defaultBranchRef {
name
}
}
}
}
}`

if (Object.values(body)[0].includes(expectedQuery)) {
// Handle the GraphQL query as needed
req.reply({
statusCode: 200,
body: {
"data": {
"data": {
"user": {
"repositories": {
"nodes": [
{
"id": "MDEwOlJlcG9zaXRvcnkzMDQwMTM4MjY=",
"resourcePath": "/adr/adr-manager",
"updatedAt": "2023-11-13T13:30:58Z",
"description": "ADR-Manager",
"defaultBranchRef": {
"name": "main"
}
},
{
"id": "R_kgDOKsK_Sw",
"resourcePath": "/tasbihaasim/crowdnave",
"updatedAt": "2023-11-11T14:45:09Z",
"description": null,
"defaultBranchRef": {
"name": "master"
}
},
{
"id": "R_kgDOKsK6Ww",
"resourcePath": "/tasbihaasim/UPISAS",
"updatedAt": "2023-11-11T11:50:40Z",
"description": "unofficial fork of the UPISAS repository",
"defaultBranchRef": {
"name": "main"
}
},
{
"id": "R_kgDOKrHqDg",
"resourcePath": "/Moneexa/CrowdNav",
"updatedAt": "2023-11-09T11:32:01Z",
"description": "A model problem for big data self adaptive systems using SUMO and TraCI",
"defaultBranchRef": {
"name": "master"
}
},
{
"id": "R_kgDOKiLYvA",
"resourcePath": "/Moneexa/MyArdoqTask",
"updatedAt": "2023-10-18T22:43:31Z",
"description": null,
"defaultBranchRef": {
"name": "master"
}
}
]
}
}
}
}
}
});
} else {
// Fallback for unexpected requests
req.reply({
statusCode: 500,
body: { error: 'Unexpected request' },
});
}
}).as('getRepos');

// Continue with your Cypress test logic
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();

cy.get("[data-cy=addRepoDialog]").click();
cy.get("[data-cy=repoNameList]").click();

cy.get("[data-cy=adrList]").then((adrList) => {
// get number of ADRs in repo
const adrCount = Cypress.$(adrList).length;
Expand Down
9 changes: 5 additions & 4 deletions cypress/e2e/adrManagerTest/AddRepo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ context("Listing and adding repositories", () => {
beforeEach(() => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))
cy.visit(TEST_BASE_URL);
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.intercept("GET", "**/user/repos**").as("getRepos");
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
});

it("Check if at least 1 repository is displayed", () => {
cy.get("[data-cy=listRepo]").should("have.length.greaterThan", 0);
});

it("Add all repositories", () => {
cy.get("[data-cy=listRepo]").then((listing) => {
const numberOfAddedRepositories = 3;
Expand All @@ -31,11 +32,11 @@ context("Listing and adding repositories", () => {

// confirm repo adding dialog
cy.get("[data-cy=addRepoDialog]").click();
cy.intercept("GET", "**/repos**").as("showRepos");
cy.intercept("GET", "**/repos/**").as("showRepos");
cy.wait("@showRepos", { timeout: 15000 });

// check if the correct number of repos was added
cy.get("[data-cy=repoNameList]").children().should("have.length", numberOfAddedRepositories);
});
});
});
});
14 changes: 10 additions & 4 deletions cypress/e2e/adrManagerTest/DeleteAdr.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ context("Deleting an ADR from a repo", () => {
it("Remove one ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))

cy.visit(TEST_BASE_URL);

// add the ADR-Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
cy.get("[data-cy=addRepoDialog]").click();
cy.intercept("GET", "**/repos**").as("showRepos");
// cy.intercept('POST', 'https://api.github.com/graphql').as("showRepos");
cy.intercept("GET", "**/repos/**").as("showRepos");

cy.wait("@showRepos", { timeout: 10000 });

cy.get("[data-cy=adrList]").then((adrList) => {
// get number of ADRs in repo
const adrCount = Cypress.$(adrList).length;

const adrCount = Cypress.$(adrList).length;
// delete the last one
cy.get("[data-cy=deleteAdrBtn]").eq(0).click();
cy.get("[data-cy=dialogDeleteAdrBtn]").click();
Expand All @@ -30,7 +35,8 @@ context("Deleting an ADR from a repo", () => {
const addedRepos = JSON.parse(localStorage.getItem("addedRepositories"));
expect(addedRepos[0].adrs.length).to.eq(adrCount - 1);
expect(addedRepos[0].deletedAdrs.length).to.eq(1);
// });
});
});
})
});
});
6 changes: 5 additions & 1 deletion cypress/e2e/adrManagerTest/DeleteRepo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ context("Deleting repositories", () => {
it("Remove a repo", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))

cy.visit(TEST_BASE_URL);

// add ADR Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);

Expand Down
5 changes: 4 additions & 1 deletion cypress/e2e/adrManagerTest/Modes.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ context("Using editor modes", () => {
it("Switch to professional mode and create a new ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))

cy.visit(TEST_BASE_URL);

// add ADR Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/adrManagerTest/Parser.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ context("Using Markdown modes", () => {
it("Convert raw Markdown", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))

cy.visit(TEST_BASE_URL);

// add ADR Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
Expand Down
30 changes: 18 additions & 12 deletions cypress/e2e/adrManagerTest/PushNewAdr.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { TEST_BASE_URL } from "../../support/e2e";

context("Committing, pushing, and remote-deleting an ADR", () => {
it("Commit and push new ADR, then delete from GitHub", () => {
const REPO_NAME = "adr/adr-test-repository-empty";
const BRANCH_NAME = "testing-branch";
const REPO_NAME = "adr/adr";
const BRANCH_NAME = "gh-pages";

function addRepositoryAndSwitchBranch() {
// add the ADR-Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=search-field-for-adding-repository]").type(REPO_NAME);
Expand All @@ -33,6 +34,7 @@ context("Committing, pushing, and remote-deleting an ADR", () => {

window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))
cy.visit(TEST_BASE_URL);

addRepositoryAndSwitchBranch();
Expand All @@ -56,17 +58,21 @@ context("Committing, pushing, and remote-deleting an ADR", () => {
cy.get("[data-cy=textFieldCommitMessage]").type("[E2ETest] Add a new ADR");
cy.get("[data-cy=mdiCheckCommitMessage]").should("be.visible");
// push to GitHub
cy.get("[data-cy=btnOfDialogCommitForPush]").click();

cy.intercept("GET", "**/repos/**/branches/**").as("getCommitSha");
cy.intercept("POST", "**/repos/**/git/commits?**").as("commitRequest");
cy.get("[data-cy=btnOfDialogCommitForPush]").click();
cy.wait("@getCommitSha");
cy.wait("@commitRequest").then((val) => {
cy.log(val.request);
for (let item in val.request) {
cy.log(item);
}
cy.log(val.request.body.author);
});

// cy.wait("@getCommitSha");
// cy.wait("@commitRequest")

// .then((val) => {
// cy.log(val.request);
// for (let item in val.request) {
// cy.log(item);
// }
// cy.log(val.request.body.author);
// });
cy.contains("OK").click();

// Remove repository
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/adrManagerTest/Routing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ context("Routing and correct URLs", () => {
beforeEach(() => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("user"))
cy.visit(TEST_BASE_URL);
});

it("URL corresponds to opened repo and ADR", () => {
cy.url().should("equal", TEST_BASE_URL);

// add the ADR-Manager repo
cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
Expand Down
Loading

0 comments on commit 3ff38e1

Please sign in to comment.