Skip to content

Commit

Permalink
Add Cypress and update some files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikikiv committed Nov 25, 2023
1 parent 051f9fc commit bb931e2
Show file tree
Hide file tree
Showing 12 changed files with 1,453 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Cypress Tests

on: push

jobs:
cypress-run:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v6
with:
build: npm run build
start: npm start
4 changes: 4 additions & 0 deletions components/AliasedEmails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default function InputCreator({ extension }: Props) {
}
>
<Input
type="email"
icon={<IconMail size="1rem" />}
radius={"xl"}
placeholder="email@example.com"
Expand Down Expand Up @@ -268,6 +269,7 @@ export default function InputCreator({ extension }: Props) {
</Box>
<Box px={rem(4)}>
<Select
type="alias"
size={extension ? "xs" : "sm"}
w={extension ? rem(110) : rem(160)}
clearable
Expand Down Expand Up @@ -303,6 +305,7 @@ export default function InputCreator({ extension }: Props) {
{selectedAlias && timestampEnabled && "-"}
<Box px={extension ? rem(1) : rem(6)}>
<Chip
data-cy={"timestampEnabled"}
variant="light"
checked={timestampEnabled}
size={extension ? "xs" : "sm"}
Expand Down Expand Up @@ -336,6 +339,7 @@ export default function InputCreator({ extension }: Props) {
{({ copied, copy }) => (
<>
<Button
id="copyEmail"
size={extension ? "xs" : "md"}
h={80}
maw={extension ? "330px" : "100%"}
Expand Down
1 change: 1 addition & 0 deletions components/global/CopyHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default function CopyHistory({ type, tooltip, scrollThreshold }: Props) {
position={"bottom"}
>
<Button
data-cy={historyItem.value}
leftIcon={<IconCopy />}
color={colorSelector(historyItem.type)}
variant={copied ? "filled" : "outline"}
Expand Down
18 changes: 18 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: "http://localhost:3000",
scrollBehavior: "center",
},

component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
22 changes: 22 additions & 0 deletions cypress/e2e/aliasedEmail.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe("template spec", () => {
const email = "idxqamv@gmail.com"
const aliasedEmail = "idxqamv+SugarFire@gmail.com"

it("passes", () => {
cy.visit("/")
cy.get('input[type="email"]').type(email)
cy.get('input[type="alias"]').type("Sugar Fire{enter}")
cy.get('[data-cy="timestampEnabled"]').uncheck({ force: true })
cy.get("#copyEmail").invoke("text").should("eq", aliasedEmail)
cy.get("#copyEmail").click()
cy.getAllLocalStorage().then((result) => {
expect(result["http://localhost:3000"]).to.contain.keys(
"email",
"aliases",
"copyHistory",
"selectedAlias"
)
})
cy.get(`[data-cy="${aliasedEmail}"]`).should("exist")
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- 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>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')
Binary file added extension.zip
Binary file not shown.
Loading

0 comments on commit bb931e2

Please sign in to comment.