2024-06-28 08:17:11 +03:00
// @ts-check
import { test , expect } from '@playwright/test' ;
import { login _user , load _logged _in _context } from './utils_e2e.js' ;
test . beforeAll ( async ( { browser } , workerInfo ) => {
await login _user ( browser , workerInfo , 'user2' ) ;
} ) ;
2024-07-06 08:30:58 +03:00
const workflow _trigger _notification _text = 'This workflow has a workflow_dispatch event trigger.' ;
2024-06-28 08:17:11 +03:00
test ( 'Test workflow dispatch present' , async ( { browser } , workerInfo ) => {
const context = await load _logged _in _context ( browser , workerInfo , 'user2' ) ;
/** @type {import('@playwright/test').Page} */
const page = await context . newPage ( ) ;
await page . goto ( '/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0' ) ;
2024-07-06 08:30:58 +03:00
await expect ( page . getByText ( workflow _trigger _notification _text ) ) . toBeVisible ( ) ;
2024-06-28 08:17:11 +03:00
const run _workflow _btn = page . locator ( '#workflow_dispatch_dropdown>button' ) ;
await expect ( run _workflow _btn ) . toBeVisible ( ) ;
const menu = page . locator ( '#workflow_dispatch_dropdown>.menu' ) ;
await expect ( menu ) . toBeHidden ( ) ;
await run _workflow _btn . click ( ) ;
await expect ( menu ) . toBeVisible ( ) ;
} ) ;
test ( 'Test workflow dispatch error: missing inputs' , async ( { browser } , workerInfo ) => {
test . skip ( workerInfo . project . name === 'Mobile Safari' , 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383' ) ;
const context = await load _logged _in _context ( browser , workerInfo , 'user2' ) ;
/** @type {import('@playwright/test').Page} */
const page = await context . newPage ( ) ;
await page . goto ( '/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0' ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await page . locator ( '#workflow_dispatch_dropdown>button' ) . click ( ) ;
await page . waitForTimeout ( 1000 ) ;
// Remove the required attribute so we can trigger the error message!
await page . evaluate ( ( ) => {
// eslint-disable-next-line no-undef
const elem = document . querySelector ( 'input[name="inputs[string2]"]' ) ;
elem ? . removeAttribute ( 'required' ) ;
} ) ;
await page . locator ( '#workflow-dispatch-submit' ) . click ( ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await expect ( page . getByText ( 'Require value for input "String w/o. default".' ) ) . toBeVisible ( ) ;
} ) ;
test ( 'Test workflow dispatch success' , async ( { browser } , workerInfo ) => {
test . skip ( workerInfo . project . name === 'Mobile Safari' , 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383' ) ;
const context = await load _logged _in _context ( browser , workerInfo , 'user2' ) ;
/** @type {import('@playwright/test').Page} */
const page = await context . newPage ( ) ;
await page . goto ( '/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0' ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await page . locator ( '#workflow_dispatch_dropdown>button' ) . click ( ) ;
await page . waitForTimeout ( 1000 ) ;
await page . type ( 'input[name="inputs[string2]"]' , 'abc' ) ;
await page . locator ( '#workflow-dispatch-submit' ) . click ( ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await expect ( page . getByText ( 'Workflow run was successfully requested.' ) ) . toBeVisible ( ) ;
await expect ( page . locator ( '.run-list>:first-child .run-list-meta' , { hasText : 'now' } ) ) . toBeVisible ( ) ;
} ) ;
2024-07-06 08:30:58 +03:00
test ( 'Test workflow dispatch box not available for unauthenticated users' , async ( { page } ) => {
await page . goto ( '/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0' ) ;
await page . waitForLoadState ( 'networkidle' ) ;
await expect ( page . locator ( 'body' ) ) . not . toContainText ( workflow _trigger _notification _text ) ;
} ) ;