|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +import { BASE_URL, loadTestImage } from './utils' |
| 3 | + |
| 4 | +test.describe('Menu', () => { |
| 5 | + test('displays home screen', async ({ page }) => { |
| 6 | + await page.goto(BASE_URL) |
| 7 | + |
| 8 | + expect(await page.textContent('text=/Home/i')).toBeTruthy() |
| 9 | + expect(await page.textContent('text=/Add Image/i')).toBeTruthy() |
| 10 | + expect(await page.textContent('text=/View/i')).toBeTruthy() |
| 11 | + expect(await page.textContent('text=/Bookmarklet/i')).toBeTruthy() |
| 12 | + expect(await page.textContent('text=/Drop Files to load images/i')).toBeTruthy() |
| 13 | + }) |
| 14 | + |
| 15 | + test('menubar updates with loading images', async ({ page }) => { |
| 16 | + await page.goto(BASE_URL) |
| 17 | + |
| 18 | + // initially only these menu items are visible |
| 19 | + expect(await page.textContent('text=/Home/i')).toBeTruthy() |
| 20 | + expect(await page.textContent('text=/Add Image/i')).toBeTruthy() |
| 21 | + expect(await page.textContent('text=/View/i')).toBeTruthy() |
| 22 | + |
| 23 | + // initially these menu items do not exist |
| 24 | + expect(await page.$('text=/ColorScale/i')).toBeNull() |
| 25 | + expect(await page.$('text=/Overlay/i')).toBeNull() |
| 26 | + expect(await page.$('text=/Header/i')).toBeNull() |
| 27 | + expect(await page.$('text=/Select/i')).toBeNull() |
| 28 | + |
| 29 | + // load an image |
| 30 | + await loadTestImage(page) |
| 31 | + expect(await page.waitForSelector('canvas')).toBeTruthy() |
| 32 | + expect( |
| 33 | + await page.textContent('text=/matrix size: 207 x 256 x 215, voxelsize: 0.74 x 0.74 x 0.74/i'), |
| 34 | + ).toBeTruthy() |
| 35 | + |
| 36 | + // after loading an image these are visible |
| 37 | + expect(await page.textContent('text=/Home/i')).toBeTruthy() |
| 38 | + expect(await page.textContent('text=/Add Image/i')).toBeTruthy() |
| 39 | + expect(await page.textContent('text=/View/i')).toBeTruthy() |
| 40 | + expect(await page.textContent('text=/ColorScale/i')).toBeTruthy() |
| 41 | + expect(await page.textContent('text=/Overlay/i')).toBeTruthy() |
| 42 | + expect(await page.textContent('text=/Header/i')).toBeTruthy() |
| 43 | + |
| 44 | + // the select menu item is only visible after loading 2 images |
| 45 | + expect(await page.$('text=/Select/i')).toBeNull() |
| 46 | + await loadTestImage(page) |
| 47 | + expect(await page.textContent('text=/Select/i')).toBeTruthy() |
| 48 | + }) |
| 49 | + |
| 50 | + test('loads an image and checks the menu bar', async ({ page }) => { |
| 51 | + await page.goto(BASE_URL) |
| 52 | + |
| 53 | + await loadTestImage(page) |
| 54 | + |
| 55 | + expect(await page.waitForSelector('canvas')).toBeTruthy() |
| 56 | + expect(await page.$$('canvas')).toHaveLength(1) |
| 57 | + expect( |
| 58 | + await page.textContent('text=/matrix size: 207 x 256 x 215, voxelsize: 0.74 x 0.74 x 0.74/i'), |
| 59 | + ).toBeTruthy() |
| 60 | + |
| 61 | + const menuBar = ['Home', 'Add Image', 'View', 'ColorScale', 'Overlay', 'Header'] |
| 62 | + for (const item of menuBar) { |
| 63 | + expect(await page.textContent(`text=/${item}/i`)).toBeTruthy() |
| 64 | + } |
| 65 | + }) |
| 66 | + |
| 67 | + test('opens the example image via the menu bar', async ({ page }) => { |
| 68 | + await page.goto(BASE_URL) |
| 69 | + |
| 70 | + await page.click('data-testid=menu-item-dropdown-Add Image') |
| 71 | + await page.click('text=/Example Image/i') |
| 72 | + |
| 73 | + expect(await page.waitForSelector('canvas')).toBeTruthy() |
| 74 | + expect(await page.$$('canvas')).toHaveLength(1) |
| 75 | + expect( |
| 76 | + await page.textContent('text=/matrix size: 207 x 256 x 215, voxelsize: 0.74 x 0.74 x 0.74/i'), |
| 77 | + ).toBeTruthy() |
| 78 | + }) |
| 79 | +}) |
0 commit comments