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

[CPT-1489] Add data-testid to ValidationErrors in QueryBuilder #4047

Merged
merged 7 commits into from
Dec 7, 2023
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
12 changes: 12 additions & 0 deletions .changeset/purple-onions-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@toptal/picasso-query-builder': minor
---

### QueryBuilder

- update validationErrors to testIds properties

### ValidationErrors

- add validationErrorsTestId property as a test id for its container.
- property validationErrorsTestId is used to set test id for validation errors messages with their corresponding index.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ const QueryBuilder = ({
setSubmitButtonClicked(true)

if (!queryBuilderValid) {
showError(<ValidationErrors validationResult={validationErrors} />)
showError(
<ValidationErrors
validationErrorsTestId={testIds?.validationErrors}
validationResult={validationErrors}
/>
)

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ describe('ValidationErrors', () => {

expect(ListItemMock).toHaveBeenCalledTimes(2)
expect(ListItemMock).toHaveBeenCalledWith(
{
expect.objectContaining({
children: 'reason1',
},
}),
{}
)
expect(ListItemMock).toHaveBeenCalledWith(
{
expect.objectContaining({
children: 'reason2',
},
}),
{}
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import type { ValidationResult } from 'react-querybuilder'

const ValidationErrors = ({
validationResult,
validationErrorsTestId: testId,
}: {
validationResult: Record<string, ValidationResult | boolean>
validationErrorsTestId?: string
}) => {
const validationErrors = useMemo(
() =>
Expand All @@ -26,7 +28,7 @@ const ValidationErrors = ({
}

return (
<Container flex direction='column' gap='small'>
<Container data-testid={testId} flex direction='column' gap='small'>
<Typography>
Please fix validation errors before running the query
</Typography>
Expand All @@ -39,8 +41,13 @@ const ValidationErrors = ({
return (
<Fragment key={rule}>
{reasons?.map((reason, index) => (
// eslint-disable-next-line react/no-array-index-key
<List.Item key={index}>{reason.message ?? reason}</List.Item>
<List.Item
// eslint-disable-next-line react/no-array-index-key
key={index}
data-testid={testId && `${testId}-${index}`}
>
{reason.message ?? reason}
</List.Item>
))}
</Fragment>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ export type TestId = {
controls?: string
valueEditor?: string
fieldSelector?: string
validationErrors?: string
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15431,14 +15431,14 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz"
integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==

json5@1, json5@^1.0.1, json5@^2.1.1:
json5@1, json5@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593"
integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==
dependencies:
minimist "^1.2.0"

[email protected], json5@^2.1.0, json5@^2.1.2, json5@^2.2.0, json5@^2.2.2, json5@^2.2.3, json5@^2.x:
[email protected], json5@^2.1.0, json5@^2.1.1, json5@^2.1.2, json5@^2.2.0, json5@^2.2.2, json5@^2.2.3, json5@^2.x:
version "2.2.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
Expand Down
Loading