filesVersionsUtils.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me>
  3. *
  4. * @author Louis Chemineau <louis@chmn.me>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import type { User } from '@nextcloud/cypress'
  23. import path from 'path'
  24. export const uploadThreeVersions = (user: User, fileName: string) => {
  25. // A new version will not be created if the changes occur
  26. // within less than one second of each other.
  27. // eslint-disable-next-line cypress/no-unnecessary-waiting
  28. cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
  29. .wait(1100)
  30. .uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
  31. .wait(1100)
  32. .uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
  33. cy.login(user)
  34. }
  35. export const openVersionsPanel = (fileName: string) =>{
  36. // Detect the versions list fetch
  37. cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions')
  38. // Open the versions tab
  39. cy.window().then(win => {
  40. win.OCA.Files.Sidebar.setActiveTab('version_vue')
  41. win.OCA.Files.Sidebar.open(`/${fileName}`)
  42. })
  43. // Wait for the versions list to be fetched
  44. cy.wait('@getVersions')
  45. cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 })
  46. }
  47. export const openVersionMenu = (index: number) => {
  48. cy.get('#tab-version_vue').within(() => {
  49. cy.get('[data-files-versions-version]')
  50. .eq(index).within(() => {
  51. cy.get('.action-item__menutoggle').filter(':visible')
  52. .click()
  53. })
  54. })
  55. }
  56. export const clickPopperAction = (actionName: string) => {
  57. cy.get('.v-popper__popper').filter(':visible')
  58. .contains(actionName)
  59. .click()
  60. }
  61. export const nameVersion = (index: number, name: string) => {
  62. openVersionMenu(index)
  63. clickPopperAction('Name this version')
  64. cy.get(':focused').type(`${name}{enter}`)
  65. }
  66. export const assertVersionContent = (filename: string, index: number, expectedContent: string) => {
  67. const downloadsFolder = Cypress.config('downloadsFolder')
  68. openVersionMenu(index)
  69. clickPopperAction('Download version')
  70. return cy.readFile(path.join(downloadsFolder, filename))
  71. .then((versionContent) => expect(versionContent).to.equal(expectedContent))
  72. .then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
  73. }