guided-setup-manual-email-notification.spec.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { flushPromises } from '@vue/test-utils'
  3. import { getByRole, queryByRole } from '@testing-library/vue'
  4. import { getNode } from '@formkit/core'
  5. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  6. import { visitView } from '#tests/support/components/visitView.ts'
  7. import { EnumSystemSetupInfoStatus } from '#shared/graphql/types.ts'
  8. import { mockAuthentication } from '#tests/support/mock-authentication.ts'
  9. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  10. import { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  11. import { mockChannelEmailSetNotificationConfigurationMutation } from '#desktop/entities/channel-email/graphql/mutations/channelEmailSetNotificationConfiguration.mocks.ts'
  12. import {
  13. mockChannelEmailValidateConfigurationOutboundMutation,
  14. waitForChannelEmailValidateConfigurationOutboundMutationCalls,
  15. } from '#desktop/entities/channel-email/graphql/mutations/channelEmailValidateConfigurationOutbound.mocks.ts'
  16. import { mockSystemSetupInfoQuery } from '../graphql/queries/systemSetupInfo.mocks.ts'
  17. describe('guided setup manual email notification', () => {
  18. describe('when system is not ready', () => {
  19. beforeEach(() => {
  20. mockApplicationConfig({
  21. system_init_done: false,
  22. })
  23. })
  24. it('redirects to guided setup start', async () => {
  25. mockSystemSetupInfoQuery({
  26. systemSetupInfo: {
  27. status: EnumSystemSetupInfoStatus.New,
  28. type: null,
  29. },
  30. })
  31. const view = await visitView('/guided-setup/manual/email-notification')
  32. await vi.waitFor(() => {
  33. expect(
  34. view,
  35. 'correctly redirects to guided setup start screen',
  36. ).toHaveCurrentUrl('/guided-setup')
  37. })
  38. view.getByText('Set up a new system')
  39. })
  40. })
  41. describe('when system is ready for optional steps', () => {
  42. beforeEach(() => {
  43. mockApplicationConfig({
  44. system_init_done: true,
  45. })
  46. mockPermissions(['admin'])
  47. mockAuthentication(true)
  48. mockFormUpdaterQuery({
  49. formUpdater: {
  50. adapter: {
  51. initialValue: 'sendmail',
  52. options: [
  53. {
  54. value: 'smtp',
  55. label: 'SMTP - configure your own outgoing SMTP settings',
  56. },
  57. {
  58. value: 'sendmail',
  59. label:
  60. 'Local MTA (Sendmail/Postfix/Exim/â\u0080¦) - use server setup',
  61. },
  62. ],
  63. },
  64. notification_sender: {
  65. initialValue: 'Zammad Helpdesk <noreply@zammad.example.com>',
  66. },
  67. },
  68. })
  69. })
  70. it('can save and continue to channels step', async () => {
  71. mockChannelEmailValidateConfigurationOutboundMutation({
  72. channelEmailValidateConfigurationOutbound: {
  73. success: true,
  74. errors: null,
  75. },
  76. })
  77. mockChannelEmailSetNotificationConfigurationMutation({
  78. channelEmailSetNotificationConfiguration: {
  79. success: true,
  80. },
  81. })
  82. const view = await visitView('/guided-setup/manual/email-notification')
  83. await flushPromises()
  84. await getNode('email-notification-setup')?.settled
  85. expect(view.getByText('Email Notification')).toBeInTheDocument()
  86. expect(view.getByLabelText('Send Mails via')).toBeInTheDocument()
  87. const continueButton = view.getByRole('button', {
  88. name: 'Save and Continue',
  89. })
  90. await view.events.click(continueButton)
  91. await vi.waitFor(() => {
  92. expect(
  93. view,
  94. 'correctly redirects to guided setup email channel step',
  95. ).toHaveCurrentUrl('/guided-setup/manual/channels')
  96. })
  97. })
  98. it('shows warning when SSL verification is turned off', async () => {
  99. const view = await visitView('/guided-setup/manual/email-notification')
  100. await flushPromises()
  101. await getNode('email-notification-setup')?.settled
  102. const form = view.getByTestId('email-notification-setup')
  103. expect(queryByRole(form, 'alert')).not.toBeInTheDocument()
  104. const adapterField = view.getByLabelText('Send Mails via')
  105. await view.events.click(adapterField)
  106. await view.events.click(view.getAllByRole('option')[0])
  107. expect(queryByRole(form, 'alert')).not.toBeInTheDocument()
  108. await view.events.click(view.getByLabelText('SSL verification'))
  109. let alert = getByRole(form, 'alert')
  110. expect(alert).toHaveTextContent(
  111. 'Turning off SSL verification is a security risk and should be used only temporary. Use this option at your own risk!',
  112. )
  113. await view.events.click(view.getByLabelText('SSL verification'))
  114. expect(alert).not.toBeInTheDocument()
  115. await view.events.click(view.getByLabelText('SSL verification'))
  116. alert = getByRole(form, 'alert')
  117. expect(alert).toBeInTheDocument()
  118. await view.events.click(adapterField)
  119. await view.events.click(view.getAllByRole('option')[1])
  120. expect(alert).not.toBeInTheDocument()
  121. })
  122. it('toggles SSL verification disabled state when a port number is provided', async () => {
  123. const view = await visitView('/guided-setup/manual/email-notification')
  124. await flushPromises()
  125. await getNode('email-notification-setup')?.settled
  126. const adapterField = view.getByLabelText('Send Mails via')
  127. await view.events.click(adapterField)
  128. await view.events.click(view.getAllByRole('option')[0])
  129. expect(view.getByLabelText('SSL verification')).not.toBeDisabled()
  130. await view.events.type(view.getByLabelText('Port'), '25')
  131. await vi.waitFor(() => {
  132. expect(view.getByLabelText('SSL verification')).toBeDisabled()
  133. })
  134. await view.events.clear(view.getByLabelText('Port'))
  135. await vi.waitFor(() => {
  136. expect(view.getByLabelText('SSL verification')).not.toBeDisabled()
  137. })
  138. await view.events.type(view.getByLabelText('Port'), '465')
  139. await vi.waitFor(() => {
  140. expect(view.getByLabelText('SSL verification')).not.toBeDisabled()
  141. })
  142. await view.events.type(view.getByLabelText('Port'), '587')
  143. await vi.waitFor(() => {
  144. expect(view.getByLabelText('SSL verification')).not.toBeDisabled()
  145. })
  146. })
  147. it('submits `false` value when SSL verification is disabled', async () => {
  148. mockChannelEmailValidateConfigurationOutboundMutation({
  149. channelEmailValidateConfigurationOutbound: {
  150. success: true,
  151. errors: null,
  152. },
  153. })
  154. mockChannelEmailSetNotificationConfigurationMutation({
  155. channelEmailSetNotificationConfiguration: {
  156. success: true,
  157. },
  158. })
  159. const view = await visitView('/guided-setup/manual/email-notification')
  160. await flushPromises()
  161. await getNode('email-notification-setup')?.settled
  162. const adapterField = view.getByLabelText('Send Mails via')
  163. await view.events.click(adapterField)
  164. await view.events.click(view.getAllByRole('option')[0])
  165. await view.events.type(view.getByLabelText('Host'), 'mail')
  166. await view.events.type(
  167. view.getByLabelText('User'),
  168. 'zammad@mail.test.dc.zammad.com',
  169. )
  170. await view.events.type(view.getByLabelText('Password'), 'zammad')
  171. await view.events.type(view.getByLabelText('Port'), '25')
  172. expect(
  173. getNode('email-notification-setup')?.find('sslVerify')?.value,
  174. ).toBe(true)
  175. await view.events.click(
  176. view.getByRole('button', {
  177. name: 'Save and Continue',
  178. }),
  179. )
  180. const calls =
  181. await waitForChannelEmailValidateConfigurationOutboundMutationCalls()
  182. expect(calls.at(-1)?.variables).toEqual(
  183. expect.objectContaining({
  184. outboundConfiguration: expect.objectContaining({
  185. sslVerify: false,
  186. }),
  187. }),
  188. )
  189. })
  190. it('can go back to system information step', async () => {
  191. const view = await visitView('/guided-setup/manual/email-notification')
  192. const goBackButton = view.getByRole('button', { name: 'Go Back' })
  193. await view.events.click(goBackButton)
  194. await vi.waitFor(() => {
  195. expect(
  196. view,
  197. 'correctly redirects to email notification step',
  198. ).toHaveCurrentUrl('/guided-setup/manual/system-information')
  199. })
  200. })
  201. it('can skip to channels step', async () => {
  202. const view = await visitView('/guided-setup/manual/email-notification')
  203. const skipButton = view.getByRole('button', { name: 'Skip' })
  204. await view.events.click(skipButton)
  205. await vi.waitFor(() => {
  206. expect(view, 'correctly redirects to channels step').toHaveCurrentUrl(
  207. '/guided-setup/manual/channels',
  208. )
  209. })
  210. })
  211. })
  212. })