1
0

filesVersionsUtils.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 path from "path"
  23. import type { User } from "@nextcloud/cypress"
  24. export function 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 function openVersionsPanel(fileName: string) {
  36. cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"]`).within(() => {
  37. cy.get('[data-cy-files-list-row-actions] .action-item__menutoggle')
  38. .click()
  39. })
  40. cy.get('.action-item__popper')
  41. .get('[data-cy-files-list-row-action="details"]')
  42. .click()
  43. cy.get('#app-sidebar-vue')
  44. .get('[aria-controls="tab-version_vue"]')
  45. .click()
  46. }
  47. export function 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 function clickPopperAction(actionName: string) {
  57. cy.get('.v-popper__popper').filter(':visible')
  58. .contains(actionName)
  59. .click()
  60. }
  61. export function nameVersion(index: number, name: string) {
  62. openVersionMenu(index)
  63. clickPopperAction('Name this version')
  64. cy.get(':focused').type(`${name}{enter}`)
  65. }
  66. export function 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. }