Skip to content

Commit 47088dd

Browse files
refactored tests as per Copilot
1 parent c3b15a6 commit 47088dd

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ test('Should pass formData to Share menu for embed code feature', () => {
617617
expect(screen.getByText('Share')).toBeInTheDocument();
618618
});
619619

620-
test('Should show single fetched query tooltip with timestamp', () => {
620+
test('Should show single fetched query tooltip with timestamp', async () => {
621621
const updatedDttm = Date.parse('2024-01-28T10:00:00.000Z');
622622
const props = createProps();
623623
props.isCached = [false];
@@ -630,11 +630,11 @@ test('Should show single fetched query tooltip with timestamp', () => {
630630
const refreshButton = screen.getByText('Force refresh');
631631
expect(refreshButton).toBeInTheDocument();
632632

633-
const tooltipContainer = refreshButton.closest('div');
634-
expect(tooltipContainer?.textContent).toMatch(/Fetched/);
633+
userEvent.hover(refreshButton);
634+
expect(await screen.findByText(/Fetched/)).toBeInTheDocument();
635635
});
636636

637-
test('Should show single cached query tooltip with timestamp', () => {
637+
test('Should show single cached query tooltip with timestamp', async () => {
638638
const cachedDttm = '2024-01-28T10:00:00.000Z';
639639
const props = createProps();
640640
props.isCached = [true];
@@ -647,11 +647,11 @@ test('Should show single cached query tooltip with timestamp', () => {
647647
const refreshButton = screen.getByText('Force refresh');
648648
expect(refreshButton).toBeInTheDocument();
649649

650-
const tooltipContainer = refreshButton.closest('div');
651-
expect(tooltipContainer?.textContent).toMatch(/Cached/);
650+
userEvent.hover(refreshButton);
651+
expect(await screen.findByText(/Cached/)).toBeInTheDocument();
652652
});
653653

654-
test('Should show multiple per-query tooltips when all queries are fetched', () => {
654+
test('Should show multiple per-query tooltips when all queries are fetched', async () => {
655655
const cachedDttm1 = '';
656656
const cachedDttm2 = '';
657657
const updatedDttm = Date.parse('2024-01-28T10:10:00.000Z');
@@ -666,11 +666,11 @@ test('Should show multiple per-query tooltips when all queries are fetched', ()
666666
const refreshButton = screen.getByText('Force refresh');
667667
expect(refreshButton).toBeInTheDocument();
668668

669-
const tooltipContainer = refreshButton.closest('div');
670-
expect(tooltipContainer?.textContent).toMatch(/Fetched/);
669+
userEvent.hover(refreshButton);
670+
expect(await screen.findByText(/Fetched/)).toBeInTheDocument();
671671
});
672672

673-
test('Should show multiple per-query tooltips when all queries are cached', () => {
673+
test('Should show multiple per-query tooltips when all queries are cached', async() => {
674674
const cachedDttm1 = '2025-01-28T10:00:00.000Z';
675675
const cachedDttm2 = '2024-01-28T10:05:00.000Z';
676676
const props = createProps(VizType.Table);
@@ -684,14 +684,13 @@ test('Should show multiple per-query tooltips when all queries are cached', () =
684684
const refreshButton = screen.getByText('Force refresh');
685685
expect(refreshButton).toBeInTheDocument();
686686

687-
const tooltipContainer = refreshButton.closest('div');
688-
expect(tooltipContainer?.textContent).toMatch(/Query 1:/);
689-
expect(tooltipContainer?.textContent).toMatch(/Query 2:/);
690-
expect(tooltipContainer?.textContent).toMatch(/Cached/);
687+
userEvent.hover(refreshButton);
688+
expect(await screen.findByText(/Query 1: Cached/)).toBeInTheDocument();
689+
expect(await screen.findByText(/Query 2: Cached/)).toBeInTheDocument();
691690
});
692691

693692

694-
test('Should deduplicate identical cache times in tooltip', () => {
693+
test('Should deduplicate identical cache times in tooltip', async () => {
695694
const sameCachedDttm = '2024-01-28T10:00:00.000Z';
696695
const props = createProps(VizType.Table);
697696
props.isCached = [true, true];
@@ -704,13 +703,11 @@ test('Should deduplicate identical cache times in tooltip', () => {
704703
const refreshButton = screen.getByText('Force refresh');
705704
expect(refreshButton).toBeInTheDocument();
706705

707-
const tooltipContainer = refreshButton.closest('div');
708-
const tooltipText = tooltipContainer?.textContent || '';
709-
expect(tooltipText).toMatch(/Cached/);
710-
expect(tooltipText).not.toMatch(/Query 1:/);
706+
userEvent.hover(refreshButton);
707+
expect(await screen.findByText(/Cached/)).toBeInTheDocument();
711708
});
712709

713-
test('Should handle three or more queries with different cache states', () => {
710+
test('Should handle three or more queries with different cache states', async () => {
714711
const cachedDttm1 = '2024-01-28T10:00:00.000Z';
715712
const cachedDttm2 = '2024-01-28T10:05:00.000Z';
716713
const cachedDttm3 = '';
@@ -726,8 +723,9 @@ test('Should handle three or more queries with different cache states', () => {
726723
const refreshButton = screen.getByText('Force refresh');
727724
expect(refreshButton).toBeInTheDocument();
728725

729-
const tooltipContainer = refreshButton.closest('div');
730-
expect(tooltipContainer?.textContent).toMatch(/Query 1:/);
731-
expect(tooltipContainer?.textContent).toMatch(/Query 2:/);
732-
expect(tooltipContainer?.textContent).toMatch(/Query 3:/);
726+
userEvent.hover(refreshButton);
727+
728+
expect(await screen.findByText(/Query 1:/)).toBeInTheDocument();
729+
expect(await screen.findByText(/Query 2:/)).toBeInTheDocument();
730+
expect(await screen.findByText(/Query 3:/)).toBeInTheDocument();
733731
});

0 commit comments

Comments
 (0)