-
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: 13956 inform user when a linked component in subform table is i…
…nvalid (#13987) Co-authored-by: Jamal Alabdullah <jamalalabdullah@Jamals-MacBook-Pro.local>
- Loading branch information
Showing
4 changed files
with
144 additions
and
8 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
101 changes: 101 additions & 0 deletions
101
...erties/EditSubformTableColumns/ColumnElement/EditColumnElement/EditColumnElement.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,101 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { subformLayoutMock } from '../../../../../testing/subformLayoutMock'; | ||
import { | ||
EditColumnElementComponentSelect, | ||
type EditColumnElementComponentSelectProps, | ||
} from './EditColumnElement'; | ||
|
||
const defaultComponents = [ | ||
{ | ||
id: subformLayoutMock.component1Id, | ||
type: subformLayoutMock.component1.type, | ||
itemType: subformLayoutMock.component1.itemType, | ||
dataModelBindings: subformLayoutMock.component1.dataModelBindings, | ||
}, | ||
{ | ||
id: subformLayoutMock.component2Id, | ||
type: subformLayoutMock.component2.type, | ||
itemType: subformLayoutMock.component2.itemType, | ||
}, | ||
]; | ||
|
||
describe('EditColumnElementComponentSelect', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render combobox with no components message when no components are available', async () => { | ||
const user = userEvent.setup(); | ||
renderEditColumnElementComponentSelect({ | ||
components: [], | ||
}); | ||
|
||
const componentSelect = screen.getByRole('combobox', { | ||
name: textMock('ux_editor.properties_panel.subform_table_columns.choose_component'), | ||
}); | ||
|
||
expect(componentSelect).toBeInTheDocument(); | ||
await user.click(componentSelect); | ||
expect( | ||
screen.getByText( | ||
textMock( | ||
'ux_editor.properties_panel.subform_table_columns.no_components_available_message', | ||
), | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render no components message when components are available', async () => { | ||
const user = userEvent.setup(); | ||
renderEditColumnElementComponentSelect(); | ||
const componentSelect = screen.getByRole('combobox', { | ||
name: textMock('ux_editor.properties_panel.subform_table_columns.choose_component'), | ||
}); | ||
|
||
expect(componentSelect).toBeInTheDocument(); | ||
await user.click(componentSelect); | ||
expect( | ||
screen.queryByRole('option', { | ||
name: textMock( | ||
'ux_editor.properties_panel.subform_table_columns.no_components_available_message', | ||
), | ||
}), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render just components with labels', async () => { | ||
const user = userEvent.setup(); | ||
renderEditColumnElementComponentSelect(); | ||
const componentSelect = screen.getByRole('combobox', { | ||
name: textMock('ux_editor.properties_panel.subform_table_columns.choose_component'), | ||
}); | ||
|
||
expect(componentSelect).toBeInTheDocument(); | ||
await user.click(componentSelect); | ||
expect( | ||
screen.getByRole('option', { | ||
name: new RegExp(`${subformLayoutMock.component1Id}`), | ||
}), | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole('option', { | ||
name: new RegExp(`${subformLayoutMock.component2Id}`), | ||
}), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
const renderEditColumnElementComponentSelect = ( | ||
props: Partial<EditColumnElementComponentSelectProps> = {}, | ||
) => { | ||
return render( | ||
<EditColumnElementComponentSelect | ||
components={defaultComponents} | ||
onSelectComponent={jest.fn()} | ||
{...props} | ||
/>, | ||
); | ||
}; |
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