Skip to content

Commit f37dc34

Browse files
committed
fix tests
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
1 parent e2d44cf commit f37dc34

9 files changed

Lines changed: 45 additions & 30 deletions

File tree

frontend/packages/react-form-wizard/src/Wizard.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ function WizardInternal({ children, onSubmit, onCancel, submitButtonText, submit
192192
</DescriptionList>
193193
</Step>
194194
</WizardStep>
195+
<WizardStep name="hidden-steps" id="hidden-steps-step" isHidden>
196+
<RenderHiddenSteps stepComponents={stepComponents} />
197+
</WizardStep>
195198
</PFWizard>
196199
</Fragment>
197200
)
@@ -346,6 +349,15 @@ function MyFooter(props: WizardFooterProps) {
346349
)
347350
}
348351

352+
function RenderHiddenSteps(props: { stepComponents: ReactElement[] }) {
353+
const { activeStep } = useWizardContext()
354+
return (
355+
<DisplayModeContext.Provider value={DisplayMode.StepsHidden}>
356+
{props.stepComponents.filter((component) => component.props.id !== activeStep.id)}
357+
</DisplayModeContext.Provider>
358+
)
359+
}
360+
349361
function WizardDrawer(props: { yamlEditor?: () => ReactNode }) {
350362
const [yamlEditor] = useState(props.yamlEditor ?? undefined)
351363
return (

frontend/packages/react-form-wizard/src/inputs/InputSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const SelectListOptions = ({
167167
<SelectOption
168168
id={isSimpleOption ? option : option.id || `option-${index}`}
169169
key={isSimpleOption ? option : option.id || `option-${index}`}
170-
value={!isSimpleOption ? option.value : option}
170+
value={!isSimpleOption ? index : option}
171171
description={!isSimpleOption ? option.description : undefined}
172172
isDisabled={displayText === NoResults || (!isSimpleOption && option.disabled)}
173173
onClick={isCreateOption ? () => onCreate?.(!isSimpleOption ? option.value : option) : undefined}

frontend/packages/react-form-wizard/src/inputs/WizSelect.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,13 @@ function WizSelectBase<T = any>(props: SelectProps<T>) {
126126

127127
const onSelect = useCallback(
128128
(selectOptionObject: string) => {
129-
switch (props.variant) {
130-
case 'single':
131-
const selectedOption = filteredOptions.find((option) => option.value === selectOptionObject)
132-
if (selectedOption) {
133-
setValue(selectedOption.value)
134-
} else {
135-
setValue(selectOptionObject)
136-
}
137-
setOpen(false)
138-
break
129+
if (Number.isInteger(Number(selectOptionObject))) {
130+
const selectOption = selectOptions?.[Number(selectOptionObject)]
131+
setValue(selectOption?.value ?? '')
132+
} else {
133+
setValue(selectOptionObject)
139134
}
135+
setOpen(false)
140136
},
141137
[isCreatable, props.variant, setValue]
142138
)
@@ -185,6 +181,7 @@ function WizSelectBase<T = any>(props: SelectProps<T>) {
185181
options={filteredOptions}
186182
isCreatable={isCreatable}
187183
onCreate={props.onCreate}
184+
footer={props.footer}
188185
/>
189186
</PfSelect>
190187
</InputGroupItem>

frontend/src/routes/Applications/CreateApplication/CreateApplicationArgoPullModel.test.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ import {
2323
nockIgnoreOperatorCheck,
2424
nockList,
2525
} from '../../../lib/nock-util'
26-
import { clickByText, typeByPlaceholderText, typeByTestId, waitForNocks, waitForText } from '../../../lib/test-util'
26+
import {
27+
clickByPlaceholderText,
28+
clickByText,
29+
typeByPlaceholderText,
30+
typeByTestId,
31+
waitForNocks,
32+
waitForText,
33+
} from '../../../lib/test-util'
2734
import { NavigationPath } from '../../../NavigationPath'
2835
import {
2936
ApplicationSet,
@@ -404,19 +411,19 @@ describe('Create Argo Application Set', () => {
404411

405412
// General
406413
await typeByTestId('name', argoAppSetGit!.metadata!.name!)
407-
await clickByText('Select the Argo server')
414+
await clickByPlaceholderText('Select the Argo server')
408415
await clickByText(gitOpsCluster!.spec!.argoServer!.argoNamespace)
409416
await clickByText('Next')
410417

411418
// Template
412419
await clickByText('Git')
413-
await clickByText('Enter or select a Git URL')
420+
await clickByPlaceholderText('Enter or select a Git URL')
414421

415422
const appBranchNocks = [nockArgoGitBranches(channelGit.spec.pathname, { branchList: [{ name: 'branch-01' }] })]
416423
await clickByText(channelGit.spec.pathname)
417424
await waitForNocks(appBranchNocks)
418425

419-
await clickByText('Enter or select a tracking revision')
426+
await clickByPlaceholderText('Enter or select a tracking revision')
420427
// await clickByText('Enter or select a tracking revision') // Hack to handle broken PatternFly dropdown not initially populating
421428
// await clickByText('Enter or select a tracking revision')
422429
const pathNocks = [

frontend/src/routes/Governance/policies/CreatePolicyAutomation.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ describe('Create Policy Automation Wizard', () => {
6565
await waitForText('Create policy automation', true)
6666

6767
// select ansible credential
68-
screen.getByRole('button', { name: /options menu/i }).click()
68+
screen.getByPlaceholderText('Select the Ansible credential').click()
6969
await clickByText(mockSecret.metadata.name!)
7070
await new Promise((resolve) => setTimeout(resolve, 2000))
7171

7272
// select ansible job
73-
screen.getByText('Select the ansible job').click()
73+
screen.getByPlaceholderText('Select the ansible job').click()
7474
screen.getByRole('option', { name: 'test-job-pre-install' }).click()
75-
screen.getByText('Once').click()
75+
screen.getByPlaceholderText(/select the schedule/i).click()
7676
screen.getByRole('option', { name: 'Disabled' }).click()
7777
screen
7878
.getByRole('checkbox', {
7979
name: /manual run: set this automation to run once\. after the automation runs, it is set to disabled\./i,
8080
})
8181
.click()
82-
screen.getByText('Disabled').click()
82+
screen.getByPlaceholderText(/select the schedule/i).click()
8383
screen.getByRole('option', { name: 'Once' }).click()
8484
screen.getByRole('button', { name: 'Next' }).click()
8585

frontend/src/routes/Governance/policies/EditPolicyAutomation.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ describe('Edit Policy Automation', () => {
5555
await new Promise((resolve) => setTimeout(resolve, 1000))
5656

5757
expect(screen.getByRole('heading', { name: 'Edit policy automation' })).toBeInTheDocument()
58-
expect(screen.getByText('ansible-test-secret')).toBeInTheDocument()
59-
expect(screen.getByText('test-job-pre-install')).toBeInTheDocument()
58+
expect(screen.getByPlaceholderText(/select the ansible credential/i)).toHaveValue('ansible-test-secret')
59+
expect(screen.getByPlaceholderText(/select the ansible job/i)).toHaveValue('test-job-pre-install')
6060

6161
// modify ansible job and schedule
62-
screen.getByText('test-job-pre-install').click()
62+
screen.getByPlaceholderText(/select the ansible job/i).click()
6363
screen.getByRole('option', { name: 'test-job-post-install' }).click()
64-
screen.getByText('Once').click()
64+
screen.getByPlaceholderText(/select the schedule/i).click()
6565
screen.getByRole('option', { name: 'Disabled' }).click()
6666
screen.getByRole('button', { name: 'Next' }).click()
6767

frontend/src/routes/Governance/policy-sets/CreatePolicySet.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ describe('Create Policy Page', () => {
4242

4343
// step 1 -- name and namespace
4444
userEvent.type(screen.getByRole('textbox', { name: /name/i }), mockPolicySets[1].metadata.name)
45-
screen.getByText('Select the namespace').click()
46-
userEvent.type(screen.getByRole('searchbox'), 'test')
45+
userEvent.type(screen.getByPlaceholderText('Select the namespace'), 'test')
4746
screen.getByRole('option', { name: 'test' }).click()
4847
screen.getByRole('button', { name: 'Next' }).click()
4948

@@ -56,10 +55,10 @@ describe('Create Policy Page', () => {
5655
await waitForText('How do you want to select clusters?')
5756
screen.getByRole('button', { name: 'New placement' }).click()
5857
screen.getByRole('button', { name: /action/i }).click()
59-
screen.getByText(/select the label/i).click()
58+
screen.getByPlaceholderText(/select the label/i).click()
6059
screen.getByRole('option', { name: /cloud/i }).click()
61-
screen.getByText(/select the values/i).click()
62-
screen.getByRole('checkbox', { name: /amazon/i }).click()
60+
screen.getByPlaceholderText(/select the values/i).click()
61+
screen.getByRole('option', { name: /amazon/i }).click()
6362
screen.getByRole('button', { name: 'Next' }).click()
6463

6564
// step 4 -- Review

frontend/src/wizards/Argo/ArgoWizard.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('ArgoWizard tests', () => {
126126
test('CreateArgoResources', async () => {
127127
nockIgnoreApiPaths()
128128
render(<TestArgoWizard />)
129-
userEvent.click(screen.getByText(/select the argo server/i))
129+
userEvent.click(screen.getByPlaceholderText(/select the argo server/i))
130130
userEvent.click(screen.getByRole('button', { name: /add argo server/i }))
131131

132132
//fill the form

frontend/src/wizards/Governance/PolicySet/PolicySetWizard.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('PolicySetWizard wizard', () => {
3737

3838
const nameTextbox = screen.getByRole('textbox', { name: /name/i })
3939
userEvent.type(nameTextbox, 'test-policy')
40-
screen.getByText(/select the namespace/i).click()
40+
screen.getByPlaceholderText(/select the namespace/i).click()
4141
screen.getByRole('option', { name: /argo-server-1/i }).click()
4242

4343
screen.getByRole('button', { name: /placement/i }).click()

0 commit comments

Comments
 (0)