2022-04-06 13:49:25 +02:00
|
|
|
import { waitFor } from '@testing-library/react';
|
|
|
|
|
import { ExploreId } from '../../../../types';
|
|
|
|
|
import { withinExplore } from './setup';
|
2022-02-23 19:05:38 +01:00
|
|
|
|
2022-04-06 13:49:25 +02:00
|
|
|
export const assertQueryHistoryExists = (query: string, exploreId: ExploreId = ExploreId.left) => {
|
|
|
|
|
const selector = withinExplore(exploreId);
|
|
|
|
|
|
|
|
|
|
expect(selector.getByText('1 queries')).toBeInTheDocument();
|
|
|
|
|
const queryItem = selector.getByLabelText('Query text');
|
2022-02-23 19:05:38 +01:00
|
|
|
expect(queryItem).toHaveTextContent(query);
|
|
|
|
|
};
|
2022-04-06 13:49:25 +02:00
|
|
|
|
|
|
|
|
export const assertQueryHistory = async (expectedQueryTexts: string[], exploreId: ExploreId = ExploreId.left) => {
|
|
|
|
|
const selector = withinExplore(exploreId);
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(selector.getByText(`${expectedQueryTexts.length} queries`)).toBeInTheDocument();
|
|
|
|
|
const queryTexts = selector.getAllByLabelText('Query text');
|
|
|
|
|
expectedQueryTexts.forEach((expectedQueryText, queryIndex) => {
|
|
|
|
|
expect(queryTexts[queryIndex]).toHaveTextContent(expectedQueryText);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const assertQueryHistoryIsStarred = async (expectedStars: boolean[], exploreId: ExploreId = ExploreId.left) => {
|
|
|
|
|
const selector = withinExplore(exploreId);
|
|
|
|
|
const starButtons = selector.getAllByRole('button', { name: /Star query|Unstar query/ });
|
|
|
|
|
await waitFor(() =>
|
|
|
|
|
expectedStars.forEach((starred, queryIndex) => {
|
|
|
|
|
expect(starButtons[queryIndex]).toHaveAccessibleName(starred ? 'Unstar query' : 'Star query');
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|