-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: required star visibility when using modify prop (#1489)
**Issue number:** https://splunk.atlassian.net/browse/ADDON-77024 ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [x] Bug Fix * [ ] Refactoring (no functional or API changes) * [ ] Documentation Update * [ ] Maintenance (dependency updates, CI, etc.) ## Summary Correctly reflects component required property after modifications on value change are applied. ### Changes Fixes error that verified if required start should be displayed. ### User experience Users see required star correct next to elements that are required currently. ## Checklist If an item doesn't apply to your changes, leave it unchecked. * [x] I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [x] Tests have been added/modified to cover the changes [(testing doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test) * [ ] Changes are documented * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests) --------- Co-authored-by: srv-rr-github-token <[email protected]>
- Loading branch information
1 parent
10bb448
commit e1fe2b0
Showing
5 changed files
with
180 additions
and
6 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
3 changes: 3 additions & 0 deletions
3
...ontrolWrapper/stories/__images__/ControlWrapper-with-modifications-chromium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...stories/__images__/ControlWrapper-with-modifications-make-required-chromium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions
129
ui/src/components/ControlWrapper/test/ControlWrapper.test.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,129 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ControlWrapper, { ControlWrapperProps } from '../ControlWrapper'; | ||
|
||
const renderControlWrapper = (props: Partial<ControlWrapperProps>) => { | ||
render( | ||
<ControlWrapper | ||
mode="create" | ||
utilityFuncts={{ | ||
utilCustomFunctions: { | ||
setState: () => {}, | ||
setErrorFieldMsg: () => {}, | ||
clearAllErrorMsg: () => {}, | ||
setErrorMsg: () => {}, | ||
}, | ||
handleChange: () => {}, | ||
addCustomValidator: () => {}, | ||
}} | ||
value="" | ||
display | ||
error={false} | ||
disabled={false} | ||
serviceName="testServiceName" | ||
dependencyValues={undefined} | ||
entity={{ | ||
field: 'url', | ||
label: 'URL', | ||
type: 'text', | ||
help: 'Enter the URL, for example', | ||
required: true, | ||
validators: [ | ||
{ | ||
errorMsg: | ||
"Invalid URL provided. URL should start with 'https' as only secure URLs are supported. Provide URL in this format", | ||
type: 'regex', | ||
pattern: '^(https://)[^/]+/?$', | ||
}, | ||
], | ||
encrypted: false, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
it('check if required star displayed correctly', () => { | ||
renderControlWrapper({}); | ||
const requiredStar = screen.queryByText('*'); | ||
expect(requiredStar).toBeInTheDocument(); | ||
}); | ||
|
||
it('check if required star not displayed', () => { | ||
renderControlWrapper({ | ||
entity: { | ||
field: 'url', | ||
label: 'URL', | ||
type: 'text', | ||
required: false, | ||
}, | ||
}); | ||
const requiredStar = screen.queryByText('*'); | ||
expect(requiredStar).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('check if required star displayed correctly from modifiedEntitiesData', () => { | ||
renderControlWrapper({ | ||
entity: { | ||
field: 'url', | ||
label: 'URL', | ||
type: 'text', | ||
required: false, | ||
}, | ||
modifiedEntitiesData: { required: true }, | ||
}); | ||
const requiredStar = screen.queryByText('*'); | ||
expect(requiredStar).toBeInTheDocument(); | ||
}); | ||
|
||
it('check if required star not displayed due to modifiedEntitiesData', () => { | ||
renderControlWrapper({ | ||
entity: { | ||
field: 'url', | ||
label: 'URL', | ||
type: 'text', | ||
required: true, | ||
}, | ||
modifiedEntitiesData: { required: false }, | ||
}); | ||
|
||
const requiredStar = screen.queryByText('*'); | ||
expect(requiredStar).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('check if label and help updated due to modifiedEntitiesData', () => { | ||
const modifications = { required: false, label: 'Modified URL', help: 'Modified help' }; | ||
renderControlWrapper({ | ||
entity: { | ||
field: 'url', | ||
label: 'URL', | ||
help: 'Enter the URL, for example', | ||
type: 'text', | ||
required: true, | ||
}, | ||
modifiedEntitiesData: modifications, | ||
}); | ||
|
||
const label = screen.getByTestId('label'); // label replaced | ||
expect(label).toHaveTextContent(modifications.label); | ||
|
||
const help = screen.getByTestId('help'); // help replaced | ||
expect(help).toHaveTextContent(modifications.help); | ||
}); | ||
|
||
it('check if help added due to modifiedEntitiesData', () => { | ||
const modifications = { help: 'Modified help' }; | ||
|
||
renderControlWrapper({ | ||
entity: { | ||
field: 'url', | ||
label: 'URL', | ||
type: 'text', | ||
required: true, | ||
}, | ||
modifiedEntitiesData: modifications, | ||
}); | ||
|
||
const help = screen.getByTestId('help'); | ||
expect(help).toHaveTextContent(modifications.help); | ||
}); |