Skip to content

Commit

Permalink
[CPT-1489] Add data-testid to ValidationErrors in QueryBuilder (#4047)
Browse files Browse the repository at this point in the history
* [CPT-1489] Add data-testid to ValidationErrors  in QueryBuilder

* [CPT-1489] Remove testid property description

* [CPT-1489] Update test id property name in ValidationErrors

* [CPT-1489] Add Changeset

* [CPT-1489] Update ValidationErrors test

* [CPT-1489] Update yarn lock

* Return undefined if testId if not defined

---------

Co-authored-by: Rasit Ozcan <[email protected]>
  • Loading branch information
toptalwadiibasmi and rasitozcan authored Dec 7, 2023
1 parent 6d4a9c7 commit 43a6e5a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
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
1 change: 1 addition & 0 deletions packages/picasso-query-builder/src/types/query-builder.ts
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

0 comments on commit 43a6e5a

Please sign in to comment.