yardz commented on a change in pull request #13895: URL: https://github.com/apache/superset/pull/13895#discussion_r607102522
########## File path: superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx ########## @@ -0,0 +1,191 @@ +/** + * 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 userEvent from '@testing-library/user-event'; +import React from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import SliceHeaderControls from '.'; + +jest.mock('src/common/components', () => { + const original = jest.requireActual('src/common/components'); + return { + ...original, + NoAnimationDropdown: (props: any) => ( + <div data-test="NoAnimationDropdown" className="ant-dropdown"> + {props.overlay} + {props.children} + </div> + ), + }; +}); + +const createProps = () => ({ + addDangerToast: jest.fn(), + addSuccessToast: jest.fn(), + exploreChart: jest.fn(), + exportCSV: jest.fn(), + forceRefresh: jest.fn(), + handleToggleFullSize: jest.fn(), + toggleExpandSlice: jest.fn(), + slice: { + slice_id: 371, + slice_url: '/superset/explore/?form_data=%7B%22slice_id%22%3A%20371%7D', + slice_name: 'Vaccine Candidates per Country & Stage', + form_data: { + adhoc_filters: [], + color_scheme: 'supersetColors', + datasource: '58__table', + groupby: ['product_category', 'clinical_stage'], + linear_color_scheme: 'schemeYlOrBr', + metric: 'count', + queryFields: { + groupby: 'groupby', + metric: 'metrics', + secondary_metric: 'metrics', + }, + row_limit: 10000, + slice_id: 371, + time_range: 'No filter', + time_range_endpoints: ['inclusive', 'exclusive'], + url_params: {}, + viz_type: 'sunburst', + }, + viz_type: 'sunburst', + datasource: '58__table', + description: 'test-description', + description_markeddown: '', + owners: [], + modified: '<span class="no-wrap">22 hours ago</span>', + changed_on: 1617143411523, + }, + isCached: [false], + isExpanded: false, + cachedDttm: [null], + updatedDttm: 1617213803803, + supersetCanExplore: true, + supersetCanCSV: true, + sliceCanEdit: false, + componentId: 'CHART-fYo7IyvKZQ', + dashboardId: 26, + isFullSize: false, + chartStatus: 'rendered', +}); + +// beforeEach(()=>{ +// jest.resetAllMocks(); +// }) + +test('Should render', () => { + const props = createProps(); + render(<SliceHeaderControls {...props} />, { useRedux: true }); + expect(screen.getByRole('button', { name: '...' })).toBeInTheDocument(); + expect(screen.getByTestId('NoAnimationDropdown')).toBeInTheDocument(); +}); + +test('Should render default props', () => { + const props = createProps(); + + // @ts-ignore + delete props.forceRefresh; + // @ts-ignore + delete props.toggleExpandSlice; + // @ts-ignore + delete props.exploreChart; + // @ts-ignore + delete props.exportCSV; + // @ts-ignore + delete props.cachedDttm; + // @ts-ignore + delete props.updatedDttm; + // @ts-ignore + delete props.isCached; + // @ts-ignore + delete props.isExpanded; + // @ts-ignore + delete props.sliceCanEdit; Review comment: I explained it better to michael on a call. createProps is a "real prop" that is being used today in the preset (dev data). But the object has some items that are optional, so for those items I am deleting in order to do some test scenarios. I could do that, but it would involve the cost of adjusting all the other tests. I find it easier to maintain just 2 "different" scenarios than to distribute this across multiple test cases. This is part of the cost for complex components :-( -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
