alex-poor commented on code in PR #40679:
URL: https://github.com/apache/superset/pull/40679#discussion_r3800079120
##########
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:
##########
@@ -940,3 +940,63 @@ test('Should NOT show row count warning for table chart
with server pagination w
mockUseUiConfig.mockRestore();
});
+
+const mockDefaultUiConfig = () => {
+ (useUiConfig as jest.Mock).mockReturnValue({
+ hideTitle: false,
+ hideTab: false,
+ hideNav: false,
+ hideChartControls: false,
+ emitDataMasks: false,
+ showRowLimitWarning: false,
+ });
+};
+
+test('Should display the localized name when not in edit mode', () => {
+ mockDefaultUiConfig();
+ const props = createProps({
+ editMode: false,
+ sliceName: 'Sales',
+ localizedName: 'Ventes',
+ });
+ render(<SliceHeader {...props} />, {
+ useRedux: true,
+ useRouter: true,
+ initialState,
+ });
+ expect(screen.getByText('Ventes')).toBeInTheDocument();
+ expect(screen.queryByText('Sales')).not.toBeInTheDocument();
+});
+
+test('Should display the canonical name in edit mode so edits target it', ()
=> {
+ mockDefaultUiConfig();
+ const props = createProps({
+ editMode: true,
+ sliceName: 'Sales',
+ localizedName: 'Ventes',
+ });
+ render(<SliceHeader {...props} />, {
+ useRedux: true,
+ useRouter: true,
+ initialState,
+ });
+ // In edit mode the editable field must show the canonical name, otherwise a
+ // save would round-trip the translation into slice_name.
+ expect(screen.getByText('Sales')).toBeInTheDocument();
Review Comment:
Adopted in 680103a, with a correction to the premise: the test passed as
written — `getByText('Sales')` did match — so it was not failing. But you're
right that the value is the thing to assert on, and switching to
`getByDisplayValue` exposed something better: the *negative* assertion was the
weak one. `queryByText('Ventes')` could never have matched a value-held string,
so it would have passed whether or not the localized name leaked into the
field. It now queries the display value too, so it tests what it claims to.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]