with-navigation.spec.ts 3.9 KB

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