with-navigation.spec.ts 3.8 KB

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