|
| 1 | +// npx playwright test asset-selection.spec.ts --debug |
| 2 | + |
| 3 | +import { test, expect } from '@playwright/test' |
| 4 | +import * as Utils from '../utils' |
| 5 | +import { STATE_AFTER_UPLOAD } from '../assetStates' |
| 6 | + |
| 7 | +test('asset selection', async ({ page }, testinfo) => { |
| 8 | + if (process.env.CI) { |
| 9 | + test.skip() |
| 10 | + return |
| 11 | + } |
| 12 | + testinfo.snapshotSuffix = '' // by default is `process.platform` |
| 13 | + const canvas = page.locator('canvas') |
| 14 | + const assetIdEl = page.locator('#selected-asset-id') |
| 15 | + |
| 16 | + const expectLastUpdate = await Utils.init(page) |
| 17 | + |
| 18 | + await expectLastUpdate(0, null) |
| 19 | + |
| 20 | + await Utils.uploadAsset(page) |
| 21 | + |
| 22 | + await page.waitForTimeout(1000) // wait for the upload to happen |
| 23 | + await expectLastUpdate(1, STATE_AFTER_UPLOAD) |
| 24 | + |
| 25 | + // no selected by default |
| 26 | + await expect(assetIdEl).toHaveText('0') |
| 27 | + |
| 28 | + // no selection after jsut hovering |
| 29 | + await page.mouse.move(550, 275) |
| 30 | + await page.waitForTimeout(100) // wait for the final result to test not-happy path |
| 31 | + await expect(assetIdEl).toHaveText('0') |
| 32 | + |
| 33 | + // hover shouldn't trigger asset update |
| 34 | + await expectLastUpdate(1, STATE_AFTER_UPLOAD) |
| 35 | + |
| 36 | + // update once selection happens |
| 37 | + await page.mouse.move(550, 275) |
| 38 | + await page.mouse.down() |
| 39 | + await page.mouse.up() |
| 40 | + await expect(canvas).toHaveScreenshot('select-image.png') |
| 41 | + await expect(assetIdEl).toHaveText('1000') |
| 42 | + await expectLastUpdate(2, STATE_AFTER_UPLOAD) |
| 43 | + |
| 44 | + // update once selections is lost |
| 45 | + await page.mouse.move(100, 275) |
| 46 | + await page.mouse.down() |
| 47 | + await page.mouse.up() |
| 48 | + await expect(assetIdEl).toHaveText('0') |
| 49 | + |
| 50 | + // loosing selection shouldn't trigger asset update |
| 51 | + await expectLastUpdate(3, STATE_AFTER_UPLOAD) |
| 52 | +}) |
0 commit comments