use-tools.spec.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { test, expect, type Page } from '@playwright/test';
  2. const openPageItemControl = async(page: Page): Promise<void> => {
  3. const nav = page.getByTestId('grw-contextual-sub-nav');
  4. const button = nav.getByTestId('open-page-item-control-btn');
  5. // Wait for navigation element to be visible and attached
  6. await expect(nav).toBeVisible();
  7. await nav.waitFor({ state: 'visible' });
  8. // Wait for button to be visible, enabled and attached
  9. await expect(button).toBeVisible();
  10. await expect(button).toBeEnabled();
  11. await button.waitFor({ state: 'visible' });
  12. // Add a small delay to ensure the button is fully interactive
  13. await page.waitForTimeout(100);
  14. await button.click();
  15. };
  16. const openPutBackPageModal = async(page: Page): Promise<void> => {
  17. const alert = page.getByTestId('trash-page-alert');
  18. const button = alert.getByTestId('put-back-button');
  19. // Wait for alert element to be visible and attached
  20. await expect(alert).toBeVisible();
  21. // Wait for button to be actionable
  22. await expect(button).toBeInViewport(); // Ensures it's visible within the viewport
  23. await expect(button).toBeEnabled(); // Ensures it's not disabled
  24. // Click the button. Playwright's click action automatically waits for the element
  25. // to be actionable (visible, stable, enabled, unobscured).
  26. // Retry clicking the button until the modal is visible or retries are exhausted
  27. for (let i = 0; i < 5; i++) {
  28. // eslint-disable-next-line no-await-in-loop
  29. await button.click({ force: true });
  30. try {
  31. // Wait for a short period to see if the modal appears
  32. // eslint-disable-next-line no-await-in-loop
  33. await page.waitForSelector('[data-testid="put-back-page-modal"]', { state: 'visible', timeout: 500 });
  34. break; // Modal appeared, exit loop
  35. }
  36. catch (error) {
  37. // Modal did not appear, wait a bit before retrying
  38. if (i < 4) { // Don't wait after the last attempt
  39. // eslint-disable-next-line no-await-in-loop
  40. await page.waitForTimeout(1000);
  41. }
  42. }
  43. }
  44. // Assert that the modal is visible after retries
  45. await expect(page.getByTestId('put-back-page-modal')).toBeVisible();
  46. };
  47. test('Page Deletion and PutBack is executed successfully', async({ page }) => {
  48. await page.goto('/Sandbox/Bootstrap5');
  49. // Delete
  50. await openPageItemControl(page);
  51. await page.getByTestId('open-page-delete-modal-btn').click();
  52. await expect(page.getByTestId('page-delete-modal')).toBeVisible();
  53. await page.getByTestId('delete-page-button').click();
  54. // PutBack
  55. await openPutBackPageModal(page);
  56. await page.getByTestId('put-back-execution-button').click();
  57. await expect(page.getByTestId('trash-page-alert')).not.toBeVisible();
  58. });
  59. test('PageDuplicateModal is shown successfully', async({ page }) => {
  60. await page.goto('/Sandbox');
  61. await openPageItemControl(page);
  62. await page.getByTestId('open-page-duplicate-modal-btn').click();
  63. await expect(page.getByTestId('page-duplicate-modal')).toBeVisible();
  64. });
  65. test('PageMoveRenameModal is shown successfully', async({ page }) => {
  66. await page.goto('/Sandbox');
  67. await openPageItemControl(page);
  68. await page.getByTestId('rename-page-btn').click();
  69. await expect(page.getByTestId('page-rename-modal')).toBeVisible();
  70. });
  71. // TODO: Uncomment after https://redmine.weseek.co.jp/issues/149786
  72. // test('PresentationModal for "/" is shown successfully', async({ page }) => {
  73. // await page.goto('/');
  74. // await openPageItemControl(page);
  75. // await page.getByTestId('open-presentation-modal-btn').click();
  76. // expect(page.getByTestId('page-presentation-modal')).toBeVisible();
  77. // });
  78. test.describe('Page Accessories Modal', () => {
  79. test.beforeEach(async({ page }) => {
  80. await page.goto('/');
  81. await openPageItemControl(page);
  82. });
  83. test('Page History is shown successfully', async({ page }) => {
  84. await page.getByTestId('open-page-accessories-modal-btn-with-history-tab').click();
  85. await expect(page.getByTestId(('page-history'))).toBeVisible();
  86. });
  87. test('Page Attachment Data is shown successfully', async({ page }) => {
  88. await page.getByTestId('open-page-accessories-modal-btn-with-attachment-data-tab').click();
  89. await expect(page.getByTestId('page-attachment')).toBeVisible();
  90. });
  91. test('Share Link Management is shown successfully', async({ page }) => {
  92. await page.getByTestId('open-page-accessories-modal-btn-with-share-link-management-data-tab').click();
  93. await expect(page.getByTestId('share-link-management')).toBeVisible();
  94. });
  95. });
  96. test('Successfully add new tag', async({ page }) => {
  97. const tag = 'we';
  98. await page.goto('/Sandbox/Bootstrap5');
  99. await page.locator('#edit-tags-btn-wrapper-for-tooltip').click();
  100. await expect(page.locator('#edit-tag-modal')).toBeVisible();
  101. await page.locator('.rbt-input-main').fill(tag);
  102. await expect(page.locator('#tag-typeahead-asynctypeahead-item-0')).toBeVisible();
  103. await page.locator('#tag-typeahead-asynctypeahead-item-0').click();
  104. await page.getByTestId('tag-edit-done-btn').click();
  105. await expect(page.getByTestId('grw-tag-labels')).toContainText(tag);
  106. });