sadpandajoe commented on code in PR #40000:
URL: https://github.com/apache/superset/pull/40000#discussion_r3432190812


##########
superset-frontend/src/chartCustomizations/components/TimeGrain/TimeGrainPreFilter.integration.test.tsx:
##########
@@ -0,0 +1,169 @@
+/**
+ * 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.
+ */
+
+/**
+ * Integration Test: Time Grain Pre-filter Feature (Customization plugin)
+ *
+ * Mirrors 
src/filters/components/TimeGrain/TimeGrainPreFilter.integration.test.tsx
+ * but targets the customization plugin at
+ * src/chartCustomizations/components/TimeGrain/TimeGrainFilterPlugin and adds
+ * a case for the escape hatch the customization version introduces.
+ */
+
+import {
+  render,
+  screen,
+  userEvent,
+  waitFor,
+} from 'spec/helpers/testing-library';
+import PluginFilterTimegrain from 
'src/chartCustomizations/components/TimeGrain/TimeGrainFilterPlugin';
+
+const data = [
+  { duration: 'PT1M', name: 'Minute' },
+  { duration: 'PT1H', name: 'Hour' },
+  { duration: 'P1D', name: 'Day' },
+  { duration: 'P1W', name: 'Week' },
+  { duration: 'P1M', name: 'Month' },
+];
+
+const baseConfig = {
+  height: 100,
+  width: 300,
+  setFilterActive: jest.fn(),
+  setHoveredFilter: jest.fn(),
+  unsetHoveredFilter: jest.fn(),
+  setFocusedFilter: jest.fn(),
+  unsetFocusedFilter: jest.fn(),
+  inputRef: { current: null },
+};
+
+/**
+ * Scenario: Dashboard owner configures a time grain filter to show only Hour, 
Day, Week.
+ * End-user opens the dashboard and can only select from those three options.
+ */
+test('time grain pre-filter restricts dashboard filter options', async () => {
+  const setDataMask = jest.fn();
+  const dashboardConfig = {
+    ...baseConfig,
+    data,
+    formData: {
+      nativeFilterId: 'time_grain_1',
+      defaultValue: null,
+      viz_type: 'filter_timegrain',
+      time_grains: ['PT1H', 'P1D', 'P1W'],
+    },
+    filterState: {
+      value: null,
+      validateStatus: undefined,
+      validateMessage: undefined,
+    },
+    setDataMask,
+  };
+
+  render(<PluginFilterTimegrain {...(dashboardConfig as any)} />);

Review Comment:
   nit: should we be casting this as any? I know we were trying to remove them 
in the code but unsure if it's something we want to do for tests too.



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

Reply via email to