Skip to content

Commit

Permalink
fix(Tests): Unskip failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geido committed Jan 6, 2025
1 parent e432f20 commit 2e268ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { useState } from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen, within } from 'spec/helpers/testing-library';
import { cleanup, render, screen, within } from 'spec/helpers/testing-library';
import setupPlugins from 'src/setup/setupPlugins';
import { getMockStoreWithNativeFilters } from 'spec/fixtures/mockStore';
import chartQueries, { sliceId } from 'spec/fixtures/mockChartQueries';
Expand Down Expand Up @@ -98,7 +98,7 @@ const MockRenderChart = ({
chartId={chartId ?? defaultChartId}
formData={formData ?? defaultFormData}
showModal={showMenu}
initialFilters={[]}
initialFilters={modalFilters ?? []}
onHideModal={() => {
setShowMenu(false);
}}
Expand All @@ -125,6 +125,16 @@ const renderMenu = ({
);
};

const setupMenu = (filters: BinaryQueryObjectFilterClause[]) => {
cleanup();
renderMenu({
chartId: defaultChartId,
formData: defaultFormData,
isContextMenu: true,
filters,
});
};

/**
* Drill to Detail modal should appear with correct initial filters
*/
Expand All @@ -140,9 +150,8 @@ const expectDrillToDetailModal = async (
});

expect(modal).toBeInTheDocument();
expect(screen.getByTestId('modal-filters')).toHaveTextContent(
JSON.stringify(filters),
);
const modalFilters = await screen.findByTestId('modal-filters');
expect(modalFilters).toHaveTextContent(JSON.stringify(filters));
};

/**
Expand Down Expand Up @@ -222,9 +231,9 @@ const expectDrillToDetailByEnabled = async () => {
await expectMenuItemEnabled(drillToDetailBy);
userEvent.hover(drillToDetailBy);

expect(
await screen.findByTestId('drill-to-detail-by-submenu'),
).toBeInTheDocument();
const submenus = await screen.findAllByTestId('drill-to-detail-by-submenu');

expect(submenus.length).toEqual(2);
};

/**
Expand All @@ -244,18 +253,17 @@ const expectDrillToDetailByDisabled = async (tooltipContent?: string) => {
const expectDrillToDetailByDimension = async (
filter: BinaryQueryObjectFilterClause,
) => {
userEvent.hover(screen.getByRole('dialog'));
const drillToDetailBySubMenu = await screen.findByTestId(
userEvent.hover(screen.getByRole('menuitem', { name: 'Drill to detail by' }));
const drillToDetailBySubMenus = await screen.findAllByTestId(
'drill-to-detail-by-submenu',
);

const menuItemName = `Drill to detail by ${filter.formattedVal}`;
console.log(screen.debug());
const drillToDetailBySubmenuItem = within(drillToDetailBySubMenu).getByRole(
'menuitem',
);
const drillToDetailBySubmenuItems = await within(
drillToDetailBySubMenus[1],
).findAllByRole('menuitem');

await expectMenuItemEnabled(drillToDetailBySubmenuItem);
await expectMenuItemEnabled(drillToDetailBySubmenuItems[0]);
await expectDrillToDetailModal(menuItemName, [filter]);
};

Expand All @@ -265,16 +273,15 @@ const expectDrillToDetailByDimension = async (
const expectDrillToDetailByAll = async (
filters: BinaryQueryObjectFilterClause[],
) => {
userEvent.hover(screen.getByRole('dialog', { name: 'Drill to detail by' }));
const drillToDetailBySubMenu = await screen.findByTestId(
userEvent.hover(screen.getByRole('menuitem', { name: 'Drill to detail by' }));
const drillToDetailBySubMenus = await screen.findAllByTestId(
'drill-to-detail-by-submenu',
);

const menuItemName = 'Drill to detail by all';
const drillToDetailBySubmenuItem = within(drillToDetailBySubMenu).getByRole(
'menuitem',
{ name: menuItemName },
);
const drillToDetailBySubmenuItem = await within(
drillToDetailBySubMenus[1],
).findByRole('menuitem', { name: menuItemName });

await expectMenuItemEnabled(drillToDetailBySubmenuItem);
await expectDrillToDetailModal(menuItemName, filters);
Expand Down Expand Up @@ -359,32 +366,34 @@ test('context menu for supported chart, dimensions, no filters', async () => {
);
});

// TODO: @geido - Fix these tests
test.skip('context menu for supported chart, dimensions, 1 filter', async () => {
test('context menu for supported chart, dimensions, 1 filter', async () => {
const filters = [filterA];
renderMenu({
formData: defaultFormData,
isContextMenu: true,
filters,
});

await expectDrillToDetailEnabled();
await expectDrillToDetailByEnabled();
await expectDrillToDetailByDimension(filterA);
});

test.skip('context menu for supported chart, dimensions, 2 filters', async () => {
test('context menu for supported chart, dimensions, filter A', async () => {
const filters = [filterA, filterB];
renderMenu({
chartId: defaultChartId,
formData: defaultFormData,
isContextMenu: true,
filters,
});

await expectDrillToDetailEnabled();
setupMenu(filters);
await expectDrillToDetailByEnabled();
await expectDrillToDetailByDimension(filterA);
});

test('context menu for supported chart, dimensions, filter B', async () => {
const filters = [filterA, filterB];
setupMenu(filters);
await expectDrillToDetailByEnabled();
await expectDrillToDetailByDimension(filterB);
});

test('context menu for supported chart, dimensions, all filters', async () => {
const filters = [filterA, filterB];
setupMenu(filters);
await expectDrillToDetailByAll(filters);
});
4 changes: 2 additions & 2 deletions superset-frontend/src/features/home/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import * as reactRedux from 'react-redux';
import fetchMock from 'fetch-mock';
import { fireEvent, render, screen, waitFor } from 'spec/helpers/testing-library';
import { render, screen } from 'spec/helpers/testing-library';
import setupExtensions from 'src/setup/setupExtensions';
import userEvent from '@testing-library/user-event';
import { getExtensionsRegistry } from '@superset-ui/core';
Expand Down Expand Up @@ -316,7 +316,7 @@ test('should render all the top navbar menu items', async () => {
expect(screen.getByText(item.label)).toBeInTheDocument();
});
});
// TODO: @geido

test.skip('should render the top navbar child menu items', async () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
Expand Down

0 comments on commit 2e268ad

Please sign in to comment.