sadpandajoe commented on code in PR #40758: URL: https://github.com/apache/superset/pull/40758#discussion_r3364767081
########## superset-frontend/src/dashboard/actions/dashboardState.certification.test.ts: ########## @@ -0,0 +1,115 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { SupersetClient } from '@superset-ui/core'; +import { waitFor } from 'spec/helpers/testing-library'; +import { + filterId, + sliceEntitiesForDashboard as sliceEntities, +} from 'spec/fixtures/mockSliceEntities'; +import { emptyFilters } from 'spec/fixtures/mockDashboardFilters'; +import mockDashboardData from 'spec/fixtures/mockDashboardData'; +import { saveDashboardRequest } from 'src/dashboard/actions/dashboardState'; +import { SAVE_TYPE_OVERWRITE } from 'src/dashboard/util/constants'; + +const mockState = { + dashboardState: { sliceIds: [filterId], hasUnsavedChanges: true }, + dashboardInfo: { metadata: { color_scheme: 'supersetColors' } }, + sliceEntities, + dashboardFilters: emptyFilters, + dashboardLayout: { + past: [], + present: mockDashboardData.positions, + future: {}, + }, + charts: {}, +}; + +let putStub: jest.SpyInstance; + +beforeEach(() => { + jest.spyOn(SupersetClient, 'post').mockResolvedValue({} as any); + jest.spyOn(SupersetClient, 'get').mockResolvedValue({} as any); + putStub = jest.spyOn(SupersetClient, 'put').mockResolvedValue({ + json: { result: mockDashboardData }, + } as any); +}); + +afterEach(() => { + jest.restoreAllMocks(); +}); + +function setup() { + const getState = jest.fn(() => mockState) as unknown as () => any; + const dispatch = jest.fn(); + return { getState, dispatch }; +} + +test('clears certification_details when certified_by is cleared', async () => { + const { getState, dispatch } = setup(); + const thunk = saveDashboardRequest( + { + ...mockDashboardData, + certified_by: '', + certification_details: 'Old details', + }, + 1, + SAVE_TYPE_OVERWRITE, + ); + thunk(dispatch, getState); + await waitFor(() => expect(putStub.mock.calls.length).toBe(1)); + const body = JSON.parse(putStub.mock.calls[0][0].body); + expect(body.certified_by).toBe(''); + expect(body.certification_details).toBe(''); +}); + +test('preserves certification_details when certified_by is set', async () => { + const { getState, dispatch } = setup(); + const thunk = saveDashboardRequest( + { + ...mockDashboardData, + certified_by: 'Alice', + certification_details: 'Verified by Alice', + }, + 1, + SAVE_TYPE_OVERWRITE, + ); + thunk(dispatch, getState); + await waitFor(() => expect(putStub.mock.calls.length).toBe(1)); + const body = JSON.parse(putStub.mock.calls[0][0].body); + expect(body.certified_by).toBe('Alice'); + expect(body.certification_details).toBe('Verified by Alice'); +}); Review Comment: Both these tests won't catch the regression if the fix is reverted. We should look at how we can update these tests such that if the fix is reverted these would fail. -- 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]
