From f68ec14f796fff29f62ad022fe538de2dc251f8f Mon Sep 17 00:00:00 2001
From: Marco Ciampini
Page 2
}, + { content:Page 3
}, + { content:Page 4
}, + ] } + /> + ); + const listContainer = screen.getByRole( 'list', { + name: 'Guide controls', + } ); + expect( + within( listContainer ).getAllByRole( 'button', { + name: /page \d of \d/i, + } ) + ).toHaveLength( 4 ); + } ); + + it( 'sets the current page when a button is clicked', async () => { + const user = userEvent.setup( { + advanceTimers: jest.advanceTimersByTime, + } ); + + render( +Page 2
}, + { content:Page 3
}, + ] } + /> + ); + + expect( screen.getByText( 'Page 1' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.click( + screen.getByRole( 'button', { name: 'Page 2 of 3' } ) + ); + + expect( screen.getByText( 'Page 2' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.click( + screen.getByRole( 'button', { name: 'Page 3 of 3' } ) + ); + + expect( screen.getByText( 'Page 3' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + + await user.click( + screen.getByRole( 'button', { name: 'Page 1 of 3' } ) + ); + + expect( screen.getByText( 'Page 1' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + } ); + + it( 'allows navigating through the pages with the left and right arrows', async () => { + const user = userEvent.setup( { + advanceTimers: jest.advanceTimersByTime, + } ); + + render( +Page 2
}, + { content:Page 3
}, + ] } + /> + ); + + expect( screen.getByText( 'Page 1' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowLeft]' ); + + expect( screen.getByText( 'Page 1' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowRight]' ); + + expect( screen.getByText( 'Page 2' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowRight]' ); + + expect( screen.getByText( 'Page 3' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowRight]' ); + + expect( screen.getByText( 'Page 3' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowLeft]' ); + + expect( screen.getByText( 'Page 2' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 1' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + + await user.keyboard( '[ArrowLeft]' ); + + expect( screen.getByText( 'Page 1' ) ).toBeVisible(); + expect( screen.queryByText( 'Page 2' ) ).not.toBeInTheDocument(); + expect( screen.queryByText( 'Page 3' ) ).not.toBeInTheDocument(); + } ); + } ); } ); diff --git a/packages/components/src/guide/test/page-control.js b/packages/components/src/guide/test/page-control.js deleted file mode 100644 index caeb3dd005476a..00000000000000 --- a/packages/components/src/guide/test/page-control.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * External dependencies - */ -import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; - -/** - * Internal dependencies - */ -import PageControl from '../page-control'; - -describe( 'PageControl', () => { - it( 'renders an empty list when there are no pages', () => { - render(