Skip to content

Commit

Permalink
fix tests related to 32 ver upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Dec 10, 2024
1 parent 194328d commit 741b5b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
36 changes: 15 additions & 21 deletions superset-frontend/src/components/GridTable/HeaderMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,10 @@ const mockInvisibleColumn3 = {
getDataAsCsv: jest.fn().mockReturnValue('csv'),
} as any as Column;

const mockSetColDef = jest.fn();

const mockGridApi = {
autoSizeColumn: jest.fn(),
autoSizeColumns: jest.fn(),
autoSizeAllColumns: jest.fn(),
setColumnPinned: jest.fn(),
getColumn: jest.fn().mockReturnValue({
setColDef: mockSetColDef,
getColDef: jest.fn().mockReturnValue({}),
}),
getColumns: jest.fn().mockReturnValue([]),
Expand All @@ -117,13 +113,12 @@ const mockedProps = {
};

afterEach(() => {
mockSetColDef.mockClear();
(mockGridApi.getDataAsCsv as jest.Mock).mockClear();
(mockGridApi.setColumnPinned as jest.Mock).mockClear();
(mockGridApi.setColumnVisible as jest.Mock).mockClear();
(mockGridApi.setColumnsPinned as jest.Mock).mockClear();
(mockGridApi.setColumnsVisible as jest.Mock).mockClear();
(mockGridApi.setColumnsVisible as jest.Mock).mockClear();
(mockGridApi.setColumnsPinned as jest.Mock).mockClear();
(mockGridApi.autoSizeColumn as jest.Mock).mockClear();
(mockGridApi.autoSizeColumns as jest.Mock).mockClear();
(mockGridApi.autoSizeAllColumns as jest.Mock).mockClear();
(mockGridApi.moveColumns as jest.Mock).mockClear();
});
Expand All @@ -145,14 +140,14 @@ test('renders buttons pinning both side', () => {
expect(queryByText('Pin Left')).toBeTruthy();
expect(queryByText('Pin Right')).toBeTruthy();
fireEvent.click(getByText('Pin Left'));
expect(mockGridApi.setColumnPinned).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnPinned).toHaveBeenCalledWith(
mockedProps.colId,
expect(mockGridApi.setColumnsPinned).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnsPinned).toHaveBeenCalledWith(
[mockedProps.colId],
'left',
);
fireEvent.click(getByText('Pin Right'));
expect(mockGridApi.setColumnPinned).toHaveBeenLastCalledWith(
mockedProps.colId,
expect(mockGridApi.setColumnsPinned).toHaveBeenLastCalledWith(
[mockedProps.colId],
'right',
);
});
Expand All @@ -164,9 +159,9 @@ test('renders unpin on pinned left', () => {
expect(queryByText('Pin Left')).toBeFalsy();
expect(queryByText('Unpin')).toBeTruthy();
fireEvent.click(getByText('Unpin'));
expect(mockGridApi.setColumnPinned).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnPinned).toHaveBeenCalledWith(
mockedProps.colId,
expect(mockGridApi.setColumnsPinned).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnsPinned).toHaveBeenCalledWith(
[mockedProps.colId],
null,
);
});
Expand All @@ -181,9 +176,8 @@ test('renders autosize column', async () => {
const { getByText } = render(<HeaderMenu {...mockedProps} />);
fireEvent.click(getByText('Autosize Column'));
await waitFor(() =>
expect(mockGridApi.autoSizeColumn).toHaveBeenCalledTimes(1),
expect(mockGridApi.autoSizeColumns).toHaveBeenCalledTimes(1),
);
expect(mockSetColDef).toHaveBeenCalledTimes(1);
});

test('renders unhide when invisible column exists', async () => {
Expand All @@ -193,8 +187,8 @@ test('renders unhide when invisible column exists', async () => {
expect(queryByText('Unhide')).toBeTruthy();
const unhideColumnsButton = await screen.findByText('column2');
fireEvent.click(unhideColumnsButton);
expect(mockGridApi.setColumnVisible).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnVisible).toHaveBeenCalledWith('column2', true);
expect(mockGridApi.setColumnsVisible).toHaveBeenCalledTimes(1);
expect(mockGridApi.setColumnsVisible).toHaveBeenCalledWith(['column2'], true);
});

describe('for main menu', () => {
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/GridTable/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const HeaderMenu: React.FC<Params> = ({
}: Params) => {
const pinColumn = useCallback(
(pinLoc: ColumnPinnedType) => {
api.setColumnPinned(colId, pinLoc);
api.setColumnsPinned([colId], pinLoc);
},
[api, colId],
);
Expand Down

0 comments on commit 741b5b1

Please sign in to comment.