index.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. import type { DragPosition } from '../typings/index';
  7. type InsertEdgeOptions = {
  8. from: string;
  9. to: string;
  10. };
  11. class FixedLayoutModel {
  12. private page: Page;
  13. constructor(page: Page) {
  14. this.page = page;
  15. }
  16. public async getNodeCount() {
  17. return await this.page.locator('.gedit-flow-activity-node').count();
  18. }
  19. public async isStartNodeExist() {
  20. return await this.page.locator('[data-node-id="start_0"]').count();
  21. }
  22. public async isEndNodeExist() {
  23. return await this.page.locator('[data-node-id="end_0"]').count();
  24. }
  25. public async isConditionNodeExist() {
  26. return await this.page.locator('[data-node-id="$blockIcon$switch_0"]').count();
  27. }
  28. public async drag(from: DragPosition, to: DragPosition) {
  29. await this.page.mouse.move(from.x, from.y);
  30. await this.page.mouse.down();
  31. await this.page.mouse.move(to.x, to.y);
  32. await this.page.mouse.up();
  33. }
  34. public async insert(searchText: string, { from, to }: InsertEdgeOptions) {
  35. const preConditionNodes = await this.page.locator('.gedit-flow-activity-node');
  36. const preCount = await preConditionNodes.count();
  37. const element = await this.page.locator(
  38. `[data-testid="sdk.flowcanvas.line.adder"][data-from="${from}"][data-to="${to}"]`
  39. );
  40. await element.waitFor({ state: 'visible' });
  41. await element.scrollIntoViewIfNeeded();
  42. await element.hover({
  43. timeout: 3000,
  44. });
  45. const adder = this.page.locator('.semi-icon-plus_circle');
  46. await adder.waitFor({ state: 'visible', timeout: 3000 });
  47. await adder.scrollIntoViewIfNeeded();
  48. await adder.click();
  49. const nodeItem = await this.page.locator('.semi-popover-content').getByText(searchText);
  50. await nodeItem.click();
  51. await this.page.waitForFunction(
  52. (expectedCount) =>
  53. document.querySelectorAll('.gedit-flow-activity-node').length >= expectedCount,
  54. preCount + 1
  55. );
  56. }
  57. }
  58. export default FixedLayoutModel;