Skip to content

Commit

Permalink
WIP test code
Browse files Browse the repository at this point in the history
  • Loading branch information
miskopo committed Dec 4, 2023
1 parent d7a522f commit dcbe289
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 96 deletions.
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
e2e: {
specPattern: "**/*.feature",
baseUrl: "https://server.ipa.demo/",
testIsolation: false,

async setupNodeEvents(
on: Cypress.PluginEvents,
Expand Down
27 changes: 27 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,30 @@
// }
// }
// }

export const BASE_URL = "/ipa/modern_ui";

// @ts-ignore
export function loginAsAnUser(username: string, password: string) {
// temporary solution as the new UI doesn't have login page yet
cy.visit("/ipa/ui");
cy.get("[id=username1]").type(username);
cy.get("[id=password2").type(password);
cy.get("button[name=login]").click();
cy.wait(1000);
cy.visit(BASE_URL);
}

export function userCleanup() {
cy.get("tr[id=admin]", { timeout: 10000 }).should("be.visible");
cy.get('input[aria-label="Select all"]').check();
cy.get("tr[id=admin] input[type=checkbox]").uncheck();

cy.get("button")
.contains("Delete")
.then(($deleteButton) => {
if ($deleteButton.prop("disabled")) return;
$deleteButton.trigger("click");
cy.get("[role=dialog] button").contains("Delete").trigger("click");
});
}
9 changes: 9 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

// Import commands.js using ES2015 syntax:
import "./commands";
import { userCleanup, loginAsAnUser } from "./commands";

const admin_login: string = "admin";
const admin_password: string = "Secret123";

// Alternatively you can use CommonJS syntax:
// require('./commands')
before(() => {
Cypress.session.clearCurrentSessionData();
loginAsAnUser(admin_login, admin_password);
userCleanup();
});
66 changes: 0 additions & 66 deletions tests/features/steps/common.js

This file was deleted.

138 changes: 138 additions & 0 deletions tests/features/steps/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor";
import "../../../cypress/support/commands";
import { BASE_URL, loginAsAnUser } from "../../../cypress/support/commands";

// navigation
Given("I am on {string} page", (handle: string) => {
cy.url().then(($url) => {
if (!$url.includes(handle)) {
cy.visit(BASE_URL + "/" + handle);
}
});
});

// login
Given("I am logged in as {string}", (username: string) => {
cy.url().then(($url) => {
if (!$url.includes("modern_ui")) {
loginAsAnUser("admin", "Secret123");
}
});
cy.get(
"div.pf-c-masthead__content button span.pf-c-dropdown__toggle-text"
).then(($ele) => {
if ($ele.text() != username) {
loginAsAnUser("admin", "Secret123");
}
});
});

When(
"I log in as {string} with password {string}",
(username: string, password: string) => {
loginAsAnUser(username, password);
}
);

When("I logout", () => {});

// Side menu
When("I open the side menu", () => {
cy.get('[id="nav-toggle"]').then(($ele) => {
if ($ele.attr("aria-expanded") === "false") {
$ele.trigger("click");
}
});
});

When("I close the side menu", () => {
cy.get('[id="nav-toggle"]').then(($ele) => {
if ($ele.attr("aria-expanded") === "true") {
$ele.trigger("click");
}
});
});

// Buttons and tabs
When("I click on {string} tab", (tabText: string) => {
cy.get("nav a").contains(tabText).click();
});

When("I click on {string} button", function (buttonText: string) {
cy.get("button").contains(buttonText).click();
});

Then("button {string} should be enabled", function (buttonText: string) {
cy.get("button").contains(buttonText).should("be.enabled");
});

Then("button {string} should be disabled", function (buttonText: string) {
cy.get("button").contains(buttonText).should("be.disabled");
});

// Modals
When(
"in the modal dialog I click on {string} button",
function (buttonText: string) {
cy.get("[role=dialog] button").contains(buttonText).click();
}
);

When(
"in the modal dialog I check {string} radio selector",
(selectorText: string) => {
cy.get("[role=dialog] input[type=radio]+label")
.contains(selectorText)
.click();
}
);

Then("I see {string} modal", (modalHeading: string) => {
cy.get("[role=dialog] h1 span").contains(modalHeading);
});

// Fields
When(
"I type in the field {string} text {string}",
(fieldName: string, content: string) => {
cy.get("[role=dialog] label")
.contains(fieldName)
.parent()
.then(($label) => {
cy.get("[name=modal-form-" + $label.attr("for") + "]").type(content);
});
}
);

// Data tables
When("I select entry {string} in the data table", (name: string) => {
cy.get("tr[id=" + name + "] input[type=checkbox]").check();
});

When("I click on {string} entry in the data table", (name: string) => {
cy.get("tr[id=" + name + "] a")
.contains(name)
.trigger("click");
});

Then("I should see {string} entry in the data table", (name: string) => {
cy.get("tr[id=" + name + "]").should("be.visible");
});

Then("I should not see {string} entry in the data table", (name: string) => {
cy.get("tr[id=" + name + "]").should("not.exist");
});
Then(
"entry {string} should have attribute {string} set to {string}",
function (name: string, column: string, value: string) {
cy.get("tr[id=" + name + "] td[data-label=" + column + "]").contains(value);
}
);

// Notifications
Then(
"I should see {string} alert with text {string}",
(type: string, content: string) => {
cy.get("div.pf-c-alert").contains(content);
}
);
16 changes: 0 additions & 16 deletions tests/features/steps/test_user.js

This file was deleted.

1 change: 1 addition & 0 deletions tests/features/steps/test_user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor";
71 changes: 57 additions & 14 deletions tests/features/test_active_user.feature
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
Feature: User manipulation
Create, edit, delete, preserve and activate users


Background:
Given I am on login page
When I log in as "admin" with password "Secret123"

Scenario: Add a new user
Given I open the side menu
* I click on "Active users" tab
* I close the side menu
* there is only admin user active
Given I am logged in as "Administrator"
Given I am on "active-users" page

Scenario Outline: Add a new user
When I click on "Add" button
* I type in the field "User login" text "testuser1"
* I type in the field "First name" text "Arthur"
* I type in the field "Last name" text "Dent"
* I type in the field "New Password" text "ILoveKlingonPoetry42"
* I type in the field "Verify password" text "ILoveKlingonPoetry42"
* I type in the field "User login" text "<userLogin>"
* I type in the field "First name" text "<firstName>"
* I type in the field "Last name" text "<lastName>"
* I type in the field "New Password" text "<password>"
* I type in the field "Verify password" text "<password>"
* in the modal dialog I click on "Add" button
Then I should see "testuser1" entry in the data table
Then I should see "<userLogin>" entry in the data table
Examples:
| userLogin | firstName | lastName | password |
| testuser1 | Arthur | Dent | ILoveKlingonPoetry42 |
| testuser2 | Banana | Bread | FishAndChips097 |
| testuser3 | Cypress | Gateway | TestingIsFun73 |


Scenario: Delete a user
Given I should see "testuser1" entry in the data table
When I select entry "testuser1" in the data table
And I click on "Delete" button
Then I see "Remove Active Users" modal

When in the modal dialog I check "Delete" radio selector
And in the modal dialog I click on "Delete" button
Then I should not see "testuser1" entry in the data table

Scenario: Disable a user
Given I should see "testuser2" entry in the data table
When I select entry "testuser2" in the data table
Then button "Disable" should be enabled
Then button "Enable" should be disabled

When I click on "Disable" button
Then I see "Disable confirmation" modal

When in the modal dialog I click on "Disable" button
Then I should see "testuser2" entry in the data table
Then entry "testuser2" should have attribute "Status" set to "Disabled"

Scenario: Re-enable a user
Given I should see "testuser2" entry in the data table
When I select entry "testuser2" in the data table
Then button "Enable" should be enabled
Then button "Disable" should be disabled

When I click on "Enable" button
Then I see "Enable confirmation" modal

Then in the modal dialog I click on "Enable" button
Then I should see "testuser2" entry in the data table
Then entry "testuser2" should have attribute "Status" set to "Enabled"

Scenario: Open user details
Given I should see "testuser2" entry in the data table
When I click on "testuser2" entry in the data table

0 comments on commit dcbe289

Please sign in to comment.