-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
672 additions
and
188 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
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
157 changes: 157 additions & 0 deletions
157
...ntend/src/components/WorkspaceProgress/Wizard/__tests__/__snapshots__/index.spec.tsx.snap
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,157 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`WorkspaceProgressWizard component snapshot 1`] = ` | ||
<div | ||
className="progress pf-c-wizard" | ||
> | ||
<button | ||
aria-expanded={true} | ||
aria-label="Wizard Toggle" | ||
className="pf-c-wizard__toggle pf-m-expanded" | ||
onClick={[Function]} | ||
> | ||
<ol | ||
className="pf-c-wizard__toggle-list" | ||
> | ||
<li | ||
className="pf-c-wizard__toggle-list-item" | ||
> | ||
<span | ||
className="pf-c-wizard__toggle-num" | ||
/> | ||
</li> | ||
</ol> | ||
<span | ||
className="pf-c-wizard__toggle-icon" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
aria-labelledby={null} | ||
fill="currentColor" | ||
height="1em" | ||
role="img" | ||
style={ | ||
Object { | ||
"verticalAlign": "-0.125em", | ||
} | ||
} | ||
viewBox="0 0 320 512" | ||
width="1em" | ||
> | ||
<path | ||
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z" | ||
/> | ||
</svg> | ||
</span> | ||
</button> | ||
<div | ||
className="pf-c-wizard__outer-wrap" | ||
> | ||
<div | ||
className="pf-c-wizard__inner-wrap" | ||
> | ||
<nav | ||
aria-label="Workspace Progress Steps" | ||
className="pf-c-wizard__nav pf-m-expanded" | ||
> | ||
<ol | ||
className="pf-c-wizard__nav-list" | ||
> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current={false} | ||
aria-disabled={null} | ||
className="pf-c-wizard__nav-link" | ||
disabled={false} | ||
onClick={[Function]} | ||
> | ||
initialize | ||
</button> | ||
</li> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current="page" | ||
aria-disabled={null} | ||
className="pf-c-wizard__nav-link pf-m-current" | ||
disabled={false} | ||
onClick={[Function]} | ||
> | ||
limit-check | ||
</button> | ||
</li> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current={false} | ||
aria-disabled={null} | ||
className="pf-c-wizard__nav-link" | ||
disabled={false} | ||
onClick={[Function]} | ||
> | ||
create | ||
</button> | ||
<ol | ||
className="pf-c-wizard__nav-list" | ||
> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current={false} | ||
aria-disabled={true} | ||
className="pf-c-wizard__nav-link pf-m-disabled" | ||
disabled={true} | ||
onClick={[Function]} | ||
> | ||
fetch | ||
</button> | ||
</li> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current={false} | ||
aria-disabled={true} | ||
className="pf-c-wizard__nav-link pf-m-disabled" | ||
disabled={true} | ||
onClick={[Function]} | ||
> | ||
conflict-check | ||
</button> | ||
</li> | ||
<li | ||
className="pf-c-wizard__nav-item" | ||
> | ||
<button | ||
aria-current={false} | ||
aria-disabled={true} | ||
className="pf-c-wizard__nav-link pf-m-disabled" | ||
disabled={true} | ||
onClick={[Function]} | ||
> | ||
apply | ||
</button> | ||
</li> | ||
</ol> | ||
</li> | ||
</ol> | ||
</nav> | ||
<div | ||
aria-label={null} | ||
aria-labelledby={null} | ||
className="pf-c-wizard__main" | ||
> | ||
<div | ||
className="pf-c-wizard__main-body" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
142 changes: 142 additions & 0 deletions
142
packages/dashboard-frontend/src/components/WorkspaceProgress/Wizard/__tests__/index.spec.tsx
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,142 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import React from 'react'; | ||
import WorkspaceProgressWizard, { WorkspaceProgressWizardStep } from '..'; | ||
import { Step, StepId } from '../..'; | ||
import getComponentRenderer, { screen } from '../../../../services/__mocks__/getComponentRenderer'; | ||
|
||
const mockGoToNext = jest.fn(); | ||
|
||
const { createSnapshot, renderComponent } = getComponentRenderer(getComponent); | ||
|
||
describe('WorkspaceProgressWizard', () => { | ||
let steps: WorkspaceProgressWizardStep[]; | ||
let ref: React.RefObject<any>; | ||
|
||
beforeEach(() => { | ||
steps = [ | ||
{ | ||
id: Step.INITIALIZE, | ||
name: Step.INITIALIZE, | ||
component: <></>, | ||
}, | ||
{ | ||
id: Step.LIMIT_CHECK, | ||
name: Step.LIMIT_CHECK, | ||
component: <></>, | ||
}, | ||
{ | ||
id: Step.CREATE, | ||
name: Step.CREATE, | ||
component: <></>, | ||
steps: [ | ||
{ | ||
id: Step.FETCH, | ||
name: Step.FETCH, | ||
component: <></>, | ||
}, | ||
{ | ||
id: Step.CONFLICT_CHECK, | ||
name: Step.CONFLICT_CHECK, | ||
component: <></>, | ||
}, | ||
{ | ||
id: Step.APPLY, | ||
name: Step.APPLY, | ||
component: <></>, | ||
}, | ||
], | ||
}, | ||
]; | ||
ref = React.createRef(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('component snapshot', () => { | ||
const activeStepId: StepId = Step.LIMIT_CHECK; | ||
|
||
const snapshot = createSnapshot(activeStepId, steps, ref); | ||
expect(snapshot).toMatchSnapshot(); | ||
}); | ||
|
||
test('switching active step', () => { | ||
const activeStepId: StepId = Step.INITIALIZE; | ||
|
||
const { reRenderComponent } = renderComponent(activeStepId, steps, ref); | ||
|
||
const buttonInitialize = screen.getByRole('button', { name: Step.INITIALIZE }); | ||
const buttonLimitCheck = screen.getByRole('button', { name: Step.LIMIT_CHECK }); | ||
|
||
expect(buttonInitialize.className.split(' ')).toEqual(expect.arrayContaining(['pf-m-current'])); | ||
expect(buttonLimitCheck.className.split(' ')).not.toEqual( | ||
expect.arrayContaining(['pf-m-current']), | ||
); | ||
|
||
const nextActiveStepId = Step.LIMIT_CHECK; | ||
reRenderComponent(nextActiveStepId, steps, ref); | ||
|
||
const nextButtonInitialize = screen.getByRole('button', { name: Step.INITIALIZE }); | ||
const nextButtonLimitCheck = screen.getByRole('button', { name: Step.LIMIT_CHECK }); | ||
|
||
expect(nextButtonInitialize.className.split(' ')).not.toEqual( | ||
expect.arrayContaining(['pf-m-current']), | ||
); | ||
expect(nextButtonLimitCheck.className.split(' ')).toEqual( | ||
expect.arrayContaining(['pf-m-current']), | ||
); | ||
}); | ||
|
||
describe('trigger goToNext using reference', () => { | ||
test('on the very first step', () => { | ||
const activeStepId: StepId = Step.INITIALIZE; | ||
|
||
renderComponent(activeStepId, steps, ref); | ||
|
||
expect(mockGoToNext).not.toHaveBeenCalled(); | ||
|
||
ref.current?.goToNext(); | ||
|
||
expect(mockGoToNext).toHaveBeenCalledWith(Step.LIMIT_CHECK, Step.INITIALIZE); | ||
}); | ||
|
||
test('on the very last step', () => { | ||
const activeStepId: StepId = Step.APPLY; | ||
|
||
renderComponent(activeStepId, steps, ref); | ||
|
||
expect(mockGoToNext).not.toHaveBeenCalled(); | ||
|
||
ref.current?.goToNext(); | ||
|
||
expect(mockGoToNext).toHaveBeenCalledWith(undefined, Step.APPLY); | ||
}); | ||
}); | ||
}); | ||
|
||
function getComponent( | ||
activeStepId: StepId, | ||
steps: WorkspaceProgressWizardStep[], | ||
ref: React.RefObject<any>, | ||
): React.ReactElement { | ||
return ( | ||
<WorkspaceProgressWizard | ||
ref={ref} | ||
activeStepId={activeStepId} | ||
steps={steps} | ||
onNext={mockGoToNext} | ||
/> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/dashboard-frontend/src/components/WorkspaceProgress/Wizard/index.module.css
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,40 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
.progress { | ||
height: 700px; | ||
} | ||
|
||
.progress .pf-c-wizard__nav { | ||
width: 100%; | ||
border: none; | ||
box-shadow: none; | ||
} | ||
|
||
.progress .pf-c-wizard__nav-link { | ||
margin-left: 8px; | ||
pointer-events: none; | ||
} | ||
|
||
.progress .pf-c-wizard__nav-link:hover, | ||
.progress .pf-c-wizard__nav-link:focus { | ||
--pf-c-wizard__nav-link--Color: var(--pf-c-wizard__nav-link--Color); | ||
--pf-c-wizard__nav-link-toggle--Color: var(--pf-c-wizard__nav-link--Color); | ||
} | ||
|
||
.progress .pf-c-wizard__nav-link > svg { | ||
margin-right: 5px; | ||
} | ||
|
||
.progress .pf-c-wizard__toggle { | ||
display: none; | ||
} |
Oops, something went wrong.