You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/24 08:19:22 UTC

(superset) branch master updated: refactor: migrate test files from nested describe blocks and remove stale lint ignores (#39202)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 584d41759b5 refactor: migrate test files from nested describe blocks and remove stale lint ignores (#39202)
584d41759b5 is described below

commit 584d41759b51dadbe19cbd8e156f4ddeed2eaf43
Author: Jay Masiwal <ma...@gmail.com>
AuthorDate: Wed Jun 24 13:49:15 2026 +0530

    refactor: migrate test files from nested describe blocks and remove stale lint ignores (#39202)
    
    Co-authored-by: Joe Li <jo...@preset.io>
---
 .../src/features/tags/BulkTagModal.test.tsx        | 119 +++++-----
 .../src/hooks/useThemeMenuItems.test.tsx           |   1 -
 superset-frontend/src/utils/common.test.tsx        | 248 ++++++++++-----------
 3 files changed, 179 insertions(+), 189 deletions(-)

diff --git a/superset-frontend/src/features/tags/BulkTagModal.test.tsx b/superset-frontend/src/features/tags/BulkTagModal.test.tsx
index 5b6ba04b9b6..9f436c81cc0 100644
--- a/superset-frontend/src/features/tags/BulkTagModal.test.tsx
+++ b/superset-frontend/src/features/tags/BulkTagModal.test.tsx
@@ -6,7 +6,7 @@
  * 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
+ * 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
@@ -36,80 +36,77 @@ const mockedProps = {
   resourceName: 'dashboard',
 };
 
-// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
-describe('BulkTagModal', () => {
-  afterEach(() => {
-    fetchMock.clearHistory().removeRoutes();
-    jest.clearAllMocks();
-  });
-
-  test('should render', () => {
-    const { container } = render(<BulkTagModal {...mockedProps} />);
-    expect(container).toBeInTheDocument();
-  });
+afterEach(() => {
+  fetchMock.clearHistory().removeRoutes();
+  jest.clearAllMocks();
+});
 
-  test('renders the correct title and message', () => {
-    render(<BulkTagModal {...mockedProps} />);
-    expect(
-      screen.getByText(/you are adding tags to 2 dashboards/i),
-    ).toBeInTheDocument();
-    expect(screen.getByText('Bulk tag')).toBeInTheDocument();
-  });
+test('should render', () => {
+  const { container } = render(<BulkTagModal {...mockedProps} />);
+  expect(container).toBeInTheDocument();
+});
 
-  test('renders tags input field', async () => {
-    render(<BulkTagModal {...mockedProps} />);
-    const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
-    expect(tagsInput).toBeInTheDocument();
-  });
+test('renders the correct title and message', () => {
+  render(<BulkTagModal {...mockedProps} />);
+  expect(
+    screen.getByText(/you are adding tags to 2 dashboards/i),
+  ).toBeInTheDocument();
+  expect(screen.getByText('Bulk tag')).toBeInTheDocument();
+});
 
-  test('calls onHide when the Cancel button is clicked', () => {
-    render(<BulkTagModal {...mockedProps} />);
-    const cancelButton = screen.getByText('Cancel');
-    fireEvent.click(cancelButton);
-    expect(mockedProps.onHide).toHaveBeenCalled();
-  });
+test('renders tags input field', async () => {
+  render(<BulkTagModal {...mockedProps} />);
+  const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
+  expect(tagsInput).toBeInTheDocument();
+});
 
-  test('submits the selected tags and shows success toast', async () => {
-    fetchMock.post('glob:*/api/v1/tag/bulk_create', {
-      result: {
-        objects_tagged: [1, 2],
-        objects_skipped: [],
-      },
-    });
+test('calls onHide when the Cancel button is clicked', () => {
+  render(<BulkTagModal {...mockedProps} />);
+  const cancelButton = screen.getByText('Cancel');
+  fireEvent.click(cancelButton);
+  expect(mockedProps.onHide).toHaveBeenCalled();
+});
 
-    render(<BulkTagModal {...mockedProps} />);
+test('submits the selected tags and shows success toast', async () => {
+  fetchMock.post('glob:*/api/v1/tag/bulk_create', {
+    result: {
+      objects_tagged: [1, 2],
+      objects_skipped: [],
+    },
+  });
 
-    const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
-    fireEvent.change(tagsInput, { target: { value: 'Test Tag' } });
-    fireEvent.keyDown(tagsInput, { key: 'Enter', code: 'Enter' });
+  render(<BulkTagModal {...mockedProps} />);
 
-    fireEvent.click(screen.getByText('Save'));
+  const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
+  fireEvent.change(tagsInput, { target: { value: 'Test Tag' } });
+  fireEvent.keyDown(tagsInput, { key: 'Enter', code: 'Enter' });
 
-    await waitFor(() => {
-      expect(mockedProps.addSuccessToast).toHaveBeenCalledWith(
-        'Tagged 2 dashboards',
-      );
-    });
+  fireEvent.click(screen.getByText('Save'));
 
-    expect(mockedProps.refreshData).toHaveBeenCalled();
-    expect(mockedProps.onHide).toHaveBeenCalled();
+  await waitFor(() => {
+    expect(mockedProps.addSuccessToast).toHaveBeenCalledWith(
+      'Tagged 2 dashboards',
+    );
   });
 
-  test('handles API errors gracefully', async () => {
-    fetchMock.post('glob:*/api/v1/tag/bulk_create', 500);
+  expect(mockedProps.refreshData).toHaveBeenCalled();
+  expect(mockedProps.onHide).toHaveBeenCalled();
+});
+
+test('handles API errors gracefully', async () => {
+  fetchMock.post('glob:*/api/v1/tag/bulk_create', 500);
 
-    render(<BulkTagModal {...mockedProps} />);
+  render(<BulkTagModal {...mockedProps} />);
 
-    const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
-    fireEvent.change(tagsInput, { target: { value: 'Test Tag' } });
-    fireEvent.keyDown(tagsInput, { key: 'Enter', code: 'Enter' });
+  const tagsInput = await screen.findByRole('combobox', { name: /tags/i });
+  fireEvent.change(tagsInput, { target: { value: 'Test Tag' } });
+  fireEvent.keyDown(tagsInput, { key: 'Enter', code: 'Enter' });
 
-    fireEvent.click(screen.getByText('Save'));
+  fireEvent.click(screen.getByText('Save'));
 
-    await waitFor(() => {
-      expect(mockedProps.addDangerToast).toHaveBeenCalledWith(
-        'Failed to tag items',
-      );
-    });
+  await waitFor(() => {
+    expect(mockedProps.addDangerToast).toHaveBeenCalledWith(
+      'Failed to tag items',
+    );
   });
 });
diff --git a/superset-frontend/src/hooks/useThemeMenuItems.test.tsx b/superset-frontend/src/hooks/useThemeMenuItems.test.tsx
index 0eb49e38571..f4dea0fd035 100644
--- a/superset-frontend/src/hooks/useThemeMenuItems.test.tsx
+++ b/superset-frontend/src/hooks/useThemeMenuItems.test.tsx
@@ -38,7 +38,6 @@ const TestComponent = (props: ThemeSubMenuProps) => {
   return <Menu items={[menuItem]} />;
 };
 
-// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
 describe('useThemeMenuItems', () => {
   const defaultProps = {
     allowOSPreference: true,
diff --git a/superset-frontend/src/utils/common.test.tsx b/superset-frontend/src/utils/common.test.tsx
index d467be8172e..5c3005eacbe 100644
--- a/superset-frontend/src/utils/common.test.tsx
+++ b/superset-frontend/src/utils/common.test.tsx
@@ -7,7 +7,7 @@
  * "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
+ * 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
@@ -27,133 +27,127 @@ import {
   ColumnDefinition,
 } from 'src/utils/common';
 
-// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
-describe('utils/common', () => {
-  // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
-  describe('optionFromValue', () => {
-    test('converts values as expected', () => {
-      expect(optionFromValue(false)).toEqual({
-        value: false,
-        label: FALSE_STRING,
-      });
-      expect(optionFromValue(true)).toEqual({
-        value: true,
-        label: TRUE_STRING,
-      });
-      expect(optionFromValue(null)).toEqual({
-        value: NULL_STRING,
-        label: NULL_STRING,
-      });
-      expect(optionFromValue('')).toEqual({
-        value: '',
-        label: '<empty string>',
-      });
-      expect(optionFromValue('foo')).toEqual({ value: 'foo', label: 'foo' });
-      expect(optionFromValue(5)).toEqual({ value: 5, label: '5' });
-    });
+test('converts values as expected', () => {
+  expect(optionFromValue(false)).toEqual({
+    value: false,
+    label: FALSE_STRING,
   });
-  // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
-  describe('prepareCopyToClipboardTabularData', () => {
-    test('converts empty array', () => {
-      const data: TabularDataRow[] = [];
-      const columns: string[] = [];
-      expect(prepareCopyToClipboardTabularData(data, columns)).toEqual('');
-    });
-    test('converts non empty array', () => {
-      const data: TabularDataRow[] = [
-        { column1: 'lorem', column2: 'ipsum' },
-        { column1: 'dolor', column2: 'sit', column3: 'amet' },
-      ];
-      const columns: string[] = ['column1', 'column2', 'column3'];
-      expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
-        'column1\tcolumn2\tcolumn3\nlorem\tipsum\t\ndolor\tsit\tamet\n',
-      );
-    });
-    test('includes 0 values and handle column objects', () => {
-      const data: TabularDataRow[] = [
-        { column1: 0, column2: 0 },
-        { column1: 1, column2: -1, 0: 0 },
-      ];
-      const columns: ColumnDefinition[] = [
-        { name: 'column1' },
-        { name: 'column2' },
-        { name: '0' },
-      ];
-      expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
-        'column1\tcolumn2\t0\n0\t0\t\n1\t-1\t0\n',
-      );
-    });
+  expect(optionFromValue(true)).toEqual({
+    value: true,
+    label: TRUE_STRING,
   });
-  // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
-  describe('applyFormattingToTabularData', () => {
-    test('does not mutate empty array', () => {
-      const data: TabularDataRow[] = [];
-      expect(applyFormattingToTabularData(data, [])).toEqual(data);
-    });
-    test('does not mutate array without temporal column', () => {
-      const data: TabularDataRow[] = [
-        { column1: 'lorem', column2: 'ipsum' },
-        { column1: 'dolor', column2: 'sit', column3: 'amet' },
-      ];
-      expect(applyFormattingToTabularData(data, [])).toEqual(data);
-    });
-    test('changes formatting of columns selected for formatting', () => {
-      const originalData: TabularDataRow[] = [
-        {
-          __timestamp: null,
-          column1: 'lorem',
-          column2: 1590014060000,
-          column3: 1507680000000,
-        },
-        {
-          __timestamp: 0,
-          column1: 'ipsum',
-          column2: 1590075817000,
-          column3: 1513641600000,
-        },
-        {
-          __timestamp: 1594285437771,
-          column1: 'dolor',
-          column2: 1591062977000,
-          column3: 1516924800000,
-        },
-        {
-          __timestamp: 1594285441675,
-          column1: 'sit',
-          column2: 1591397351000,
-          column3: 1518566400000,
-        },
-      ];
-      const timeFormattedColumns: string[] = ['__timestamp', 'column3'];
-      const expectedData: TabularDataRow[] = [
-        {
-          __timestamp: null,
-          column1: 'lorem',
-          column2: 1590014060000,
-          column3: '2017-10-11 00:00:00',
-        },
-        {
-          __timestamp: '1970-01-01 00:00:00',
-          column1: 'ipsum',
-          column2: 1590075817000,
-          column3: '2017-12-19 00:00:00',
-        },
-        {
-          __timestamp: '2020-07-09 09:03:57',
-          column1: 'dolor',
-          column2: 1591062977000,
-          column3: '2018-01-26 00:00:00',
-        },
-        {
-          __timestamp: '2020-07-09 09:04:01',
-          column1: 'sit',
-          column2: 1591397351000,
-          column3: '2018-02-14 00:00:00',
-        },
-      ];
-      expect(
-        applyFormattingToTabularData(originalData, timeFormattedColumns),
-      ).toEqual(expectedData);
-    });
+  expect(optionFromValue(null)).toEqual({
+    value: NULL_STRING,
+    label: NULL_STRING,
   });
+  expect(optionFromValue('')).toEqual({
+    value: '',
+    label: '<empty string>',
+  });
+  expect(optionFromValue('foo')).toEqual({ value: 'foo', label: 'foo' });
+  expect(optionFromValue(5)).toEqual({ value: 5, label: '5' });
+});
+
+test('converts empty array', () => {
+  const data: TabularDataRow[] = [];
+  const columns: string[] = [];
+  expect(prepareCopyToClipboardTabularData(data, columns)).toEqual('');
+});
+
+test('converts non empty array', () => {
+  const data: TabularDataRow[] = [
+    { column1: 'lorem', column2: 'ipsum' },
+    { column1: 'dolor', column2: 'sit', column3: 'amet' },
+  ];
+  const columns: string[] = ['column1', 'column2', 'column3'];
+  expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
+    'column1\tcolumn2\tcolumn3\nlorem\tipsum\t\ndolor\tsit\tamet\n',
+  );
+});
+
+test('includes 0 values and handle column objects', () => {
+  const data: TabularDataRow[] = [
+    { column1: 0, column2: 0 },
+    { column1: 1, column2: -1, 0: 0 },
+  ];
+  const columns: ColumnDefinition[] = [
+    { name: 'column1' },
+    { name: 'column2' },
+    { name: '0' },
+  ];
+  expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
+    'column1\tcolumn2\t0\n0\t0\t\n1\t-1\t0\n',
+  );
+});
+
+test('does not mutate empty array', () => {
+  const data: TabularDataRow[] = [];
+  expect(applyFormattingToTabularData(data, [])).toEqual(data);
+});
+
+test('does not mutate array without temporal column', () => {
+  const data: TabularDataRow[] = [
+    { column1: 'lorem', column2: 'ipsum' },
+    { column1: 'dolor', column2: 'sit', column3: 'amet' },
+  ];
+  expect(applyFormattingToTabularData(data, [])).toEqual(data);
+});
+
+test('changes formatting of columns selected for formatting', () => {
+  const originalData: TabularDataRow[] = [
+    {
+      __timestamp: null,
+      column1: 'lorem',
+      column2: 1590014060000,
+      column3: 1507680000000,
+    },
+    {
+      __timestamp: 0,
+      column1: 'ipsum',
+      column2: 1590075817000,
+      column3: 1513641600000,
+    },
+    {
+      __timestamp: 1594285437771,
+      column1: 'dolor',
+      column2: 1591062977000,
+      column3: 1516924800000,
+    },
+    {
+      __timestamp: 1594285441675,
+      column1: 'sit',
+      column2: 1591397351000,
+      column3: 1518566400000,
+    },
+  ];
+  const timeFormattedColumns: string[] = ['__timestamp', 'column3'];
+  const expectedData: TabularDataRow[] = [
+    {
+      __timestamp: null,
+      column1: 'lorem',
+      column2: 1590014060000,
+      column3: '2017-10-11 00:00:00',
+    },
+    {
+      __timestamp: '1970-01-01 00:00:00',
+      column1: 'ipsum',
+      column2: 1590075817000,
+      column3: '2017-12-19 00:00:00',
+    },
+    {
+      __timestamp: '2020-07-09 09:03:57',
+      column1: 'dolor',
+      column2: 1591062977000,
+      column3: '2018-01-26 00:00:00',
+    },
+    {
+      __timestamp: '2020-07-09 09:04:01',
+      column1: 'sit',
+      column2: 1591397351000,
+      column3: '2018-02-14 00:00:00',
+    },
+  ];
+  expect(
+    applyFormattingToTabularData(originalData, timeFormattedColumns),
+  ).toEqual(expectedData);
 });