Skip to content

Commit

Permalink
Username search cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Oct 19, 2023
1 parent 8011653 commit 8520673
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cypress/e2e/users_spec/user_homepage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference types="cypress" />

import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";
import { UserPage } from "../../pageobject/Users/usersearch";

describe("Asset Tab", () => {
const userPage = new UserPage();
const usernameToTest = "devdoctor";
const currentuser = "devdistrictadmin";
const loginPage = new LoginPage();
before(() => {
loginPage.loginAsDisctrictAdmin();
cy.saveLocalStorage();
});

beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/users");
});

it("Search by username", () => {
userPage.checkSearchInputVisibility();
userPage.typeInSearchInput(usernameToTest);
userPage.checkUrlForUsername(usernameToTest);
userPage.checkUsernameText(usernameToTest);
userPage.checkUsernameBadgeVisibility(true);
userPage.clearSearchInput();
userPage.checkUsernameBadgeVisibility(false);
userPage.typeInSearchInput(usernameToTest);
userPage.checkUsernameText(usernameToTest);
userPage.clickRemoveIcon();
userPage.checkUsernameBadgeVisibility(false);
userPage.checkUsernameText(currentuser);
});
afterEach(() => {
cy.saveLocalStorage();
});
});
37 changes: 37 additions & 0 deletions cypress/pageobject/Users/UserSearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// UserPage.ts
export class UserPage {
// Element selectors
searchByUsernameInput = "#search-by-username";
usernameText = "#username";
usernameBadge = "[data-testid='Username']";
removeIcon = "#removeicon";

checkSearchInputVisibility() {
cy.get(this.searchByUsernameInput).should("be.visible");
}

typeInSearchInput(text: string) {
cy.get(this.searchByUsernameInput).click().type(text);
}

clearSearchInput() {
cy.get(this.searchByUsernameInput).click().clear();
}

checkUrlForUsername(username: string) {
cy.url().should("include", `username=${username}`);
}

checkUsernameText(username: string) {
cy.get(this.usernameText).should("have.text", username);
}

checkUsernameBadgeVisibility(shouldBeVisible: boolean) {
const assertion = shouldBeVisible ? "be.visible" : "not.be.visible";
cy.get(this.usernameBadge).should(assertion);
}

clickRemoveIcon() {
cy.get(this.removeIcon).click();
}
}
1 change: 1 addition & 0 deletions src/CAREUI/display/FilterBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const FilterBadge = ({ name, value, onRemove }: FilterBadgeProps) => {
>
{`${name}: ${value}`}
<i
id="removeicon"
className="fas fa-times ml-2 cursor-pointer rounded-full px-1 py-0.5 hover:bg-gray-500"
onClick={onRemove}
></i>
Expand Down
1 change: 1 addition & 0 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export default function ManageUsers() {
<div className="col-span-2 my-2 flex flex-col justify-between space-y-3 lg:flex-row lg:space-x-4 lg:space-y-0 lg:px-3">
<div className="w-full">
<SearchInput
id="search-by-username"
name="username"
onChange={(e) => updateQuery({ [e.name]: e.value })}
value={qParams.username}
Expand Down

0 comments on commit 8520673

Please sign in to comment.