michael-s-molina commented on a change in pull request #13887:
URL: https://github.com/apache/superset/pull/13887#discussion_r607067996



##########
File path: 
superset-frontend/src/dashboard/components/filterscope/FilterScope.test.tsx
##########
@@ -0,0 +1,372 @@
+/**
+ * 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 React from 'react';
+import { render, screen } from 'spec/helpers/testing-library';
+import userEvent from '@testing-library/user-event';
+import FilterScopeSelector from './FilterScopeSelector';
+
+const ROOT_ID = 'ROOT_ID';
+const GRID = 'GRID';
+const TABS = 'TABS';
+const TAB = 'TAB';
+const FILTER_A = 'FILTER_A';
+const FILTER_B = 'FILTER_B';
+const FILTER_C = 'FILTER_C';
+const TAB_A = 'TAB_A';
+const TAB_B = 'TAB_B';
+const CHART_A = 'CHART_A';
+const CHART_B = 'CHART_B';
+const CHART_C = 'CHART_C';
+const CHART_D = 'CHART_D';
+
+const EXPAND_ALL = 'Expand all';
+const COLLAPSE_ALL = 'Collapse all';
+const CHECKED = 'checked';
+const UNCHECKED = 'unchecked';
+const INDETERMINATE = 'indeterminate';
+const ALL_FILTERS = 'All filters';
+const ALL_CHARTS = 'All charts';
+
+const createProps = () => ({
+  dashboardFilters: {
+    1: {
+      chartId: 1,
+      componentId: 'component-id',
+      datasourceId: 'datasource-id',
+      directPathToFilter: [],
+      isDateFilter: false,
+      isInstantFilter: false,
+      filterName: FILTER_A,
+      columns: { column_b: undefined, column_c: undefined },
+      labels: { column_b: FILTER_B, column_c: FILTER_C },
+      scopes: {
+        column_b: { immune: [], scope: [ROOT_ID] },
+        column_c: { immune: [], scope: [ROOT_ID] },
+      },
+    },
+  },
+  layout: {
+    ROOT_ID: { children: [GRID], id: ROOT_ID, type: 'ROOT' },
+    GRID: {
+      children: [TABS],
+      id: GRID,
+      type: GRID,
+      parents: [ROOT_ID],
+    },
+    TABS: {
+      children: [TAB_A, TAB_B],
+      id: TABS,
+      type: TABS,
+      parents: [ROOT_ID, GRID],
+    },
+    TAB_A: {
+      meta: { text: TAB_A },
+      children: [CHART_A, CHART_B],
+      id: TAB_A,
+      type: TAB,
+      parents: [ROOT_ID, GRID, TABS],
+    },
+    TAB_B: {
+      meta: { text: TAB_B },
+      children: [CHART_C, CHART_D],
+      id: TAB_B,
+      type: TAB,
+      parents: [ROOT_ID, GRID, TABS],
+    },
+    CHART_A: {
+      meta: {
+        chartId: 2,
+        sliceName: CHART_A,
+      },
+      children: [],
+      id: CHART_A,
+      type: 'CHART',
+      parents: [ROOT_ID, GRID, TABS, TAB_A],
+    },
+    CHART_B: {
+      meta: {
+        chartId: 3,
+        sliceName: CHART_B,
+      },
+      children: [],
+      id: CHART_B,
+      type: 'CHART',
+      parents: [ROOT_ID, GRID, TABS, TAB_A],
+    },
+    CHART_C: {
+      meta: {
+        chartId: 4,
+        sliceName: CHART_C,
+      },
+      children: [],
+      id: CHART_C,
+      type: 'CHART',
+      parents: [ROOT_ID, GRID, TABS, TAB_B],
+    },
+    CHART_D: {
+      meta: {
+        chartId: 5,
+        sliceName: CHART_D,
+      },
+      children: [],
+      id: CHART_D,
+      type: 'CHART',
+      parents: [ROOT_ID, GRID, TABS, TAB_B],
+    },
+  },
+  updateDashboardFiltersScope: jest.fn(),
+  setUnsavedChanges: jest.fn(),
+  onCloseModal: jest.fn(),
+});
+
+type CheckboxState = 'checked' | 'unchecked' | 'indeterminate';
+
+/**
+ * Unfortunatelly react-checkbox-tree doesn't provide an easy way to
+ * access the checkbox icon. We need this function to find the element.
+ */
+function getCheckboxIcon(element: HTMLElement): Element {
+  const parent = element.parentElement!;
+  if (parent.classList.contains('rct-text')) {
+    return parent.children[1];
+  }
+  return getCheckboxIcon(parent);
+}
+
+/**
+ * Unfortunatelly when using react-checkbox-tree, the only perceived change of 
a
+ * checkbox state change is the fill color of the SVG icon.
+ */
+function getCheckboxState(name: string): CheckboxState {
+  const element = screen.getByRole('link', { name });
+  const svgPath = getCheckboxIcon(element).children[1].children[0].children[0];
+  const fill = svgPath.getAttribute('fill');
+  return fill === '#20A7C9'
+    ? CHECKED
+    : fill === '#999999'

Review comment:
       Great tip! Done.




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