generate_template.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const templates = require('../../src/assets/local/data/templates.json')['templates'];
  2. const path = require('path');
  3. const localConfig = require('../../src/assets/local/localconfig.json');
  4. const instanceId = localConfig.id;
  5. Cypress.on('uncaught:exception', (err, runnable) => {
  6. // returning false here prevents Cypress from
  7. // failing the test
  8. return false;
  9. });
  10. // https://elaichenkov.medium.com/cypress-how-to-verify-that-file-is-downloaded-with-cy-verify-downloads-c520b7760a69
  11. const exportTemplate = function (downloadsFolder, filename, savedFilename, extension) {
  12. const downloadedPath = path.join(downloadsFolder, filename);
  13. const savedPath = path.join(downloadsFolder, savedFilename);
  14. cy.task('file:exist', savedPath).then((exist) => {
  15. if (exist) return;
  16. cy.get(`#export-${extension}-button`).click({ force: true, timeout: 300000 });
  17. // null for "encoding" https://docs.cypress.io/api/commands/readfile#Arguments
  18. if (extension === 'template') {
  19. cy.readFile(downloadedPath, 'utf8', { timeout: 15000 });
  20. // .its('version').should('eq', '0.9.2')
  21. } else {
  22. cy.readFile(downloadedPath, 'binary', { timeout: 15000 }).should((buffer) => expect(buffer.length).to.be.gt(100));
  23. }
  24. cy.task('file:rename', { oldPath: downloadedPath, newPath: savedPath });
  25. });
  26. };
  27. describe('Export ', () => {
  28. const downloadsFolder = Cypress.config('downloadsFolder');
  29. for (const template of templates) {
  30. it('Generate ' + template.id, () => {
  31. cy.viewport(1280, 720);
  32. const url = `/edit/${template.id}`;
  33. cy.visit(url);
  34. cy.get('#whiteboard').as('whiteboard');
  35. exportTemplate(downloadsFolder, `aktivisda-${template.id}.png`, `${instanceId}/templates/png/${template.id}.png`, `png`);
  36. exportTemplate(downloadsFolder, `aktivisda-${template.id}.jpeg`, `${instanceId}/templates/jpeg/${template.id}.jpeg`, `jpg`);
  37. exportTemplate(downloadsFolder, `aktivisda-${template.id}.pdf`, `${instanceId}/templates/pdf/${template.id}.pdf`, `pdf`);
  38. exportTemplate(downloadsFolder, `${template.id}.json`, `${instanceId}/templates/json/${template.id}.akt`, `template`);
  39. });
  40. }
  41. });