header_contacts-menu.cy.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { User } from '@nextcloud/cypress'
  6. import { clearState, getNextcloudHeader } from '../../support/commonUtils'
  7. // eslint-disable-next-line n/no-extraneous-import
  8. import randomString from 'crypto-random-string'
  9. const admin = new User('admin', 'admin')
  10. const getContactsMenu = () => getNextcloudHeader().find('#header-menu-contactsmenu')
  11. const getContactsMenuToggle = () => getNextcloudHeader().find('#contactsmenu .header-menu__trigger')
  12. const getContactsSearch = () => getContactsMenu().find('#contactsmenu__menu__search')
  13. describe('Header: Contacts menu', { testIsolation: true }, () => {
  14. let user: User
  15. beforeEach(() => {
  16. // clear user and group state
  17. clearState()
  18. // ensure the contacts menu is not restricted
  19. cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
  20. // create a new user for testing the contacts
  21. cy.createRandomUser().then(($user) => {
  22. user = $user
  23. })
  24. // Given I am logged in as the admin
  25. cy.login(admin)
  26. cy.visit('/')
  27. })
  28. it('Other users are seen in the contacts menu', () => {
  29. // When I open the Contacts menu
  30. getContactsMenuToggle().click()
  31. // I see that the Contacts menu is shown
  32. getContactsMenu().should('exist')
  33. // I see that the contact user in the Contacts menu is shown
  34. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  35. // I see that the contact "admin" in the Contacts menu is not shown
  36. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  37. })
  38. it('Just added users are seen in the contacts menu', () => {
  39. // I create a new user
  40. const newUserName = randomString(7)
  41. // we can not use createRandomUser as it will invalidate the session
  42. cy.runOccCommand(`user:add --password-from-env '${newUserName}'`, { env: { OC_PASS: '1234567' } })
  43. // I open the Contacts menu
  44. getContactsMenuToggle().click()
  45. // I see that the Contacts menu is shown
  46. getContactsMenu().should('exist')
  47. // I see that the contact user in the Contacts menu is shown
  48. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  49. // I see that the contact of the new user in the Contacts menu is shown
  50. getContactsMenu().contains('li.contact', newUserName).should('be.visible')
  51. // I see that the contact "admin" in the Contacts menu is not shown
  52. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  53. })
  54. it('Search for other users in the contacts menu', () => {
  55. cy.createRandomUser().then((otherUser) => {
  56. // Given I am logged in as the admin
  57. cy.login(admin)
  58. cy.visit('/')
  59. // I open the Contacts menu
  60. getContactsMenuToggle().click()
  61. // I see that the Contacts menu is shown
  62. getContactsMenu().should('exist')
  63. // I see that the contact user in the Contacts menu is shown
  64. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  65. // I see that the contact of the new user in the Contacts menu is shown
  66. getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')
  67. // I see that the Contacts menu search input is shown
  68. getContactsSearch().should('exist')
  69. // I search for the otherUser
  70. getContactsSearch().type(otherUser.userId)
  71. // I see that the contact otherUser in the Contacts menu is shown
  72. getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')
  73. // I see that the contact user in the Contacts menu is not shown
  74. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  75. // I see that the contact "admin" in the Contacts menu is not shown
  76. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  77. })
  78. })
  79. it('Search for unknown users in the contacts menu', () => {
  80. // I open the Contacts menu
  81. getContactsMenuToggle().click()
  82. // I see that the Contacts menu is shown
  83. getContactsMenu().should('exist')
  84. // I see that the contact user in the Contacts menu is shown
  85. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  86. // I see that the Contacts menu search input is shown
  87. getContactsSearch().should('exist')
  88. // I search for an unknown user
  89. getContactsSearch().type('surely-unknown-user')
  90. // I see that the no results message in the Contacts menu is shown
  91. getContactsMenu().find('ul li').should('have.length', 0)
  92. // I see that the contact user in the Contacts menu is not shown
  93. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  94. // I see that the contact "admin" in the Contacts menu is not shown
  95. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  96. })
  97. it('Users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group', () => {
  98. // I enable restricting username autocompletion to groups
  99. cy.runOccCommand('config:app:set --value yes core shareapi_restrict_user_enumeration_to_group')
  100. // I open the Contacts menu
  101. getContactsMenuToggle().click()
  102. // I see that the Contacts menu is shown
  103. getContactsMenu().should('exist')
  104. // I see that the contact user in the Contacts menu is not shown
  105. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  106. // I see that the contact "admin" in the Contacts menu is not shown
  107. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  108. // I close the Contacts menu
  109. getContactsMenuToggle().click()
  110. // I disable restricting username autocompletion to groups
  111. cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
  112. // I open the Contacts menu
  113. getContactsMenuToggle().click()
  114. // I see that the Contacts menu is shown
  115. getContactsMenu().should('exist')
  116. // I see that the contact user in the Contacts menu is shown
  117. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  118. // I see that the contact "admin" in the Contacts menu is not shown
  119. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  120. })
  121. })