rusackas commented on a change in pull request #13656:
URL: https://github.com/apache/superset/pull/13656#discussion_r602033323



##########
File path: 
superset-frontend/src/explore/components/controls/CollectionControl/CollectionControl.test.tsx
##########
@@ -0,0 +1,171 @@
+/**
+ * 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 CollectionControl from '.';
+
+jest.mock('@superset-ui/chart-controls', () => ({
+  InfoTooltipWithTrigger: (props: any) => (
+    <button
+      onClick={props.onClick}
+      type="button"
+      data-icon={props.icon}
+      data-tooltip={props.tooltip}
+    >
+      {props.label}
+    </button>
+  ),
+}));
+
+jest.mock('..', () => ({
+  __esModule: true,
+  default: {
+    TestControl: (props: any) => (
+      <button
+        type="button"
+        onClick={() => props.onChange(0, 'update')}
+        data-test="TestControl"
+      >
+        TestControl
+      </button>
+    ),
+  },
+}));
+
+let defaultProps = {
+  actions: {
+    addDangerToast: jest.fn(),
+    addInfoToast: jest.fn(),
+    addSuccessToast: jest.fn(),
+    addWarningToast: jest.fn(),
+    createNewSlice: jest.fn(),
+    fetchDatasourcesStarted: jest.fn(),
+    fetchDatasourcesSucceeded: jest.fn(),
+    fetchFaveStar: jest.fn(),
+    saveFaveStar: jest.fn(),
+    setControlValue: jest.fn(),
+    setDatasource: jest.fn(),
+    setDatasourceType: jest.fn(),
+    setDatasources: jest.fn(),
+    setExploreControls: jest.fn(),
+    sliceUpdated: jest.fn(),
+    toggleFaveStar: jest.fn(),
+    updateChartTitle: jest.fn(),
+  },
+  addTooltip: 'Add an item',
+  controlName: 'TestControl',
+  description: null,
+  hovered: false,
+  itemGenerator: jest.fn(),
+  keyAccessor: jest.fn(),
+  label: 'Time series columns',
+  name: 'column_collection',
+  onChange: jest.fn(),
+  placeholder: 'Empty collection',
+  type: 'CollectionControl',
+  validationErrors: [],
+  validators: [jest.fn()],
+  value: [{ key: 'hrYAZ5iBH' }],
+};
+
+beforeEach(() => {
+  defaultProps = {
+    actions: {
+      addDangerToast: jest.fn(),
+      addInfoToast: jest.fn(),
+      addSuccessToast: jest.fn(),
+      addWarningToast: jest.fn(),
+      createNewSlice: jest.fn(),
+      fetchDatasourcesStarted: jest.fn(),
+      fetchDatasourcesSucceeded: jest.fn(),
+      fetchFaveStar: jest.fn(),
+      saveFaveStar: jest.fn(),
+      setControlValue: jest.fn(),
+      setDatasource: jest.fn(),
+      setDatasourceType: jest.fn(),
+      setDatasources: jest.fn(),
+      setExploreControls: jest.fn(),
+      sliceUpdated: jest.fn(),
+      toggleFaveStar: jest.fn(),
+      updateChartTitle: jest.fn(),
+    },
+    addTooltip: 'Add an item',
+    controlName: 'TestControl',
+    description: null,
+    hovered: false,
+    itemGenerator: jest.fn(),
+    keyAccessor: jest.fn(),
+    label: 'Time series columns',
+    name: 'column_collection',
+    onChange: jest.fn(),
+    placeholder: 'Empty collection',
+    type: 'CollectionControl',
+    validationErrors: [],
+    validators: [jest.fn()],
+    value: [{ key: 'hrYAZ5iBH' }],
+  };
+});
+
+test('Should render', () => {
+  render(<CollectionControl {...defaultProps} />);
+  expect(screen.getByTestId('CollectionControl')).toBeInTheDocument();

Review comment:
       I'm curious what sort of problems you were running into there that might 
be worth avoiding them for. I like @michael-s-molina 's implementation - it's 
clean, and it makes less noise in the DOM.




-- 
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]

Reply via email to