index.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type { Page } from '@playwright/test';
  2. type InsertEdgeOptions = {
  3. from: string;
  4. to: string;
  5. };
  6. class FixedLayoutModel {
  7. private page: Page;
  8. constructor(page: Page) {
  9. this.page = page;
  10. }
  11. public async getNodeCount() {
  12. return await this.page.locator('.gedit-flow-activity-node').count();
  13. }
  14. public async insert(searchText: string, { from, to }: InsertEdgeOptions) {
  15. const preConditionNodes = await this.page.locator('.gedit-flow-activity-node');
  16. const preCount = await preConditionNodes.count();
  17. const element = await this.page.locator(
  18. `[data-testid="sdk.flowcanvas.line.adder"][data-from="${from}"][data-to="${to}"]`
  19. );
  20. await element.waitFor({ state: 'visible' });
  21. await element.scrollIntoViewIfNeeded();
  22. await element.hover({
  23. timeout: 3000,
  24. });
  25. const adder = this.page.locator('.semi-icon-plus_circle');
  26. await adder.waitFor({ state: 'visible', timeout: 3000 });
  27. await adder.scrollIntoViewIfNeeded();
  28. await adder.click();
  29. const nodeItem = await this.page.locator('.semi-popover-content').getByText(searchText);
  30. await nodeItem.click();
  31. await this.page.waitForFunction(
  32. (expectedCount) =>
  33. document.querySelectorAll('.gedit-flow-activity-node').length >= expectedCount,
  34. preCount + 1
  35. );
  36. }
  37. }
  38. export default FixedLayoutModel;