domain-capture.spec.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import DomainCapture from '../../../../../modules/group-settings/frontend/js/components/domain-capture'
  2. describe('<DomainCapture />', function () {
  3. beforeEach(function () {
  4. this.email = 'user@example.com'
  5. this.groupName = 'test-group'
  6. this.ssoInitPath = '/sso/init/path'
  7. this.notificationsInstitution = []
  8. cy.window().then(win => {
  9. win.metaAttributesCache.set('ol-user', {
  10. email: this.email,
  11. first_name: 'Nice',
  12. last_name: 'Wombat',
  13. })
  14. win.metaAttributesCache.set('ol-email', this.email)
  15. win.metaAttributesCache.set('ol-groupName', this.groupName)
  16. win.metaAttributesCache.set('ol-ssoInitPath', this.ssoInitPath)
  17. win.metaAttributesCache.set(
  18. 'ol-notificationsInstitution',
  19. this.notificationsInstitution
  20. )
  21. win.metaAttributesCache.set('ol-managedUsersEnabled', false)
  22. })
  23. cy.mount(<DomainCapture />)
  24. })
  25. it('renders the heading', function () {
  26. cy.findByRole('heading', {
  27. name: new RegExp(
  28. `your account is associated with ${this.groupName}`,
  29. 'i'
  30. ),
  31. })
  32. })
  33. it('renders the description', function () {
  34. cy.findByTestId('domain-capture-signed-in-as')
  35. .invoke('text')
  36. .should(
  37. 'match',
  38. new RegExp(
  39. `you’re signed in using your organization email ${this.email}. ` +
  40. 'this means you need to take one of the following actions',
  41. 'i'
  42. )
  43. )
  44. })
  45. describe('join group card', function () {
  46. describe('title', function () {
  47. it('renders with managed users disabled', function () {
  48. cy.findByTestId('domain-capture-join-card').within(() => {
  49. cy.findByRole('heading', {
  50. name: new RegExp(`join ${this.groupName} enterprise group`, 'i'),
  51. })
  52. })
  53. })
  54. it('renders with managed users enabled', function () {
  55. cy.window().then(win => {
  56. win.metaAttributesCache.set('ol-managedUsersEnabled', true)
  57. })
  58. cy.mount(<DomainCapture />)
  59. cy.findByTestId('domain-capture-join-card').within(() => {
  60. cy.findByRole('heading', {
  61. name: new RegExp(
  62. `join ${this.groupName} managed enterprise group`,
  63. 'i'
  64. ),
  65. })
  66. })
  67. })
  68. })
  69. it('renders the body', function () {
  70. cy.findByTestId('domain-capture-join-card').within(() => {
  71. cy.findByText(
  72. /get access to enterprise features and benefits provided by your organization/i
  73. )
  74. cy.findByRole('link', { name: /join group/i }).should(
  75. 'have.attr',
  76. 'href',
  77. this.ssoInitPath
  78. )
  79. })
  80. })
  81. })
  82. it('renders the remove company email card', function () {
  83. cy.findByTestId('domain-capture-remove-email-card').within(() => {
  84. cy.findByRole('heading', {
  85. name: /remove your organization email address from this account/i,
  86. })
  87. cy.findByText(
  88. /if this is a personal .* account, you should change your email address to keep ownership of your personal projects/i
  89. )
  90. cy.findByRole('link', { name: /change email address/i }).should(
  91. 'have.attr',
  92. 'href',
  93. '/user/settings'
  94. )
  95. })
  96. })
  97. describe('notifications', function () {
  98. it('renders missing email on account error message', function () {
  99. const institutionEmail = 'email@example.com'
  100. const notificationsInstitution = [
  101. {
  102. templateKey: 'notification_email_not_in_account',
  103. institutionEmail,
  104. },
  105. ]
  106. cy.window().then(win => {
  107. win.metaAttributesCache.set(
  108. 'ol-notificationsInstitution',
  109. notificationsInstitution
  110. )
  111. })
  112. cy.mount(<DomainCapture />)
  113. cy.findByRole('alert').should(
  114. 'contain.text',
  115. `Your email address ${this.email} was not recognized. ` +
  116. `Your organization’s identity provider returned ${institutionEmail}. ` +
  117. `You will need to log out of ${this.email} and use ${institutionEmail} to create an account via SSO. ` +
  118. `You can transfer your existing projects to the new account.`
  119. )
  120. cy.findByRole('link', {
  121. name: /transfer your existing projects/i,
  122. }).should(
  123. 'have.attr',
  124. 'href',
  125. '/learn/how-to/How_to_Transfer_Project_Ownership'
  126. )
  127. })
  128. it('renders group limit reached error message', function () {
  129. const notificationsInstitution = [
  130. { templateKey: 'notification_group_member_limit_reached' },
  131. ]
  132. cy.window().then(win => {
  133. win.metaAttributesCache.set(
  134. 'ol-notificationsInstitution',
  135. notificationsInstitution
  136. )
  137. })
  138. cy.mount(<DomainCapture />)
  139. cy.findByRole('alert').should(
  140. 'contain.text',
  141. 'Sorry, your group has no licenses available. ' +
  142. 'Please contact your administrator to request a license.'
  143. )
  144. })
  145. it('renders institution error message', function () {
  146. const errorMsg = 'Error message'
  147. const notificationsInstitution = [
  148. {
  149. templateKey: 'notification_institution_sso_error',
  150. error: {
  151. message: errorMsg,
  152. },
  153. },
  154. ]
  155. cy.window().then(win => {
  156. win.metaAttributesCache.set(
  157. 'ol-notificationsInstitution',
  158. notificationsInstitution
  159. )
  160. })
  161. cy.mount(<DomainCapture />)
  162. cy.findByRole('alert').should('contain.text', errorMsg)
  163. })
  164. })
  165. })