dashboard-compressor.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function uglierBytes (text) {
  2. const KB = 2 ** 10
  3. const MB = KB * KB
  4. if (text.endsWith(' KB')) {
  5. return Number(text.slice(0, -3)) * KB
  6. }
  7. if (text.endsWith(' MB')) {
  8. return Number(text.slice(0, -3)) * MB
  9. }
  10. if (text.endsWith(' B')) {
  11. return Number(text.slice(0, -2))
  12. }
  13. throw new Error(`Not what the computer thinks a human-readable size string look like: ${text}`)
  14. }
  15. describe('dashboard-compressor', () => {
  16. beforeEach(() => {
  17. cy.visit('/dashboard-compressor')
  18. cy.get('.uppy-Dashboard-input').as('file-input')
  19. })
  20. it('should compress images', () => {
  21. const sizeBeforeCompression = []
  22. cy.get('@file-input').attachFile(['images/cat.jpg', 'images/traffic.jpg'])
  23. cy.get('.uppy-Dashboard-Item-statusSize').each((element) => {
  24. const text = element.text()
  25. sizeBeforeCompression.push(uglierBytes(text))
  26. })
  27. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  28. cy.get('.uppy-Informer p[role="alert"]', {
  29. timeout: 10000,
  30. }).should('be.visible')
  31. cy.get('.uppy-Dashboard-Item-statusSize').should((elements) => {
  32. expect(elements).to.have.length(sizeBeforeCompression.length)
  33. for (let i = 0; i < elements.length; i++) {
  34. expect(sizeBeforeCompression[i]).to.be.greaterThan(
  35. uglierBytes(elements[i].textContent),
  36. )
  37. }
  38. })
  39. })
  40. })