-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1711 from AletheiaFact/setup-cypress-component-te…
…sting feat: Configuration branch to enable the component testing area
- Loading branch information
Showing
45 changed files
with
445 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
Binary file renamed
BIN
+43.3 KB
...est-npm-2.88.12-9c79415088-2c6fbf7f31.zip → ...quest-npm-3.0.7-c52826fe4d-af17367647.zip
Binary file not shown.
Binary file added
BIN
+10.3 KB
.yarn/cache/call-bind-apply-helpers-npm-1.0.1-cda777c96d-3c55343261.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+14.2 KB
...ature-npm-1.3.6-5b2eff4373-10be2af476.zip → ...ature-npm-1.4.0-086af1c8e9-f07f4cc048.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
<!-- Used by Next.js to inject CSS. --> | ||
<div id="__next_css__DO_NOT_USE__"></div> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
This file contains 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,39 @@ | ||
// *********************************************************** | ||
// This example support/component.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import "./commands"; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
import { mount } from "cypress/react18"; | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount; | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add("mount", mount); | ||
|
||
// Example use: | ||
// cy.mount(<MyComponent />) |
This file contains 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
This file contains 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,62 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import React from "react"; | ||
import { mount } from "cypress/react"; | ||
import BackButton from "../../src/components/BackButton"; | ||
|
||
describe("BackButton Component", () => { | ||
describe("should not render on home page or root path", () => { | ||
const mockRouter = (pathname: string) => { | ||
cy.stub(require("next/router"), "useRouter").returns({ | ||
pathname, | ||
route: pathname, | ||
query: {}, | ||
asPath: pathname, | ||
push: cy.stub(), | ||
replace: cy.stub(), | ||
prefetch: cy.stub().resolves(), | ||
}); | ||
}; | ||
|
||
it("should render and handle callback", () => { | ||
const callbackSpy = cy.spy().as("callbackSpy"); | ||
|
||
mount(<BackButton callback={callbackSpy} isVisible={true} />); | ||
|
||
cy.get('[data-cy="testBackButton"]').should("be.visible").click(); | ||
cy.get("@callbackSpy").should("have.been.calledOnce"); | ||
}); | ||
|
||
it("should call router.back when no callback is provided", () => { | ||
const routerBackSpy = cy.spy().as("routerBackSpy"); | ||
|
||
cy.stub(require("next/router"), "useRouter").returns({ | ||
pathname: "/another-page", | ||
back: routerBackSpy, | ||
}); | ||
|
||
mount(<BackButton isVisible={true} />); | ||
|
||
cy.get('[data-cy="testBackButton"]').click(); | ||
cy.get("@routerBackSpy").should("have.been.calledOnce"); | ||
}); | ||
|
||
it("should not render when isVisible is false", () => { | ||
mount(<BackButton isVisible={false} />); | ||
|
||
cy.get('[data-cy="testBackButton"]').should("not.exist"); | ||
}); | ||
|
||
it("should not render on the root path", () => { | ||
mockRouter("/"); | ||
mount(<BackButton isVisible={true} />); | ||
cy.get('[data-cy="testBackButton"]').should("not.exist"); | ||
}); | ||
|
||
it("should not render on the home page path", () => { | ||
mockRouter("/home-page"); | ||
mount(<BackButton isVisible={true} />); | ||
cy.get('[data-cy="testBackButton"]').should("not.exist"); | ||
}); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.