-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: addded helptext for hidden property (#14292)
- Loading branch information
1 parent
1bd192d
commit 9bfa321
Showing
5 changed files
with
167 additions
and
9 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
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
85 changes: 85 additions & 0 deletions
85
frontend/packages/ux-editor/src/components/config/editModal/EditBooleanValue.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,85 @@ | ||
import React from 'react'; | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { EditBooleanValue } from './EditBooleanValue'; | ||
import { renderWithProviders } from '../../../testing/mocks'; | ||
|
||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
import { ComponentType } from 'app-shared/types/ComponentType'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
const renderEditBooleanValue = ({ | ||
handleComponentChange = jest.fn(), | ||
value = false, | ||
propertyKey = 'required', | ||
componentOverrides = {}, | ||
helpText = '', | ||
} = {}) => | ||
renderWithProviders( | ||
<EditBooleanValue | ||
handleComponentChange={handleComponentChange} | ||
propertyKey={propertyKey} | ||
component={{ | ||
id: 'c24d0812-0c34-4582-8f31-ff4ce9795e96', | ||
type: ComponentType.Input, | ||
textResourceBindings: { | ||
title: 'ServiceName', | ||
}, | ||
required: value, | ||
itemType: 'COMPONENT', | ||
dataModelBindings: { simpleBinding: 'some-path' }, | ||
...componentOverrides, | ||
}} | ||
/>, | ||
); | ||
|
||
describe('EditBooleanValue', () => { | ||
it('should render component as switch', () => { | ||
renderEditBooleanValue(); | ||
|
||
expect( | ||
screen.getByRole('checkbox', { name: textMock('ux_editor.component_properties.required') }), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onChange handler with the correct arguments', async () => { | ||
const handleComponentChange = jest.fn(); | ||
renderEditBooleanValue({ handleComponentChange }); | ||
const inputElement = screen.getByLabelText(textMock('ux_editor.component_properties.required')); | ||
|
||
user.click(inputElement); | ||
|
||
await waitFor(() => { | ||
expect(handleComponentChange).toHaveBeenCalledWith({ | ||
id: 'c24d0812-0c34-4582-8f31-ff4ce9795e96', | ||
type: ComponentType.Input, | ||
textResourceBindings: { | ||
title: 'ServiceName', | ||
}, | ||
required: true, | ||
itemType: 'COMPONENT', | ||
dataModelBindings: { simpleBinding: 'some-path' }, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should display correct help text when value is an expression (array)', () => { | ||
renderEditBooleanValue({ | ||
componentOverrides: { | ||
required: [], | ||
}, | ||
}); | ||
expect( | ||
screen.getByText(textMock('ux_editor.component_properties.config_is_expression_message')), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display custom help text', () => { | ||
const customHelpText = textMock('ux_editor.component_properties_help_text.required'); | ||
renderEditBooleanValue({ | ||
helpText: customHelpText, | ||
}); | ||
expect(screen.getByRole('button')).toHaveTextContent(customHelpText); | ||
}); | ||
}); |
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