You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IssuesAppGuide-it.tsx 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import userEvent from '@testing-library/user-event';
  21. import React from 'react';
  22. import { mockCurrentUser } from '../../../helpers/testMocks';
  23. import { NoticeType } from '../../../types/users';
  24. import {
  25. branchHandler,
  26. componentsHandler,
  27. issuesHandler,
  28. renderIssueApp,
  29. renderProjectIssuesApp,
  30. ui,
  31. usersHandler,
  32. } from '../test-utils';
  33. jest.mock('../sidebar/Sidebar', () => {
  34. const fakeSidebar = () => {
  35. return <div data-guiding-id="issue-5" />;
  36. };
  37. return {
  38. __esModule: true,
  39. default: fakeSidebar,
  40. Sidebar: fakeSidebar,
  41. };
  42. });
  43. jest.mock('../../../components/common/ScreenPositionHelper', () => ({
  44. __esModule: true,
  45. default: class ScreenPositionHelper extends React.Component<{
  46. children: (args: { top: number }) => React.ReactNode;
  47. }> {
  48. render() {
  49. // eslint-disable-next-line testing-library/no-node-access
  50. return this.props.children({ top: 10 });
  51. }
  52. },
  53. }));
  54. beforeEach(() => {
  55. issuesHandler.reset();
  56. componentsHandler.reset();
  57. branchHandler.reset();
  58. usersHandler.reset();
  59. window.scrollTo = jest.fn();
  60. window.HTMLElement.prototype.scrollTo = jest.fn();
  61. });
  62. it('should display guide', async () => {
  63. const user = userEvent.setup();
  64. renderIssueApp(
  65. mockCurrentUser({
  66. isLoggedIn: true,
  67. dismissedNotices: { [NoticeType.ISSUE_NEW_STATUS_AND_TRANSITION_GUIDE]: true },
  68. }),
  69. );
  70. expect(await ui.guidePopup.find()).toBeInTheDocument();
  71. expect(await ui.guidePopup.find()).toBeInTheDocument();
  72. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.1.title');
  73. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.1.content');
  74. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.1.5');
  75. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  76. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.2.title');
  77. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.2.content');
  78. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.2.5');
  79. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  80. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.3.title');
  81. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.3.content');
  82. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.3.5');
  83. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  84. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.4.title');
  85. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.4.content');
  86. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.4.5');
  87. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  88. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.5.title');
  89. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.5.content');
  90. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.5.5');
  91. expect(ui.guidePopup.byRole('button', { name: 'Next' }).query()).not.toBeInTheDocument();
  92. await user.click(ui.guidePopup.byRole('button', { name: 'close' }).get());
  93. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  94. });
  95. it('should not show guide for those who dismissed it', async () => {
  96. renderIssueApp(
  97. mockCurrentUser({
  98. isLoggedIn: true,
  99. dismissedNotices: {
  100. [NoticeType.ISSUE_GUIDE]: true,
  101. [NoticeType.ISSUE_NEW_STATUS_AND_TRANSITION_GUIDE]: true,
  102. },
  103. }),
  104. );
  105. expect((await ui.issueItems.findAll()).length).toBeGreaterThan(0);
  106. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  107. });
  108. it('should skip guide', async () => {
  109. const user = userEvent.setup();
  110. renderIssueApp(
  111. mockCurrentUser({
  112. isLoggedIn: true,
  113. dismissedNotices: { [NoticeType.ISSUE_NEW_STATUS_AND_TRANSITION_GUIDE]: true },
  114. }),
  115. );
  116. expect(await ui.guidePopup.find()).toBeInTheDocument();
  117. expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_list.1.title');
  118. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.1.5');
  119. await user.click(ui.guidePopup.byRole('button', { name: 'skip' }).get());
  120. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  121. });
  122. it('should not show guide if issues need sync', async () => {
  123. renderProjectIssuesApp(
  124. undefined,
  125. { needIssueSync: true },
  126. mockCurrentUser({
  127. isLoggedIn: true,
  128. dismissedNotices: { [NoticeType.ISSUE_NEW_STATUS_AND_TRANSITION_GUIDE]: true },
  129. }),
  130. );
  131. expect((await ui.issueItems.findAll()).length).toBeGreaterThan(0);
  132. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  133. });
  134. it('should not show guide if user is not logged in', async () => {
  135. renderIssueApp(mockCurrentUser({ isLoggedIn: false }));
  136. expect((await ui.issueItems.findAll()).length).toBeGreaterThan(0);
  137. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  138. });
  139. it('should not show guide if there are no issues', () => {
  140. issuesHandler.setIssueList([]);
  141. renderIssueApp(mockCurrentUser({ isLoggedIn: true }));
  142. expect(ui.loading.query()).not.toBeInTheDocument();
  143. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  144. });
  145. it('should show guide on issue page', async () => {
  146. const user = userEvent.setup();
  147. renderProjectIssuesApp(
  148. 'project/issues?issues=issue11&open=issue11&id=myproject',
  149. undefined,
  150. mockCurrentUser({ isLoggedIn: true }),
  151. );
  152. expect(await ui.guidePopup.find()).toBeInTheDocument();
  153. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.1.5');
  154. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  155. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.2.5');
  156. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  157. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.3.5');
  158. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  159. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.4.5');
  160. await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
  161. expect(ui.guidePopup.get()).toHaveTextContent('guiding.step_x_of_y.5.5');
  162. expect(ui.guidePopup.byRole('button', { name: 'Next' }).query()).not.toBeInTheDocument();
  163. await user.click(ui.guidePopup.byRole('button', { name: 'close' }).get());
  164. expect(ui.guidePopup.query()).not.toBeInTheDocument();
  165. });