index.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import type { Page } from '@playwright/test';
  6. type InsertEdgeOptions = {
  7. from: string;
  8. to: string;
  9. };
  10. class FixedLayoutModel {
  11. private page: Page;
  12. constructor(page: Page) {
  13. this.page = page;
  14. }
  15. public async getNodeCount() {
  16. return await this.page.locator('.gedit-flow-activity-node').count();
  17. }
  18. public async isStartNodeExist() {
  19. return await this.page.locator('[data-node-id="start_0"]').count();
  20. }
  21. public async isEndNodeExist() {
  22. return await this.page.locator('[data-node-id="end_0"]').count();
  23. }
  24. public async isConditionNodeExist() {
  25. return await this.page.locator('[data-node-id="$blockIcon$switch_0"]').count();
  26. }
  27. public async insert(searchText: string, { from, to }: InsertEdgeOptions) {
  28. const preConditionNodes = await this.page.locator('.gedit-flow-activity-node');
  29. const preCount = await preConditionNodes.count();
  30. const element = await this.page.locator(
  31. `[data-testid="sdk.flowcanvas.line.adder"][data-from="${from}"][data-to="${to}"]`
  32. );
  33. await element.waitFor({ state: 'visible' });
  34. await element.scrollIntoViewIfNeeded();
  35. await element.hover({
  36. timeout: 3000,
  37. });
  38. const adder = this.page.locator('.semi-icon-plus_circle');
  39. await adder.waitFor({ state: 'visible', timeout: 3000 });
  40. await adder.scrollIntoViewIfNeeded();
  41. await adder.click();
  42. const nodeItem = await this.page.locator('.semi-popover-content').getByText(searchText);
  43. await nodeItem.click();
  44. await this.page.waitForFunction(
  45. (expectedCount) =>
  46. document.querySelectorAll('.gedit-flow-activity-node').length >= expectedCount,
  47. preCount + 1
  48. );
  49. }
  50. }
  51. export default FixedLayoutModel;