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

Add unit tests with Cypress component testing #92

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# misc
.DS_Store
*.pem
.project
.settings/

# debug
npm-debug.log*
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ The easiest way to deploy your Next.js app is to use the [Vercel Platform](https
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

## E2E tests

1. Run npm install
2. Update cypress/config/cypress.config.dev.ts with credentials- When login functionality is implemented. Not needed now.
3. Run npm run test which will open cypress window -> choose E2E testing -> Choose browser to run the tests against -> choose test files to run. This will use dev config file.
4. Running test through cmd, npm run test:dev. This will use electron headless browser to run the tests.

## Component tests

1. Run npx cypress open which will open cypress window -> choose Component Testing -> Choose browser to run the tests against -> choose test files to run.
2. Running test through cmd, npx cypress run --component. This will run all specs.
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export default defineConfig({
// implement node event listeners here
},
},

component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
14 changes: 14 additions & 0 deletions cypress/support/component-index.html
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>
39 changes: 39 additions & 0 deletions cypress/support/component.ts
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 />)
8 changes: 8 additions & 0 deletions src/app/archived/pageArchiveHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ArchiveHome from './page'

describe('<ArchiveHome />', () => {
it('renders', () => {
cy.mount(<ArchiveHome />)
})
})
8 changes: 8 additions & 0 deletions src/app/direct/pageDirectHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import DirectHome from './page'

describe('<DirectHome />', () => {
it('renders', () => {
cy.mount(<DirectHome />)
})
})
8 changes: 8 additions & 0 deletions src/app/pageHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import Home from './page'

describe('<Home />', () => {
it('renders', () => {
cy.mount(<Home />)
})
})
8 changes: 8 additions & 0 deletions src/components/archived/ArchiveCard.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ArchiveCard from './ArchiveCard'

describe('<ArchiveCard />', () => {
it('renders', () => {
cy.mount(<ArchiveCard cardHeader={''} description={''} />)
})
})
8 changes: 8 additions & 0 deletions src/components/archived/ArchiveFilter.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ArchiveFilter from './ArchiveFilter'

describe('<ArchiveFilter />', () => {
it('renders', () => {
cy.mount(<ArchiveFilter />)
})
})
8 changes: 8 additions & 0 deletions src/components/archived/ArchiveHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import ArchiveHome from './ArchiveHome'

describe('<ArchiveHome />', () => {
it('renders', () => {
cy.mount(<ArchiveHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/c-cda/CCDAHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import CCDAHome from './CCDAHome'

describe('<CCDAHome />', () => {
it('renders', () => {
cy.mount(<CCDAHome />)
})
})
16 changes: 16 additions & 0 deletions src/components/c-cda/additional/scorecard/ScorecardResults.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import ScorecardResults from './ScorecardResults'

describe('<ScorecardResults />', () => {
it('renders', () => {
cy.mount(
<ScorecardResults
dialogState={false}
handleCloseDialog={function (): void {
throw new Error('Function not implemented.')
}}
isShowSampleDownloadButton={false}
/>
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import ErrorDisplayCard from './ErrorDisplay'

describe('<ErrorDisplayCard />', () => {
it('renders', () => {
cy.mount(
<ErrorDisplayCard
open={false}
handleClose={function (): void {
throw new Error('Function not implemented.')
}}
response={{
error: undefined,
errorStatus: undefined,
}}
/>
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import ValidatorLoadingCard from './ResultsLoading'

describe('<ValidatorLoadingCard />', () => {
it('renders', () => {
cy.mount(
<ValidatorLoadingCard
open={false}
handleClose={function (): void {
throw new Error('Function not implemented.')
}}
estimatedValidationTime={0}
fileName={''}
/>
)
})
})
8 changes: 8 additions & 0 deletions src/components/cqmt/CqmHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import CqmHome from './CqmHome'

describe('<CqmHome />', () => {
it('renders', () => {
cy.mount(<CqmHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/direct/DirectHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import DirectHome from './DirectHome'

describe('<DirectHome />', () => {
it('renders', () => {
cy.mount(<DirectHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/home/SiteHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import SiteHome from './SiteHome'

describe('<SiteHome />', () => {
it('renders', () => {
cy.mount(<SiteHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/home/SiteHomeRows.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import SiteHomeRows from './SiteHomeRows'

describe('<SiteHomeRows />', () => {
it('renders', () => {
cy.mount(<SiteHomeRows />)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import IndustryResourcesHome from './IndustryResourcesHome'

describe('<IndustryResourcesHome />', () => {
it('renders', () => {
cy.mount(<IndustryResourcesHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/public-health-reporting/PHRHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import PHRHome from './PHRHome'

describe('<PHRHome />', () => {
it('renders', () => {
cy.mount(<PHRHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/resources/DocsCard.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import DocsCard from './DocsCard'

describe('<DocsCard />', () => {
it('renders', () => {
cy.mount(<DocsCard header={''} content={undefined} />)
})
})
8 changes: 8 additions & 0 deletions src/components/resources/DocsHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import DocsHome from './DocsHome'

describe('<DocsHome />', () => {
it('renders', () => {
cy.mount(<DocsHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/resources/DocsSubMenu.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import DocsSubMenu from './DocsSubMenu'

describe('<DocsSubMenu />', () => {
it('renders', () => {
cy.mount(<DocsSubMenu />)
})
})
8 changes: 8 additions & 0 deletions src/components/resources/FAQHome.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import FAQHome from './FAQHome'

describe('<FAQHome />', () => {
it('renders', () => {
cy.mount(<FAQHome />)
})
})
8 changes: 8 additions & 0 deletions src/components/resources/WelcomeHeader.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import WelcomeHeader from './WelcomeHeader'

describe('<WelcomeHeader />', () => {
it('renders', () => {
cy.mount(<WelcomeHeader heading={''} subheading={''} description={undefined} />)
})
})
8 changes: 8 additions & 0 deletions src/components/shared/Ankle.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import Ankle from './Ankle'

describe('<Ankle />', () => {
it('renders', () => {
cy.mount(<Ankle />)
})
})
8 changes: 8 additions & 0 deletions src/components/shared/BannerBox.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import BannerBox from './BannerBox'

describe('<BannerBox />', () => {
it('renders', () => {
cy.mount(<BannerBox heading={''} description={undefined} />)
})
})
8 changes: 8 additions & 0 deletions src/components/shared/CardWithBorder.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import CardWithBorder from './CardWithBorder'

describe('<CardWithBorder />', () => {
it('renders', () => {
cy.mount(<CardWithBorder cardHeader={''} buttonTitle={''} buttonIcon={undefined} />)
})
})
18 changes: 18 additions & 0 deletions src/components/shared/CardWithImageCriteriaCard.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import CriteriaCard from './CardWithImage'

describe('<CriteriaCard />', () => {
it('renders', () => {
cy.mount(
<CriteriaCard
title={''}
cardImage={''}
cardHeader={''}
description={''}
pathname={''}
maxWidth={0}
imageWidth={''}
/>
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import CircularProgressWithLabelAndBackground from './CircularProgressWithLabelAndBackground'

describe('<CircularProgressWithLabelAndBackground />', () => {
it('renders', () => {
cy.mount(<CircularProgressWithLabelAndBackground progressValue={0} labelValue={''} labelAndProgressColor={''} />)
})
})
8 changes: 8 additions & 0 deletions src/components/shared/LinkButton.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import LinkButton from './LinkButton'

describe('<LinkButton />', () => {
it('renders', () => {
cy.mount(<LinkButton label={''} url={''} icon={undefined} />)
})
})
8 changes: 8 additions & 0 deletions src/components/shared/SectionHeader.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import SectionHeader from './SectionHeader'

describe('<SectionHeader />', () => {
it('renders', () => {
cy.mount(<SectionHeader header={''} subHeader={''} />)
})
})
2 changes: 1 addition & 1 deletion src/components/shared/dialog/DialogTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CustomDialogTitle: FC<DialogTitleProps> = ({ children, handleClose }) => (
<IconButton
aria-label="Close Dialog"
sx={{ position: 'absolute', right: 8, top: 8 }}
onClick={(e) => {
onClick={(e: { stopPropagation: () => void }) => {
e.stopPropagation()
handleClose()
}}
Expand Down
Loading