Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add E2E tests for toolbar zoom controls #697

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions frontend/packages/e2e/tests/e2e/toolbar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect, test } from '@playwright/test'

test.beforeEach(async ({ page }) => {
await page.goto('/')
const cookieButton = page.getByRole('button', {
name: 'Accept All Cookies',
})
await cookieButton.click({ timeout: 3000, force: true }).catch(() => {})
})

test.describe('Desktop Toolbar', () => {
test('should be visible', async ({ page }) => {
const toolbar = page.getByRole('toolbar', { name: 'Toolbar' })
await expect(toolbar).toBeVisible()
})

test('zoom in button should increase zoom level', async ({ page }) => {
const toolbar = page.getByRole('toolbar', { name: 'Toolbar' })
const zoomLevelText = toolbar.locator('span[class*="zoomLevelText"]')

const zoomLevelBefore = await zoomLevelText.textContent()

const zoomInButton = toolbar.getByRole('button', { name: 'Zoom in' })
await zoomInButton.click()

const zoomLevelAfter = await zoomLevelText.textContent()
expect(Number.parseInt(zoomLevelBefore)).toBeLessThan(
Number.parseInt(zoomLevelAfter),
)
})

test('zoom out button should decrease zoom level', async ({ page }) => {
const toolbar = page.getByRole('toolbar', { name: 'Toolbar' })
const zoomLevelText = toolbar.locator('span[class*="zoomLevelText"]')

const zoomLevelBefore = await zoomLevelText.textContent()

const zoomOutButton = toolbar.getByRole('button', { name: 'Zoom out' })
await zoomOutButton.click()

const zoomLevelAfter = await zoomLevelText.textContent()
expect(Number.parseInt(zoomLevelBefore)).toBeGreaterThan(
Number.parseInt(zoomLevelAfter),
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ZoomControls } from './ZoomControls'

export const DesktopToolbar: FC = () => {
return (
<ToolbarPrimitive.Root className={styles.root}>
<ToolbarPrimitive.Root className={styles.root} aria-label="Toolbar">
<ZoomControls />
<ToolbarPrimitive.Separator className={styles.separator} />
<div className={styles.buttons}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const MobileToolbar: FC = () => {
[styles.open]: isOpen && !isShowModeMenu,
[styles.openShowModeMenu]: isOpen && isShowModeMenu,
})}
aria-label="Toolbar"
>
<div className={styles.positionRelative}>
{/* Default(closed) */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ export const ZoomControls: FC = () => {
return (
<div className={styles.wrapper}>
<ToolbarButton asChild onClick={handleClickZoomOut}>
<IconButton icon={<Minus />} tooltipContent="Zoom Out" />
<IconButton
icon={<Minus />}
tooltipContent="Zoom Out"
aria-label="Zoom out"
/>
</ToolbarButton>
<span className={styles.zoomLevelText}>
{Math.floor(zoomLevel * 100)}%
</span>
<ToolbarButton asChild onClick={handleClickZoomIn}>
<IconButton icon={<Plus />} tooltipContent="Zoom In" />
<IconButton
icon={<Plus />}
tooltipContent="Zoom In"
aria-label="Zoom in"
/>
</ToolbarButton>
</div>
)
Expand Down