-
Notifications
You must be signed in to change notification settings - Fork 10
Added PanelSidebar cypress test #33
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
Merged
neotob
merged 4 commits into
neolution-ch:feature/hbl-layout-alpha
from
severinoAmmirati:feature/hbl-layout-alpha-sideabar-cypress
Sep 15, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
19fdd14
Added PanelSidebar cypress test and improved DateHandler test
severinoAmmirati 8414407
updated changelog
severinoAmmirati 65965c6
Merge branch 'feature/hbl-layout-alpha' into feature/hbl-layout-alpha…
severinoAmmirati 646d41e
Fix pr feedbacks
severinoAmmirati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
cypress/cypress/component/PanelSidebar/PanelSidebar.cy.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import React from "react"; | ||
| import {PanelSideBarLayoutProvider, PanelSideBarProvider, PanelSideBarLayout, PanelItem, PanelLinkRendererProps} from "react-pattern-ui"; | ||
| import { faBars, faCogs } from "@fortawesome/free-solid-svg-icons"; | ||
|
|
||
| type CustomPanelItem<TLocalPanelIds = ""> = { | ||
| id: "home" | "settings" | TLocalPanelIds; | ||
| }; | ||
|
|
||
| type TSideBarMenuItem<TLocalPanelIds = ""> = PanelItem<CustomPanelItem<TLocalPanelIds>>; | ||
|
|
||
| const PanelSidebar = (items: TSideBarMenuItem[]) => (<PanelSideBarLayoutProvider> | ||
| <PanelSideBarProvider | ||
| globalItems={items} | ||
| LinkRenderer={(elem: PanelLinkRendererProps<Record<string, unknown>>) => ( | ||
| <div id={elem.item.id} | ||
| onClick={() => { | ||
| const pageContent = document.getElementById("pageContent"); | ||
| if (pageContent) { | ||
| pageContent.innerText = elem.item.id; | ||
| } | ||
| }}> | ||
| <>{elem.item.title}</> | ||
| </div> | ||
| )}> | ||
| <PanelSideBarLayout> | ||
| <div id="pageContent">Cypress</div> | ||
| </PanelSideBarLayout> | ||
| </PanelSideBarProvider> | ||
| </PanelSideBarLayoutProvider>) | ||
|
|
||
| const getSidebarItems = (active?: boolean, disabled?: boolean): TSideBarMenuItem[] => [ | ||
| { | ||
| id: "home", | ||
| title: "Home", | ||
| icon: faBars, | ||
| disabled, | ||
| items: [ | ||
| { | ||
| title: "Home", | ||
| id: "home", | ||
| active, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "settings", | ||
| title: "Settings", | ||
| icon: faCogs, | ||
| disabled, | ||
| items: [ | ||
| { | ||
| title: "Settings", | ||
| id: "settings", | ||
| }, | ||
| { | ||
| title: "Dropdown", | ||
| id: "dropdownTest", | ||
| children: [ | ||
| { | ||
| title: "Dropdown test 1", | ||
| id: "dropdown-test1", | ||
| }, | ||
| { | ||
| title: "Dropdown test 2", | ||
| id: "dropdown-test2", | ||
| active, | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| describe("PanelSidebar.cy.tsx", () => { | ||
|
|
||
| it("icon and titles rendered correctly", () => { | ||
| const sidebarItems = getSidebarItems(); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check if icon are rendered | ||
| cy.get('[data-icon="bars"]').should("be.visible"); | ||
| cy.get('[data-icon="gears"]').should("be.visible"); | ||
|
|
||
| // Check if is titles are rendered | ||
| cy.get("#home").invoke("text").should("equal", "Home"); | ||
| cy.get("button[title=Settings]").click(); | ||
| cy.get("#settings").invoke("text").should("equal", "Settings"); | ||
| }); | ||
|
|
||
| it("flat menu entry", () => { | ||
| const sidebarItems = getSidebarItems(); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check page content changes | ||
| cy.get("#home").click(); | ||
| cy.get("#pageContent").invoke("text").should("equal", "home"); | ||
| cy.get("button[title=Settings]").click(); | ||
| cy.get("#settings").click(); | ||
| cy.get("#pageContent").invoke("text").should("equal", "settings"); | ||
| }); | ||
|
|
||
| it("nested menu entries", () => { | ||
| const sidebarItems = getSidebarItems(); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check page content changes | ||
| cy.get("button[title=Settings]").click(); | ||
| cy.get("#settings").click(); | ||
| cy.get(".dropdown-toggle").click(); | ||
| cy.get("#dropdown-test1").click(); | ||
| cy.get("#pageContent").invoke("text").should("equal", "dropdown-test1"); | ||
| cy.get("#dropdown-test2").click(); | ||
| cy.get("#pageContent").invoke("text").should("equal", "dropdown-test2"); | ||
| }); | ||
|
|
||
| it("disabled entries", () => { | ||
| const sidebarItems = getSidebarItems(false, true); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check are disabled and page content not doesn't change | ||
| cy.get("button[title=Home]").should("have.attr", "disabled"); | ||
| cy.get("button[title=Home]").click({ force: true }); | ||
| cy.get("#pageContent").invoke("text").should("equal", "Cypress"); | ||
| cy.get("button[title=Settings]").should("have.attr", "disabled"); | ||
| cy.get("button[title=Settings]").click({ force: true }) | ||
| cy.get("#pageContent").invoke("text").should("equal", "Cypress"); | ||
| }); | ||
|
|
||
| it("toggle sidebar", () => { | ||
| const sidebarItems = getSidebarItems(); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check toggle sidebar | ||
| cy.get('[data-icon="angle-left"]').should("be.visible"); | ||
| cy.get("#side-nav-toggle").click(); | ||
| cy.get('[data-icon="angle-right"]').should("be.visible"); | ||
| cy.get(".toggled").should("exist"); | ||
| cy.get(".side-nav__items").should("not.be.visible") | ||
| }); | ||
|
|
||
| it("selected flat entry", () => { | ||
| const sidebarItems = getSidebarItems(true); | ||
| cy.mount(PanelSidebar(sidebarItems)); | ||
|
|
||
| // Check active entries | ||
| cy.get("#home").parent("li").should("have.class", "active"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.