Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Scenarios for handling of active users #199

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 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 All @@ -22,4 +23,9 @@ export default defineConfig({
return config;
},
},
env: {
base_url: "/ipa/modern_ui",
admin_login: "admin",
admin_password: "Secret123",
miskopo marked this conversation as resolved.
Show resolved Hide resolved
},
});
71 changes: 61 additions & 10 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,64 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
export {}; // needed for modification of global scope to work properly

declare global {
namespace Cypress {
interface Chainable {
createTestUser(username: string): Chainable<void>;
loginAsAnUser(username: string, password: string): Chainable<void>;
userCleanup(): Chainable<void>;
}
}
}

Cypress.Commands.add("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(Cypress.env("base_url"));
});

Cypress.Commands.add("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");
});
});

Cypress.Commands.add("createTestUser", (username: string) => {
cy.visit(Cypress.env("base_url") + "/active-users");
miskopo marked this conversation as resolved.
Show resolved Hide resolved
if (cy.get("tr[id=" + username + "]").should("not.exist")) {
cy.get("button").contains("Add").click();
cy.get("[role=dialog] label")
.contains("User login")
.parent()
.then(($label) => {
cy.get("[name=modal-form-" + $label.attr("for") + "]").type(username);
});
cy.get("[role=dialog] label")
.contains("First name")
.parent()
.then(($label) => {
cy.get("[name=modal-form-" + $label.attr("for") + "]").type("Artic");
});
cy.get("[role=dialog] label")
.contains("Last name")
.parent()
.then(($label) => {
cy.get("[name=modal-form-" + $label.attr("for") + "]").type("Asbestos");
});
cy.get("[role=dialog] button").contains("Add").click();
}
});
7 changes: 5 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
before(() => {
Cypress.session.clearCurrentSessionData().then();
cy.loginAsAnUser(Cypress.env("admin_login"), Cypress.env("admin_password"));
cy.userCleanup();
});
196 changes: 196 additions & 0 deletions tests/features/active_users_handling.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
Feature: User manipulation
Create, disable, delete, preserve and activate users


Background:
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 "<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 "<userLogin>" entry in the data table
Examples:
| userLogin | firstName | lastName | password |
| testuser1 | Arthur | Dent | ILoveKlingonPoetry42 |
| testuser2 | Banana | Bread | FishAndChips097 |
| testuser3 | Cypress | Gateway | TestingIsFun73 |

# Test if "Add and add another" behaves as expected
Scenario: Add one user after another
When I click on "Add" button
* I type in the field "User login" text "chainuser1"
* I type in the field "First name" text "Chain"
* I type in the field "Last name" text "User1"
* I type in the field "New Password" text "CorrectHorseBatteryStaple"
* I type in the field "Verify password" text "CorrectHorseBatteryStaple"
* in the modal dialog I click on "Add and add another" button

When I type in the field "User login" text "chainuser2"
* I type in the field "First name" text "Chain"
* I type in the field "Last name" text "User2"
* I type in the field "New Password" text "IncorrectHorseBatteryStaple"
* I type in the field "Verify password" text "IncorrectHorseBatteryStaple"
* in the modal dialog I click on "Add" button
Then I should see "chainuser1" entry in the data table
Then I should see "chainuser2" entry in the data table

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: Preserve a user
Given I should see "testuser3" entry in the data table
When I select entry "testuser3" in the data table
And I click on "Delete" button
Then I see "Remove Active Users" modal

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

Scenario: Restore preserved user
Given I am on "preserved-users" page
And I select entry "testuser3" in the data table
When I select entry "testuser3" in the data table
And I click on "Restore" button
Then I see "Restore preserved user" modal

When in the modal dialog I click on "Restore" button
Then I should not see "testuser3" entry in the data table

When I am on "active-users" page
Then I should see "testuser3" 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: Disable multiple users at once
Given I should see "testuser2" entry in the data table
Given I should see "testuser3" entry in the data table
When I select entry "testuser2" in the data table
When I select entry "testuser3" 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 I should see "testuser3" entry in the data table
Then entry "testuser2" should have attribute "Status" set to "Disabled"
Then entry "testuser3" should have attribute "Status" set to "Disabled"

Scenario: Re-enable multiple users at once
Given I should see "testuser2" entry in the data table
Given I should see "testuser3" entry in the data table
When I select entry "testuser2" in the data table
When I select entry "testuser3" 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 I should see "testuser3" entry in the data table
Then entry "testuser2" should have attribute "Status" set to "Enabled"
Then entry "testuser3" should have attribute "Status" set to "Enabled"

Scenario: Try to delete admin user
Given I should see "admin" entry in the data table
When I select entry "admin" 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 see a modal with text "admin cannot be deleted"
When in the modal dialog I click on "OK" button
And in the modal dialog I click on "Cancel" button
Then I should see "admin" entry in the data table

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

When in the modal dialog I check "Preserve" radio selector
And in the modal dialog I click on "Preserve" button
Then I see a modal with text "admin cannot be deleted or disabled"
When in the modal dialog I click on "OK" button
And in the modal dialog I click on "Cancel" button
Then I should see "admin" entry in the data table

Scenario: Try to disable admin user
Given I should see "admin" entry in the data table
When I select entry "admin" in the data table
And I click on "Disable" button
Then I see "Disable confirmation" modal

When in the modal dialog I click on "Disable" button
Then I see a modal with text "admin cannot be deleted or disabled"
When in the modal dialog I click on "OK" button
Then I should see "admin" entry in the data table

Scenario: Cancel creation of a user
When I click on "Add" button
* I type in the field "User login" text "cancelleduser"
* I type in the field "First name" text "Cancelled"
* I type in the field "Last name" text "User1"
* I type in the field "New Password" text "DoesntReallyMatter"
* I type in the field "Verify password" text "DoesntReallyMatter"
* in the modal dialog I click on "Cancel" button
Then I should not see "cancelleduser" entry in the data table

Scenario: Create a user without password
When I click on "Add" button
* I type in the field "User login" text "lookmanopass"
* I type in the field "First name" text "LookMa"
* I type in the field "Last name" text "NoPassword"
* in the modal dialog I click on "Add" button
Then I should see "lookmanopass" entry in the data table

Scenario: Rebuild auto membership
When I click on kebab menu and select "Rebuild auto membership"
Then I see "Confirmation" modal

When in the modal dialog I click on "OK" button
Then I should see "success" alert with text "Success alert:Automember rebuild membership task completed"
66 changes: 0 additions & 66 deletions tests/features/steps/common.js

This file was deleted.

Loading
Loading