gdpr.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { expect } from "../setup";
  2. import { generateDescription } from "../utils/faker";
  3. export async function enableGDPR(adminPage) {
  4. /**
  5. * Navigating to the gdpr configuration page.
  6. */
  7. await adminPage.goto("admin/configuration/general/gdpr");
  8. const isEnabled = adminPage.locator("label > div").first().check();
  9. /**
  10. * If not enabled, then we enable it.
  11. */
  12. if (!isEnabled) {
  13. const gdprsettingToggle = adminPage.locator("label > div").first();
  14. await gdprsettingToggle.waitFor({ state: "visible", timeout: 5000 });
  15. await adminPage.locator("label > div").first().click();
  16. }
  17. /**
  18. * Verifying enable state.
  19. */
  20. const toggleInput = adminPage.locator("label > div").first();
  21. await expect(toggleInput).toBeChecked();
  22. /**
  23. * Click the 'Save Configuration' button.
  24. */
  25. await adminPage.getByRole("button", { name: "Save Configuration" }).click();
  26. }
  27. export async function disableGDPR(adminPage) {
  28. /**
  29. * Navigating to the gdpr configuration page.
  30. */
  31. await adminPage.goto("admin/configuration/general/gdpr");
  32. const isDisabled = adminPage.locator("label > div").first().uncheck();
  33. /**
  34. * If not disabled, then we disable it.
  35. */
  36. if (!isDisabled) {
  37. const gdprsettingToggle = adminPage.locator("label > div").first();
  38. await gdprsettingToggle.waitFor({ state: "visible", timeout: 5000 });
  39. await adminPage.locator("label > div").first().click();
  40. }
  41. /**
  42. * Verifying disable state.
  43. */
  44. const toggleInput = adminPage.locator("label > div").first();
  45. await expect(toggleInput).not.toBeChecked();
  46. /**
  47. * Click the 'Save Configuration' button.
  48. */
  49. await adminPage.getByRole("button", { name: "Save Configuration" }).click();
  50. }
  51. export async function enableGDPRAgreement(adminPage) {
  52. const agreement = {
  53. checkboxLabel: "I agree with this statement.",
  54. content: generateDescription(),
  55. };
  56. /**
  57. * Navigating to the gdpr configuration page.
  58. */
  59. await adminPage.goto("admin/configuration/general/gdpr");
  60. const isEnabled = adminPage
  61. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  62. .first()
  63. .check();
  64. /**
  65. * If not enabled, then we enable it.
  66. */
  67. if (!isEnabled) {
  68. const gdprsettingToggle = adminPage
  69. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  70. .first();
  71. await gdprsettingToggle.waitFor({ state: "visible", timeout: 5000 });
  72. await adminPage
  73. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  74. .first()
  75. .click();
  76. }
  77. /**
  78. * Verifying enable state.
  79. */
  80. const toggleInput = adminPage
  81. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  82. .first();
  83. await expect(toggleInput).toBeChecked();
  84. /**
  85. * Fill the agreement checkbox label.
  86. */
  87. await adminPage
  88. .getByRole("textbox", { name: "Agreement Checkbox Label" })
  89. .click();
  90. await adminPage
  91. .getByRole("textbox", {
  92. name: "Agreement Checkbox Label",
  93. })
  94. .fill(agreement.checkboxLabel);
  95. await adminPage.click('button[type="submit"].primary-button:visible');
  96. /**
  97. * Fill the agreement content.
  98. */
  99. await adminPage.waitForSelector('#general_gdpr__agreement__agreement_content__ifr', { state: 'visible' });
  100. await adminPage.frameLocator('#general_gdpr__agreement__agreement_content__ifr').locator('body').clear();
  101. await adminPage.fillInTinymce(
  102. "#general_gdpr__agreement__agreement_content__ifr",
  103. agreement.content
  104. );
  105. /**
  106. * Save the configuration.
  107. */
  108. await adminPage.click('button[type="submit"].primary-button:visible');
  109. return agreement;
  110. }
  111. export async function disableGDPRAgreement(adminPage) {
  112. /**
  113. * Navigating to the gdpr configuration page.
  114. */
  115. await adminPage.goto("admin/configuration/general/gdpr");
  116. const isDisabled = adminPage
  117. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  118. .first()
  119. .uncheck();
  120. /**
  121. * If not disabled, then we disable it.
  122. */
  123. if (!isDisabled) {
  124. const gdprsettingToggle = adminPage
  125. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  126. .first();
  127. await gdprsettingToggle.waitFor({ state: "visible", timeout: 5000 });
  128. await adminPage
  129. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  130. .first()
  131. .click();
  132. }
  133. /**
  134. * Verifying disable state.
  135. */
  136. const toggleInput = adminPage
  137. .locator("div:nth-child(4) > div > .mb-4 > .relative > div")
  138. .first();
  139. await expect(toggleInput).not.toBeChecked();
  140. /**
  141. * Click the 'Save Configuration' button.
  142. */
  143. await adminPage.getByRole("button", { name: "Save Configuration" }).click();
  144. }
  145. export async function enableCookiesNotice(adminPage, position = "bottom-left") {
  146. /**
  147. * Navigating to the gdpr configuration page.
  148. */
  149. await adminPage.goto("admin/configuration/general/gdpr");
  150. const isEnabled = adminPage
  151. .locator("div:nth-child(6) > div > .mb-4 > .relative > div")
  152. .check();
  153. /**
  154. * If not enabled, then we enable it.
  155. */
  156. if (!isEnabled) {
  157. const gdprsettingToggle = adminPage.locator(
  158. "div:nth-child(6) > div > .mb-4 > .relative > div"
  159. );
  160. await gdprsettingToggle.waitFor({ state: "visible", timeout: 5000 });
  161. await adminPage
  162. .locator("div:nth-child(6) > div > .mb-4 > .relative > div")
  163. .click();
  164. }
  165. /**
  166. * Verifying enable state.
  167. */
  168. const toggleInput = adminPage.locator(
  169. "div:nth-child(6) > div > .mb-4 > .relative > div"
  170. );
  171. await expect(toggleInput).toBeChecked();
  172. await adminPage
  173. .locator('select[name="general[gdpr][cookie][position]"]')
  174. .selectOption(position);
  175. await adminPage
  176. .getByRole("textbox", {
  177. name: "Static Block Identifier",
  178. })
  179. .fill("cookie block");
  180. await adminPage
  181. .getByRole("textbox", {
  182. name: "Description",
  183. })
  184. .fill("this website uses cookies to ensure you");
  185. /**
  186. * Save the configuration.
  187. */
  188. await adminPage.click('button[type="submit"].primary-button:visible');
  189. }