Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang committed Apr 6, 2023
1 parent 9c27db7 commit de5c2df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,25 @@ import chartQueries, { sliceId } from 'spec/fixtures/mockChartQueries';
import fetchMock from 'fetch-mock';
import DrillByChart from './DrillByChart';

const CHART_DATA_ENDPOINT =
'glob:*api/v1/chart/data?form_data=%7B%22slice_id%22%3A18%7D';

const chart = chartQueries[sliceId];

const fetchWithNoData = () => {
fetchMock.post(CHART_DATA_ENDPOINT, {
result: [
{
total_count: 0,
data: [],
colnames: [],
coltypes: [],
},
],
});
};

const setup = (overrides: Record<string, any> = {}) =>
render(<DrillByChart formData={{ ...chart.form_data, ...overrides }} />, {
useRedux: true,
});
const setup = (overrides: Record<string, any> = {}, result?: any) =>
render(
<DrillByChart
formData={{ ...chart.form_data, ...overrides }}
result={result}
/>,
{
useRedux: true,
},
);

const waitForRender = (overrides: Record<string, any> = {}) =>
waitFor(() => setup(overrides));

afterEach(fetchMock.restore);

test('should render', async () => {
fetchWithNoData();
const { container } = await waitForRender();
expect(container).toBeInTheDocument();
});
Expand All @@ -64,7 +53,6 @@ test('should render loading indicator', async () => {
});

test('should render the "No results" components', async () => {
fetchWithNoData();
setup();
setup({}, []);
expect(await screen.findByText('No Results')).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Loading from 'src/components/Loading';

interface DrillByChartProps {
formData: BaseFormData & { [key: string]: any };
result: QueryData[];
result?: QueryData[];
}

export default function DrillByChart({ formData, result }: DrillByChartProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ test('should generate Explore url', async () => {
await screen.findByRole('link', { name: 'Edit chart' }),
).toHaveAttribute('href', '/explore/?form_data_key=123&dashboard_page_id=1');
});

test('should render radio buttons', async () => {
await renderModal();
const chartRadio = screen.getByRole('radio', { name: /chart/i });
const tableRadio = screen.getByRole('radio', { name: /table/i });

expect(chartRadio).toBeInTheDocument();
expect(tableRadio).toBeInTheDocument();
expect(chartRadio).toBeChecked();
expect(tableRadio).not.toBeChecked();
userEvent.click(tableRadio);
expect(chartRadio).not.toBeChecked();
expect(tableRadio).toBeChecked();
});

0 comments on commit de5c2df

Please sign in to comment.