with-navigation.spec.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { expect, type Page, test } from '@playwright/test';
  2. import { readFileSync } from 'fs';
  3. import path from 'path';
  4. /**
  5. * for the issues:
  6. * @see https://redmine.weseek.co.jp/issues/122040
  7. * @see https://redmine.weseek.co.jp/issues/124281
  8. */
  9. test('should not be cleared and should prevent GrantSelector from modified', async ({
  10. page,
  11. }) => {
  12. await page.goto('/Sandbox/for-122040');
  13. // Open Editor
  14. await page.getByTestId('editor-button').click();
  15. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  16. // Open GrantSelector and select "only me"
  17. await page.getByTestId('grw-grant-selector').click();
  18. const dropdownMenu = page.getByTestId('grw-grant-selector-dropdown-menu');
  19. await expect(dropdownMenu).toBeVisible();
  20. await dropdownMenu.locator('.dropdown-item').nth(2).click();
  21. await expect(page.getByTestId('grw-grant-selector')).toContainText('Only me');
  22. // Upload attachment
  23. const filePath = path.resolve(__dirname, '../23-editor/assets/example.txt');
  24. const buffer = readFileSync(filePath).toString('base64');
  25. const dataTransfer = await page.evaluateHandle(
  26. async ({ bufferData, localFileName, localFileType }) => {
  27. const dt = new DataTransfer();
  28. const blobData = await fetch(bufferData).then((res) => res.blob());
  29. const file = new File([blobData], localFileName, {
  30. type: localFileType,
  31. });
  32. dt.items.add(file);
  33. return dt;
  34. },
  35. {
  36. bufferData: `data:application/octet-stream;base64,${buffer}`,
  37. localFileName: 'sample.tst',
  38. localFileType: 'application/octet-stream',
  39. },
  40. );
  41. await page
  42. .locator('.dropzone')
  43. .first()
  44. .dispatchEvent('drop', { dataTransfer });
  45. await expect(
  46. page.getByTestId('page-editor-preview-body').getByTestId('rich-attachment'),
  47. ).toBeVisible();
  48. // Save page
  49. await page.getByTestId('save-page-btn').click();
  50. // Expect grant not to be reset after uploading an attachment
  51. await expect(page.getByTestId('page-grant-alert')).toContainText(
  52. 'Browsing of this page is restricted',
  53. );
  54. });
  55. const appendTextToEditorUntilContains = async (page: Page, text: string) => {
  56. await page.locator('.cm-content').fill(text);
  57. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  58. text,
  59. );
  60. };
  61. /**
  62. * for the issue:
  63. * @see https://redmine.weseek.co.jp/issues/115285
  64. */
  65. test('Successfully updating the page body', async ({ page }) => {
  66. const page1Path = '/Sandbox/for-115285/page1';
  67. const page2Path = '/Sandbox/for-115285/page2';
  68. const page1Body = 'Hello';
  69. const page2Body = 'World';
  70. await page.goto(page1Path);
  71. // Open Editor (page1)
  72. await page.getByTestId('editor-button').click();
  73. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  74. // Append text
  75. await appendTextToEditorUntilContains(page, page1Body);
  76. // Save page
  77. await page.getByTestId('save-page-btn').click();
  78. await expect(page.locator('.main')).toContainText(page1Body);
  79. // Duplicate page1
  80. await page
  81. .getByTestId('grw-contextual-sub-nav')
  82. .getByTestId('open-page-item-control-btn')
  83. .click();
  84. await page.getByTestId('open-page-duplicate-modal-btn').click();
  85. await expect(page.getByTestId('page-duplicate-modal')).toBeVisible();
  86. await page.locator('.form-control').fill(page2Path);
  87. await page.getByTestId('btn-duplicate').click();
  88. // Open Editor (page2)
  89. await page.getByTestId('editor-button').click();
  90. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  91. // Expect to see the text from which you are duplicating
  92. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  93. page1Body,
  94. );
  95. // Append text
  96. await appendTextToEditorUntilContains(page, page1Body + page2Body);
  97. await page.goto(page1Path);
  98. // Open Editor (page1)
  99. await page.getByTestId('editor-button').click();
  100. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  101. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  102. page1Body,
  103. );
  104. });