Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Cypress Tests
Browse files Browse the repository at this point in the history
* Increase the `cy.wait` for Keycloak redirect from 600ms to 1200ms
* Add a `cy.wait(2000)` to the beginning of the Opportunity creation
  forms

Fix ZLTO Reward field in Cypress

More fixes

Remove unneeded sleep

Don't enable Credential Issuance

Wait 1s before/after entering opportunity keywords
rblaine95 committed May 8, 2024
1 parent 6a76bd4 commit 23c4456
Showing 3 changed files with 356 additions and 349 deletions.
274 changes: 140 additions & 134 deletions cypress/e2e/opportunities.cy.ts
Original file line number Diff line number Diff line change
@@ -9,137 +9,143 @@ declare global {
}
}

// describe(`Opportunities`, function () {
// const magicNumber = Math.floor(Math.random() * 1000000);
// this.magicNumber = magicNumber;

// before(function () {
// // set a variable on the context object
// this.magicNumber = magicNumber;
// });

// describe(`${TESTORGADMINUSER_EMAIL} (OrganisationAdmin role)`, () => {
// beforeEach(() => {
// cy.login(TESTORGADMINUSER_EMAIL, TESTORGADMINUSER_PASSWORD);
// });

// it("should create an opportunity", function () {
// // visit the home page
// cy.visit("http://localhost:3000", {
// // stub the console log and error methods for console assertions
// onBeforeLoad(win) {
// cy.stub(win.console, "log").as("consoleLog");
// cy.stub(win.console, "error").as("consoleError");
// },
// });
// cy.wait(10000);

// //* click on the first organisation link on the user menu
// cy.get(`button[id="btnUserMenu"]`).should("exist").click();
// cy.get(`#organisations a`).first().click();
// cy.wait(10000);

// // href should end with /organisations/guid
// cy.location("href").then((href) => {
// const match = href.match(/\/organisations\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/);
// if (match) {
// // store the organisation guid in an alias
// cy.wrap(match[1]).as("guid");
// } else {
// throw new Error("Organisation guid not found in href");
// }
// });

// //* click on the opportunities link on the navigation menu
// cy.get(`button[id="btnNavbarMenu"]`).should("exist").click();
// cy.wait(200);
// cy.get(`a[id="lnkNavbarMenuModal_Opportunities"]`).first().click();
// cy.wait(6000);

// // href shoud be /organisations/guid/opportunities
// cy.get("@guid").then((guid) => {
// cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities`);
// });

// //* click on the create opportunity button
// cy.get(`a[id="btnCreateOpportunity"]`).should("exist").click();
// cy.wait(10000);

// // href should be /organisations/guid/opportunities/create
// cy.get("@guid").then((guid) => {
// cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities/create`);
// });

// //* step 1: fill out form and click next
// cy.get("input[name=title]").type(`Test Opportunity ${this.magicNumber}`);
// cy.get("input[id=input_typeid]").type("Learning{enter}");
// cy.get("input[id=input_categories]").type("Agriculture{enter}Business and Entrepreneurship{enter}");
// cy.get("input[name=uRL]").type(`https://www.testopportunity.com`);
// cy.get("textarea[name=description]").type("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");

// cy.get("button[type=submit]").should("exist").click();

// //* step 2: fill out form and click next
// cy.get("input[id=input_languages]").type("Afrikaans{enter}");
// cy.get("input[id=input_countries]").type("Botswana{enter}South Africa{enter}");
// cy.get("input[id=input_difficultyId]").type("Beginner{enter}");
// cy.get("input[name=commitmentIntervalCount]").type(`1`);
// cy.get("input[id=input_commitmentIntervalId]").type("Day{enter}");
// const today = new Date();
// cy.get("input[id=input_dateStart]").type(`${today.toISOString().slice(0, 10)}{enter}`);
// today.setDate(today.getDate() + 1);
// cy.get("input[id=input_dateEnd]").type(`${today.toISOString().slice(0, 10)}{enter}`);
// cy.get("input[name=participantLimit]").type(`1000`);

// cy.get("button[type=submit]").should("exist").click();

// //* step 3: fill out form and click next
// cy.get("input[name=yomaReward]").type(`1`);
// cy.get("input[name=zltoReward]").type(`2`);
// cy.get("input[id=input_skills]").type(".net assemblies{enter}10 Gigabit Ethernet{enter}3D Animation{enter}");

// cy.get("button[type=submit]").should("exist").click();

// //* step 4: fill out form and click next
// cy.get("input[id=input_keywords]").type("keyword1{enter}keyword2{enter}keyword3{enter}");

// cy.get("button[type=submit]").should("exist").click();

// //* step 5: fill out form and click next
// cy.get("button[type=submit]").should("exist").click();
// cy.get("input[id=verificationEnabledManual]").check();
// cy.get(`input[id="chk_verificationType_File Upload"]`).check();
// cy.get(`input[id="input_verificationType_File Upload"]`).type("2", { moveToEnd: true });
// cy.get(`input[id="chk_verificationType_Location"]`).check();
// cy.get(`input[id="input_verificationType_Location"]`).type("2", { moveToEnd: true });
// cy.get(`input[id="chk_verificationType_Picture"]`).check();
// cy.get(`input[id="input_verificationType_Picture"]`).type("2", { moveToEnd: true });
// cy.get(`input[id="chk_verificationType_Voice Note"]`).check();
// cy.get(`input[id="input_verificationType_Voice Note"]`).type("2", { moveToEnd: true });

// cy.get("button[type=submit]").should("exist").click();

// //* step 6: fill out form and click next
// cy.get("input[name=credentialIssuanceEnabled]").check();
// cy.wait(500);
// cy.get("input[id=input_ssiSchemaName]").type("Default{enter}");

// cy.get("button[type=submit]").should("exist").click();

// //* step 7: fill out form and click submit
// cy.get("input[name=postAsActive]").check();

// cy.get("button[type=submit]").should("exist").click();

// // assert toast message
// cy.get(".Toastify__toast-container").should("be.visible");
// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Opportunity created");

// // href shoud be /organisations/guid/opportunities
// cy.get("@guid").then((guid) => {
// cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities`);
// });
// });
// });
// });
describe(`Opportunities`, function () {
const magicNumber = Math.floor(Math.random() * 1000000);
this.magicNumber = magicNumber;

before(function () {
// set a variable on the context object
this.magicNumber = magicNumber;
});

describe(`${TESTORGADMINUSER_EMAIL} (OrganisationAdmin role)`, () => {
beforeEach(() => {
cy.login(TESTORGADMINUSER_EMAIL, TESTORGADMINUSER_PASSWORD);
});

it("should create an opportunity", function () {
// visit the home page
cy.visit("http://localhost:3000", {
// stub the console log and error methods for console assertions
onBeforeLoad(win) {
cy.stub(win.console, "log").as("consoleLog");
cy.stub(win.console, "error").as("consoleError");
},
});
cy.wait(10000);

//* click on the first organisation link on the user menu
cy.get(`button[id="btnUserMenu"]`).should("exist").click();
cy.get(`#organisations a`).first().click();
cy.wait(10000);

// href should end with /organisations/guid
cy.location("href").then((href) => {
const match = href.match(/\/organisations\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/);
if (match) {
// store the organisation guid in an alias
cy.wrap(match[1]).as("guid");
} else {
throw new Error("Organisation guid not found in href");
}
});

//* click on the opportunities link on the navigation menu
cy.get(`button[id="btnNavbarMenu"]`).should("exist").click();
cy.wait(200);
cy.get(`a[id="lnkNavbarMenuModal_Opportunities"]`).first().click();
cy.wait(6000);

// href shoud be /organisations/guid/opportunities
cy.get("@guid").then((guid) => {
cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities`);
});

//* click on the create opportunity button
cy.get(`a[id="btnCreateOpportunity"]`).should("exist").click();
cy.wait(10000);

// href should be /organisations/guid/opportunities/create
cy.get("@guid").then((guid) => {
cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities/create`);
});

//* step 1: fill out form and click next
cy.get("input[name=title]").type(`Test Opportunity ${this.magicNumber}`);
cy.get("input[id=input_typeid]").type("Learning{enter}");
cy.get("input[id=input_categories]").type("Agriculture{enter}Business and Entrepreneurship{enter}");
cy.get("input[name=uRL]").type(`https://www.testopportunity.com`);
cy.get("textarea[name=description]").type("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");

cy.get("button[type=submit]").should("exist").click();

//* step 2: fill out form and click next
cy.wait(2000);
cy.get("input[id=input_languages]").type("Afrikaans{enter}");
cy.get("input[id=input_countries]").type("Botswana{enter}South Africa{enter}");
cy.get("input[id=input_difficultyId]").type("Beginner{enter}");
cy.get("input[name=commitmentIntervalCount]").type(`1`);
cy.get("input[id=input_commitmentIntervalId]").type("Day{enter}");
const today = new Date();
cy.get("input[id=input_dateStart]").type(`${today.toISOString().slice(0, 10)}{enter}`);
today.setDate(today.getDate() + 1);
cy.get("input[id=input_dateEnd]").type(`${today.toISOString().slice(0, 10)}{enter}`);
cy.get("input[name=participantLimit]").type(`1000`);

cy.get("button[type=submit]").should("exist").click();

//* step 3: fill out form and click next
cy.wait(2000);
cy.get("input[name=zltoReward]").type(`1`);
cy.get("input[name=zltoRewardPool]").type(`2`);
cy.get("input[id=input_skills]").type(".net assemblies{enter}10 Gigabit Ethernet{enter}3D Animation{enter}");

cy.get("button[type=submit]").should("exist").click();

//* step 4: fill out form and click next
cy.wait(1000);
cy.get("input[id=input_keywords]").type("keyword1{enter}keyword2{enter}keyword3{enter}");
cy.wait(1000);

cy.get("button[type=submit]").should("exist").click();

//* step 5: fill out form and click next
cy.wait(2000);
cy.get("button[type=submit]").should("exist").click();
cy.get("input[id=verificationEnabledManual]").click();
cy.get(`input[id="chk_verificationType_File Upload"]`).click();
cy.get(`input[id="input_verificationType_File Upload"]`).type("2", { moveToEnd: true });
cy.get(`input[id="chk_verificationType_Location"]`).click();
cy.get(`input[id="input_verificationType_Location"]`).type("2", { moveToEnd: true });
cy.get(`input[id="chk_verificationType_Picture"]`).click();
cy.get(`input[id="input_verificationType_Picture"]`).type("2", { moveToEnd: true });
cy.get(`input[id="chk_verificationType_Voice Note"]`).click();
cy.get(`input[id="input_verificationType_Voice Note"]`).type("2", { moveToEnd: true });

cy.get("button[type=submit]").should("exist").click();

//* step 6: fill out form and click next
// Enabling Credential Issuance requires access to CloudAPI
// cy.get("input[name=credentialIssuanceEnabled]").click();
// cy.wait(500);
// cy.get("input[id=input_ssiSchemaName]").type("Default{enter}");

cy.get("button[type=submit]").should("exist").click();

//* step 7: fill out form and click submit
cy.get("input[name=postAsActive]").check();

cy.get("button[type=submit]").should("exist").click();

// assert toast message
cy.get(".Toastify__toast-container").should("be.visible");
// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Opportunity created");

// href shoud be /organisations/guid/opportunities
cy.get("@guid").then((guid) => {
cy.location("href").should("eq", `http://localhost:3000/organisations/${guid}/opportunities`);
});
});
});
});
428 changes: 214 additions & 214 deletions cypress/e2e/organisations.cy.ts
Original file line number Diff line number Diff line change
@@ -23,217 +23,217 @@ declare global {
}
}

// describe(`Organisation Registration & Approval`, function () {
// const magicNumber = Math.floor(Math.random() * 1000000);
// this.magicNumber = magicNumber;

// before(function () {
// // set a variable on the context object
// this.magicNumber = magicNumber;
// });

// describe(`${TESTUSER_EMAIL} (User role)`, () => {
// beforeEach(() => {
// cy.login(TESTUSER_EMAIL, TESTUSER_PASSWORD);
// });

// it("should register an organisation", function () {
// // visit the registration page
// cy.visit("http://localhost:3000/organisations/register", {
// // stub the console log and error methods for console assertions
// onBeforeLoad(win) {
// cy.stub(win.console, "log").as("consoleLog");
// cy.stub(win.console, "error").as("consoleError");
// },
// });
// cy.wait(500);

// //* step 1: fill out form and click next
// cy.get("input[name=name]").type(`Test Organisation ${this.magicNumber}`);
// cy.get("textarea[name=streetAddress]").type("123 Fake Street");
// cy.get("input[name=province]").type("Bogusville");
// cy.get("input[name=city]").type("Fake City");
// cy.get("select[name=countryId]").select(COUNTRY_ID);
// cy.get("input[name=postalCode]").type("1234");
// cy.get("input[name=websiteURL]").type("http://www.google.com");
// cy.fixture("org_logo.png").then((fileContent) => {
// cy.get("input[type=file][name=logo]").attachFile({
// fileContent: fileContent.toString(),
// fileName: "org_logo.png",
// mimeType: "image/png",
// });
// });
// cy.get("input[name=tagline]").type("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
// cy.get("textarea[name=biography]").type(
// "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa."
// );

// cy.wait(500);
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(500);

// //* step 2: fill out form and click next
// cy.get(`input[type=checkbox][name=providerTypes][value="${PROVIDER_TYPE_IMPACT_ID}"]`).check(); // check the "Impact" checkbox

// cy.fixture("dummy.pdf").then((fileContent) => {
// cy.get("input[type=file][name=registration]").attachFile({
// fileContent: fileContent.toString(),
// fileName: "dummy.pdf",
// mimeType: "application/pdf",
// });
// });

// cy.wait(500);
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(500);

// //* step 3: click submit
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(14000);

// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Organisation registered");

// // href should be /organisations/register/success
// cy.location("href").should("eq", "http://localhost:3000/organisations/register/success");
// });

// it("should edit an organisation", function () {
// // visit the home page
// cy.visit("http://localhost:3000/", {
// // stub the console log and error methods for console assertions
// onBeforeLoad(win) {
// cy.stub(win.console, "log").as("consoleLog");
// cy.stub(win.console, "error").as("consoleError");
// },
// });
// cy.wait(500);

// //* click on the organisation on the user menu
// cy.get(`button[id="btnUserMenu`).first().click();
// cy.get(`a[id="userMenu_orgs_Test Organisation ${this.magicNumber}"]`).first().click();
// cy.wait(4000);

// // href should end with /edit
// cy.location("href").should("match", /\/edit$/);

// //* step 1: update form and click submit
// cy.get("input[name=name]").type(" updated", { moveToEnd: true });
// cy.get("textarea[name=streetAddress]").type(" updated", { moveToEnd: true });
// cy.get("input[name=province]").type(" updated", { moveToEnd: true });
// cy.get("input[name=city]").type(" updated", { moveToEnd: true });
// cy.get("select[name=countryId]").select(COUNTRY_ID2);
// cy.get("input[name=postalCode]").type("4321");
// cy.get("input[name=websiteURL]").type(".2", { moveToEnd: true });
// cy.get("input[name=tagline]").type(" updated", { moveToEnd: true });
// cy.get("textarea[name=biography]").type(" updated", { moveToEnd: true });
// cy.get("button.filepond--action-remove-item").click(); // remove existing image
// cy.fixture("org_logo.png").then((fileContent) => {
// cy.get("input[type=file][name=logo]").attachFile({
// fileContent: fileContent.toString(),
// fileName: "org_logo.png",
// mimeType: "image/png",
// });
// });

// cy.wait(500);
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(500);

// // assert toast message
// cy.get(".Toastify__toast-container").should("be.visible");
// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");

// //* step 2: update form and click submit
// cy.get("a[id=lnkOrganisationRoles]").click(); // click on the roles tab
// cy.wait(500);
// cy.get(`input[type=checkbox][name=providerTypes][value="${PROVIDER_TYPE_EDUCATION_ID}"]`).check(); // check the "Education" checkbox
// cy.fixture("dummy.pdf").then((fileContent) => {
// cy.get("input[type=file][name=education]").attachFile({
// fileContent: fileContent.toString(),
// fileName: "dummy.pdf",
// mimeType: "application/pdf",
// });
// });
// cy.wait(500);
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(500);

// // assert toast message
// cy.get(".Toastify__toast-container").should("be.visible");
// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");

// //* step 3: click submit
// cy.get("a[id=lnkOrganisationAdmins]").click(); // click on the admins tab
// cy.wait(500);
// cy.get("button[type=submit]").should("exist").click();
// cy.wait(500);

// // assert toast message
// cy.get(".Toastify__toast-container").should("be.visible");
// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");
// });
// });

// describe(`${TESTADMINUSER_EMAIL} (Admin role)`, () => {
// beforeEach(() => {
// cy.login(TESTADMINUSER_EMAIL, TESTADMINUSER_PASSWORD);
// });

// it("should approve the organisation", function () {
// // visit the admin page
// cy.visit("http://localhost:3000/admin", {
// // stub the console log and error methods for console assertions
// onBeforeLoad(win) {
// cy.stub(win.console, "log").as("consoleLog");
// cy.stub(win.console, "error").as("consoleError");
// },
// });
// cy.wait(500);

// //* click on the admin link on the user menu
// cy.get(`button[id="btnUserMenu`).should("exist").click();
// cy.get(`a[id="userMenu_admin"]`).should("exist").click();
// cy.wait(1000);

// // href should end with /admin
// cy.location("href").should("match", /\/admin$/);

// //* click on the organisations link on the navigation menu
// cy.get(`button[id="btnNavbarMenu`).should("exist").click();
// cy.wait(200);
// cy.get(`a[id="lnkNavbarMenuModal_Organisations"]`).first().click();
// cy.wait(2000);

// // href should end with /organisations
// cy.location("href").should("match", /\/organisations$/);

// //* click on the organisation on the organisations page
// cy.get(`a[id="lnkOrganisation_Test Organisation ${this.magicNumber} updated"]`).should("exist").click();
// cy.wait(6000);

// // href should end with /verify
// cy.location("href").should("match", /\/verify$/);

// // open approve dialog
// cy.get(`button[id="btnApprove"]`).should("exist").click();

// // enter comments into textarea
// cy.get(`textarea[id="txtVerifyComments"]`).should("exist").type("Approved by admin user");

// // approve the organisation by clicking on approve button
// cy.get(`button[id="btnApproveModal"]`).should("exist").click();

// // assert toast message
// cy.get(".Toastify__toast-container").should("be.visible");
// // assert console with the expected message
// cy.get("@consoleLog").should("be.calledWith", "Organisation approved");

// // href should end with /organisations
// cy.location("href").should("match", /\/organisations$/);
// });
// });
// });
describe(`Organisation Registration & Approval`, function () {
const magicNumber = Math.floor(Math.random() * 1000000);
this.magicNumber = magicNumber;

before(function () {
// set a variable on the context object
this.magicNumber = magicNumber;
});

describe(`${TESTUSER_EMAIL} (User role)`, () => {
beforeEach(() => {
cy.login(TESTUSER_EMAIL, TESTUSER_PASSWORD);
});

it("should register an organisation", function () {
// visit the registration page
cy.visit("http://localhost:3000/organisations/register", {
// stub the console log and error methods for console assertions
onBeforeLoad(win) {
cy.stub(win.console, "log").as("consoleLog");
cy.stub(win.console, "error").as("consoleError");
},
});
cy.wait(500);

//* step 1: fill out form and click next
cy.get("input[name=name]").type(`Test Organisation ${this.magicNumber}`);
cy.get("textarea[name=streetAddress]").type("123 Fake Street");
cy.get("input[name=province]").type("Bogusville");
cy.get("input[name=city]").type("Fake City");
cy.get("select[name=countryId]").select(COUNTRY_ID);
cy.get("input[name=postalCode]").type("1234");
cy.get("input[name=websiteURL]").type("http://www.google.com");
cy.fixture("org_logo.png").then((fileContent) => {
cy.get("input[type=file][name=logo]").attachFile({
fileContent: fileContent.toString(),
fileName: "org_logo.png",
mimeType: "image/png",
});
});
cy.get("input[name=tagline]").type("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
cy.get("textarea[name=biography]").type(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa."
);

cy.wait(500);
cy.get("button[type=submit]").should("exist").click();
cy.wait(500);

//* step 2: fill out form and click next
cy.get(`input[type=checkbox][name=providerTypes][value="${PROVIDER_TYPE_IMPACT_ID}"]`).check(); // check the "Impact" checkbox

cy.fixture("dummy.pdf").then((fileContent) => {
cy.get("input[type=file][name=registration]").attachFile({
fileContent: fileContent.toString(),
fileName: "dummy.pdf",
mimeType: "application/pdf",
});
});

cy.wait(500);
cy.get("button[type=submit]").should("exist").click();
cy.wait(500);

//* step 3: click submit
cy.get("button[type=submit]").should("exist").click();
cy.wait(14000);

// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Organisation registered");

// href should be /organisations/register/success
cy.location("href").should("eq", "http://localhost:3000/organisations/register/success");
});

it("should edit an organisation", function () {
// visit the home page
cy.visit("http://localhost:3000/", {
// stub the console log and error methods for console assertions
onBeforeLoad(win) {
cy.stub(win.console, "log").as("consoleLog");
cy.stub(win.console, "error").as("consoleError");
},
});
cy.wait(500);

//* click on the organisation on the user menu
cy.get(`button[id="btnUserMenu`).first().click();
cy.get(`a[id="userMenu_orgs_Test Organisation ${this.magicNumber}"]`).first().click();
cy.wait(4000);

// href should end with /edit
cy.location("href").should("match", /\/edit$/);

//* step 1: update form and click submit
cy.get("input[name=name]").type(" updated", { moveToEnd: true });
cy.get("textarea[name=streetAddress]").type(" updated", { moveToEnd: true });
cy.get("input[name=province]").type(" updated", { moveToEnd: true });
cy.get("input[name=city]").type(" updated", { moveToEnd: true });
cy.get("select[name=countryId]").select(COUNTRY_ID2);
cy.get("input[name=postalCode]").type("4321");
cy.get("input[name=websiteURL]").type(".2", { moveToEnd: true });
cy.get("input[name=tagline]").type(" updated", { moveToEnd: true });
cy.get("textarea[name=biography]").type(" updated", { moveToEnd: true });
cy.get("button.filepond--action-remove-item").click(); // remove existing image
cy.fixture("org_logo.png").then((fileContent) => {
cy.get("input[type=file][name=logo]").attachFile({
fileContent: fileContent.toString(),
fileName: "org_logo.png",
mimeType: "image/png",
});
});

cy.wait(500);
cy.get("button[type=submit]").should("exist").click();
cy.wait(500);

// assert toast message
cy.get(".Toastify__toast-container").should("be.visible");
// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");

//* step 2: update form and click submit
cy.get("a[id=lnkOrganisationRoles]").click(); // click on the roles tab
cy.wait(500);
cy.get(`input[type=checkbox][name=providerTypes][value="${PROVIDER_TYPE_EDUCATION_ID}"]`).check(); // check the "Education" checkbox
cy.fixture("dummy.pdf").then((fileContent) => {
cy.get("input[type=file][name=education]").attachFile({
fileContent: fileContent.toString(),
fileName: "dummy.pdf",
mimeType: "application/pdf",
});
});
cy.wait(500);
cy.get("button[type=submit]").should("exist").click();
cy.wait(500);

// assert toast message
cy.get(".Toastify__toast-container").should("be.visible");
// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");

//* step 3: click submit
cy.get("a[id=lnkOrganisationAdmins]").click(); // click on the admins tab
cy.wait(500);
cy.get("button[type=submit]").should("exist").click();
cy.wait(500);

// assert toast message
cy.get(".Toastify__toast-container").should("be.visible");
// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Your organisation has been updated");
});
});

describe(`${TESTADMINUSER_EMAIL} (Admin role)`, () => {
beforeEach(() => {
cy.login(TESTADMINUSER_EMAIL, TESTADMINUSER_PASSWORD);
});

it("should approve the organisation", function () {
// visit the admin page
cy.visit("http://localhost:3000/admin", {
// stub the console log and error methods for console assertions
onBeforeLoad(win) {
cy.stub(win.console, "log").as("consoleLog");
cy.stub(win.console, "error").as("consoleError");
},
});
cy.wait(500);

//* click on the admin link on the user menu
cy.get(`button[id="btnUserMenu`).should("exist").click();
cy.get(`a[id="userMenu_admin"]`).should("exist").click();
cy.wait(1000);

// href should end with /admin
cy.location("href").should("match", /\/admin$/);

//* click on the organisations link on the navigation menu
cy.get(`button[id="btnNavbarMenu`).should("exist").click();
cy.wait(200);
cy.get(`a[id="lnkNavbarMenuModal_Organisations"]`).first().click();
cy.wait(2000);

// href should end with /organisations
cy.location("href").should("match", /\/organisations$/);

//* click on the organisation on the organisations page
cy.get(`a[id="lnkOrganisation_Test Organisation ${this.magicNumber} updated"]`).should("exist").click();
cy.wait(6000);

// href should end with /verify
cy.location("href").should("match", /\/verify$/);

// open approve dialog
cy.get(`button[id="btnApprove"]`).should("exist").click();

// enter comments into textarea
cy.get(`textarea[id="txtVerifyComments"]`).should("exist").type("Approved by admin user");

// approve the organisation by clicking on approve button
cy.get(`button[id="btnApproveModal"]`).should("exist").click();

// assert toast message
cy.get(".Toastify__toast-container").should("be.visible");
// assert console with the expected message
cy.get("@consoleLog").should("be.calledWith", "Organisation approved");

// href should end with /organisations
cy.location("href").should("match", /\/organisations$/);
});
});
});
3 changes: 2 additions & 1 deletion cypress/support/commands/login.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ export const login = (username: string, password: string) => {
// });
// });
cy.get('button[id="btnSignIn"]').should("exist").click();
cy.wait(6000);
// Something is causing Next -> Keycloak load time to be long
cy.wait(12000);
cy.origin("http://keycloak:8080", { args: { username, password } }, ({ username, password }) => {
cy.reload(); // Reload the page to get cookies to load
// cy.getAllCookies().then((cookies) => {

0 comments on commit 23c4456

Please sign in to comment.