-
-
Notifications
You must be signed in to change notification settings - Fork 301
Created new studioBanner for form validation #5214
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
Changes from 13 commits
90ec7a5
7d56b91
a88acad
4b5aac0
c2febf8
e6dbc22
b389537
53e139e
d27a23e
d9b1a8e
ad877f9
d713285
0c3f925
f4d9955
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <template> | ||
|
|
||
| <div | ||
| class="banner" | ||
| data-testid="studio-banner" | ||
| :style="{ backgroundColor: error ? $themePalette.red.v_100 : '' }" | ||
| > | ||
| <slot> | ||
| {{ text }} | ||
| </slot> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import useKLiveRegion from 'kolibri-design-system/lib/composables/useKLiveRegion'; | ||
|
|
||
| export default { | ||
| name: 'StudioBanner', | ||
| setup() { | ||
| const { sendPoliteMessage } = useKLiveRegion(); | ||
| return { sendPoliteMessage }; | ||
| }, | ||
| props: { | ||
| error: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| }, | ||
| mounted() { | ||
| const slotContent = this.$slots.default; | ||
| const textContent = slotContent[0].text; | ||
| if (textContent && this.error) { | ||
| this.sendPoliteMessage(textContent); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost there :) Screen reader now properly announces the error message when I click "Send request" for the first time, while not announcing each dynamic change to error count as I requested 👍 However when I fix few errors, but not all of them, and click the button again, it doesn't announce. This is because the same banner is displayed, and mounted is not executed again. Maybe we could simply
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made changes @MisRob. Thanks for the suggestion. Now sendPoliteMessage will be called in onValidationFailed. Which is triggered by form validation. So from now on when ever the submit is click. If there are any errors sendPoliteMessage will be sent. |
||
| } | ||
| }, | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .banner { | ||
| padding: 16px; | ||
| } | ||
|
|
||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { render, screen } from '@testing-library/vue'; | ||
| import VueRouter from 'vue-router'; | ||
| import StudioBanner from '../StudioBanner.vue'; | ||
|
|
||
| // Mock the Kolibri design system composable | ||
| const mockSendPoliteMessage = jest.fn(); | ||
| jest.mock('kolibri-design-system/lib/composables/useKLiveRegion', () => ({ | ||
| __esModule: true, | ||
| default: () => ({ | ||
| sendPoliteMessage: mockSendPoliteMessage, | ||
| }), | ||
| })); | ||
|
|
||
| const sampleErrorMessage = 'This is an error message'; | ||
|
|
||
| describe('StudioBanner', () => { | ||
| beforeEach(() => { | ||
| mockSendPoliteMessage.mockClear(); | ||
| }); | ||
|
|
||
| test('render with defaults values', () => { | ||
| render(StudioBanner, { | ||
| props: { | ||
| error: false, | ||
| }, | ||
| routes: new VueRouter(), | ||
| slots: { | ||
| default: 'normal text', | ||
| }, | ||
| }); | ||
| const banner = screen.getByTestId('studio-banner'); | ||
| expect(banner).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('render with error true', () => { | ||
| render(StudioBanner, { | ||
| props: { | ||
| error: true, | ||
| }, | ||
| routes: new VueRouter(), | ||
| slots: { | ||
| default: sampleErrorMessage, | ||
| }, | ||
| }); | ||
|
|
||
| const banner = screen.getByTestId('studio-banner'); | ||
| expect(banner).toBeInTheDocument(); | ||
| expect(banner).toHaveStyle('background-color: rgb(255, 217, 211)'); | ||
| expect(screen.getByText(sampleErrorMessage)).toBeInTheDocument(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was
!importantneeded?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check and update it