| | |
| | | await expect(page).toHaveURL(/\/dashboard$/) |
| | | } |
| | | |
| | | async function registerCabinet(page: Page, name: string) { |
| | | await page.goto('/device-cabinet/new') |
| | | interface RegisterDeviceOptions { |
| | | createPath: string |
| | | listPath: RegExp |
| | | nameLabel: string |
| | | name: string |
| | | fillAdditionalFields?: () => Promise<void> |
| | | } |
| | | |
| | | async function registerDevice(page: Page, options: RegisterDeviceOptions) { |
| | | await page.goto(options.createPath) |
| | | await page.getByRole('button', { name: '选择设备' }).click() |
| | | const row = page.locator('.device-table tbody tr').filter({ has: page.getByRole('button', { name: '选择' }) }).first() |
| | | await expect(row).toBeVisible() |
| | | const code = (await row.locator('td').first().textContent())?.trim() || '' |
| | | await row.getByRole('button', { name: '选择' }).click() |
| | | await page.locator('label').filter({ hasText: '检测柜名称' }).locator('input').fill(name) |
| | | await page.locator('label').filter({ hasText: '规格/容量' }).locator('input').fill('120') |
| | | await page.locator('label').filter({ hasText: options.nameLabel }).locator('input').fill(options.name) |
| | | await options.fillAdditionalFields?.() |
| | | await page.getByRole('button', { name: '保存', exact: true }).click() |
| | | await expect(page).toHaveURL(/\/device-cabinet$/) |
| | | await expect(page).toHaveURL(options.listPath) |
| | | await expect(page.locator('tbody tr').filter({ hasText: code })).toBeVisible() |
| | | return code |
| | | } |
| | | |
| | | async function registerCabinet(page: Page, name: string) { |
| | | return registerDevice(page, { |
| | | createPath: '/device-cabinet/new', |
| | | listPath: /\/device-cabinet$/, |
| | | nameLabel: '检测柜名称', |
| | | name, |
| | | fillAdditionalFields: () => page.locator('label').filter({ hasText: '规格/容量' }).locator('input').fill('120'), |
| | | }) |
| | | } |
| | | |
| | | async function registerCollector(page: Page, name: string) { |
| | | await page.goto('/device-collector/new') |
| | | await page.getByRole('button', { name: '选择设备' }).click() |
| | | const row = page.locator('.device-table tbody tr').filter({ has: page.getByRole('button', { name: '选择' }) }).first() |
| | | await expect(row).toBeVisible() |
| | | const code = (await row.locator('td').first().textContent())?.trim() || '' |
| | | await row.getByRole('button', { name: '选择' }).click() |
| | | await page.locator('label').filter({ hasText: '采集器名称' }).locator('input').fill(name) |
| | | await page.getByRole('button', { name: '保存', exact: true }).click() |
| | | await expect(page).toHaveURL(/\/device-collector$/) |
| | | await expect(page.locator('tbody tr').filter({ hasText: code })).toBeVisible() |
| | | return code |
| | | return registerDevice(page, { |
| | | createPath: '/device-collector/new', |
| | | listPath: /\/device-collector$/, |
| | | nameLabel: '采集器名称', |
| | | name, |
| | | }) |
| | | } |
| | | |
| | | async function deleteRegisteredDevice(page: Page, path: string, code: string) { |