Skip to content

Commit

Permalink
Added test & examples
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikMatiasko committed Apr 27, 2024
1 parent 8703994 commit 2827604
Show file tree
Hide file tree
Showing 37 changed files with 614 additions and 88 deletions.
78 changes: 39 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,70 +41,70 @@
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/preset-typescript": "^7.24.1",
"@emotion/babel-plugin": "^11.11.0",
"@emotion/babel-preset-css-prop": "^11.11.0",
"@emotion/cache": "^11.11.0",
"@emotion/css": "^11.11.2",
"@emotion/eslint-plugin": "^11.11.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@floating-ui/react": "^0.26.2",
"@floating-ui/react-dom": "^2.0.4",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@floating-ui/react": "^0.26.12",
"@floating-ui/react-dom": "^2.0.8",
"@floating-ui/react-dom-interactions": "^0.13.3",
"@hookform/resolvers": "^3.3.4",
"@lezer/highlight": "^1.2.0",
"@mdx-js/react": "^2.3.0",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/context-zone": "^1.18.1",
"@opentelemetry/core": "^1.18.1",
"@opentelemetry/instrumentation": "^0.45.1",
"@opentelemetry/instrumentation-fetch": "^0.45.1",
"@opentelemetry/instrumentation-xml-http-request": "^0.45.1",
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@opentelemetry/sdk-trace-web": "^1.18.1",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/context-zone": "^1.24.0",
"@opentelemetry/core": "^1.24.0",
"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/instrumentation-fetch": "^0.51.0",
"@opentelemetry/instrumentation-xml-http-request": "^0.51.0",
"@opentelemetry/sdk-trace-base": "^1.24.0",
"@opentelemetry/sdk-trace-web": "^1.24.0",
"@types/convert-units": "^2.3.9",
"@types/dompurify": "^3.0.2",
"@types/lodash": "^4.14.202",
"@types/mustache": "^4.2.2",
"@types/dompurify": "^3.0.5",
"@types/lodash": "^4.17.0",
"@types/mustache": "^4.2.5",
"@types/node": "^18.16.17",
"@types/react": "^18.2.38",
"@types/react-color": "^3.0.10",
"@types/react-dom": "^18.2.17",
"@types/react-helmet": "^6.1.9",
"@types/react-table": "^7.7.18",
"@types/react-transition-group": "^4.4.9",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@uiw/codemirror-extensions-langs": "^4.21.21",
"@uiw/codemirror-themes": "^4.21.21",
"@uiw/react-codemirror": "^4.21.21",
"axios": "^1.6.2",
"@types/react": "^18.3.0",
"@types/react-color": "^3.0.12",
"@types/react-dom": "^18.3.0",
"@types/react-helmet": "^6.1.11",
"@types/react-table": "^7.7.20",
"@types/react-transition-group": "^4.4.10",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.21.0",
"@uiw/codemirror-extensions-langs": "^4.21.25",
"@uiw/codemirror-themes": "^4.21.25",
"@uiw/react-codemirror": "^4.21.25",
"axios": "^1.6.8",
"babel-jest": "^29.7.0",
"bootstrap": "^5.3.2",
"classnames": "^2.3.2",
"bootstrap": "^5.3.3",
"classnames": "^2.5.1",
"detect-browser": "^5.3.0",
"dompurify": "^3.0.5",
"framer-motion": "^10.16.5",
"dompurify": "^3.1.1",
"framer-motion": "^11.1.7",
"jest-sonar-reporter": "^2.0.0",
"jsoneditor": "^9.10.4",
"jsoneditor": "^9.10.5",
"lodash": "^4.17.21",
"mustache": "^4.2.0",
"oidc-react": "^3.2.2",
"pkijs": "^3.0.16",
"random-words": "^2.0.0",
"random-words": "^2.0.1",
"rc-scrollbars": "^1.1.6",
"react": "^18.2.0",
"react": "^18.3.0",
"react-app-polyfill": "^3.0.0",
"react-avatar": "^5.0.3",
"react-bootstrap": "^2.9.1",
"react-bootstrap": "^2.10.2",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
"react-dom": "^18.3.0",
"react-dropzone": "^14.2.3",
"react-helmet": "^6.1.0",
"react-hook-form": "^7.48.2",
"react-hook-form": "^7.51.3",
"react-hook-form-persist": "^3.0.0",
"react-intl": "^5.25.1",
"react-merge-refs": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ exports[`<ConfirmModal> renders without crashing 1`] = `
<div
class="emotion-1"
role="dialog"
style="opacity: 1; transform: none;"
style="opacity: 1; transform: translateY(0) translateZ(0);"
>
<div
class="emotion-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ exports[`<Modal> render correctly - snapshot 1`] = `
<div
class="emotion-1"
role="dialog"
style="opacity: 1; transform: none;"
style="opacity: 1; transform: translateY(0) translateZ(0);"
>
<div
class="emotion-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -270,9 +268,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -305,9 +301,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -340,9 +334,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -391,9 +383,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -442,9 +432,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -494,9 +482,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down Expand Up @@ -546,9 +532,7 @@ exports[`<SimpleStripTable> render correctly - snapshot 1`] = `
tabindex="1"
type="submit"
>
<div
style="transform: none;"
>
<div>
<svg
fill="none"
height="16"
Expand Down
2 changes: 2 additions & 0 deletions src/components/Organisms/CaList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './CaList'
export * from './CaList'
52 changes: 52 additions & 0 deletions src/components/Templates/FullPageWizard/FullPageWizard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import FullPageWizard from './FullPageWizard'

describe('FullPageWizard', () => {
const props = {
activeStep: 0,
steps: [
{ name: 'Step 1', description: 'Description 1' },
{ name: 'Step 2', description: 'Description 2' },
{ name: 'Step 3', description: 'Description 3' },
],
onStepChange: () => {},
title: 'Test Title',
}

it('renders without crashing', () => {
const { container, asFragment } = render(<FullPageWizard {...props} />)
expect(container.firstChild).toBeInTheDocument()
expect(asFragment()).toMatchSnapshot()
})

it('renders the correct number of steps', () => {
const { getAllByRole } = render(<FullPageWizard {...props} />)
const steps = getAllByRole('listitem')
expect(steps.length).toBe(props.steps.length)
})

it('calls onStepChange when a step is clicked', () => {
const mockOnStepChange = jest.fn()
const { getAllByRole } = render(<FullPageWizard {...props} activeStep={1} onStepChange={mockOnStepChange} visitedStep={0} />)
const steps = getAllByRole('link')
fireEvent.click(steps[0])
expect(mockOnStepChange).toHaveBeenCalledWith(0)
})

it('does not call onStepChange when a non-visited step is clicked', () => {
const mockOnStepChange = jest.fn()
const { getAllByRole } = render(<FullPageWizard {...props} onStepChange={mockOnStepChange} visitedStep={0} />)
const steps = getAllByRole('link')
fireEvent.click(steps[1])
expect(mockOnStepChange).not.toHaveBeenCalled()
})

it('calls onClose when close button is clicked', () => {
const mockOnClose = jest.fn()
const { getByRole } = render(<FullPageWizard {...props} onClose={mockOnClose} />)
const closeButton = getByRole('button')
fireEvent.click(closeButton)
expect(mockOnClose).toHaveBeenCalled()
})
})
15 changes: 10 additions & 5 deletions src/components/Templates/FullPageWizard/FullPageWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ const FullPageWizard: ComponentType<Props> = (props) => {
<li css={[activeStep >= key && styles.visited]} key={key}>
<div css={styles.icon}>
{activeStep > key ? (
<IconDone fill={theme.colorPalette.primary} />
<IconDone fill={theme?.colorPalette?.primary} />
) : (
<IconCircle fill={activeStep >= key ? theme.colorPalette.primary : theme.colorPalette.neutral300} />
<IconCircle fill={activeStep >= key ? theme?.colorPalette?.primary : theme?.colorPalette?.neutral300} />
)}
</div>
<a
css={[styles.link, activeStep >= key && styles.visited, visitedStep && visitedStep >= key && styles.activeLink]}
css={[
styles.link,
activeStep >= key && styles.visited,
visitedStep !== undefined && visitedStep >= key && styles.activeLink,
]}
href='#'
onClick={(e) => {
e.preventDefault()

if (visitedStep && visitedStep >= key) {
if (visitedStep !== undefined && visitedStep >= key) {
isFunction(onStepChange) && onStepChange(key)
}
}}
Expand All @@ -64,8 +68,9 @@ const FullPageWizard: ComponentType<Props> = (props) => {
e.preventDefault()
isFunction(onClose) && onClose()
}}
role='button'
>
<span>{i18n.close}</span>
<span>{i18n?.close}</span>
<IconCloseCircle {...convertSize(32)} />
</a>
<div css={styles.content}>{children}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export interface ComponentType<P> extends FC<P> {
export type Props = {
activeStep: number
children?: ReactNode
i18n: {
i18n?: {
close: string
}
onClose: () => void
onClose?: () => void
onStepChange: (step: number) => void
steps: { name: string; description?: string; link?: string }[]
title: string
Expand Down
Loading

0 comments on commit 2827604

Please sign in to comment.