节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
2.95 KiB
Stardust
import { test, expect } from './fixtures';
import { gotoLeafPage, assertPageRendered, collectErrors } from './helpers';

/**
 * Configs/ConfigData/Index 迁移 e2e(TDD)
 *
 * 自定义逻辑(配置数据版本管理):
 *  - 用版本只读 / 待发布版本可改(Version>0 在用只读,NewVersion>0 待发布可改)
 *  - 列表含自定义操作列:行级「发布」(NewVersion>Version 即可用,否则 disabled)
 *  - 工具栏「发布新版」:当存在待发布版本(NewVersion>Version)时显示,POST /Configs/ConfigData/Publish
 *  - 自定义 Add:新增配置数据,OnInsert 自动赋值 NewVersion
 *  - 后端 API:GET /api/Configs/ConfigData、POST /api/Configs/ConfigData/Publish(均已存在)
 *
 * 种子数据为空时列表 0 行属正常,仅校验:渲染 + 自定义操作列/按钮存在 + 无 >=400 错误。
 */
test('Configs/ConfigData 页面渲染(列表 + 版本管理自定义操作列)', async ({ page }) => {
  const errs = collectErrors(page);
  await gotoLeafPage(page, 'Configs/ConfigData');
  const rendered = await assertPageRendered(page);
  expect(rendered).toBe('list');

  // 列表与表格必须渲染
  await expect(page.locator('main.cosmic-content .list-page')).toBeVisible();
  await expect(page.locator('main.cosmic-content .el-table').first()).toBeVisible();

  // 版本管理自定义操作列:行级「发布」按钮必须存在(始终渲染 + disabled 控制)
  await expect(
    page.locator('main.cosmic-content').getByRole('button', { name: '发布' }).first(),
  ).toBeVisible();

  // 工具栏「发布新版」(批处理 Publish)按钮必须存在
  await expect(
    page.locator('main.cosmic-content').getByRole('button', { name: '发布新版' }).first(),
  ).toBeVisible();

  const captured = await errs;
  if (captured.errors.length) {
    console.log('NET_ERR=' + JSON.stringify(captured.errors));
    throw new Error('存在接口/资源 >=400 错误: ' + JSON.stringify(captured.errors));
  }

  // 截图 1:列表态(主交付物)
  await page.screenshot({
    path: 'e2e/screenshots/Configs/ConfigData/list.png',
    fullPage: true,
  });

  // 截图 2:触发工具栏「发布新版」后态(验证自定义 Action 连通)
  // 空种子时无待发布版本,该按钮 disabled,click 短超时后跳过(不影响交付截图)
  try {
    await page
      .locator('main.cosmic-content')
      .getByRole('button', { name: '发布新版' })
      .first()
      .click({ timeout: 3000 });
    await page.waitForTimeout(800);
    await page.screenshot({
      path: 'e2e/screenshots/Configs/ConfigData/after-publish.png',
      fullPage: true,
    });
  } catch (e) {
    console.log('PUBLISH_CLICK_SKIPPED=' + String(e));
    // 空数据下按钮 disabled,补一张当前列表态截图作为动作后态
    await page.screenshot({
      path: 'e2e/screenshots/Configs/ConfigData/after-publish.png',
      fullPage: true,
    });
  }

  expect(true).toBe(true);
});