|
| 1 | +import * as editor from '../../../support/editor-helpers' |
| 2 | +import * as project from '../../../support/project-helpers' |
| 3 | +import { dataCy } from '../../../support/utils' |
| 4 | + |
| 5 | +describe('Document Template Editor / Editor / Preview with KM Editor', () => { |
| 6 | + const kmName = 'Test Knowledge Model' |
| 7 | + const kmId = 'test-km' |
| 8 | + |
| 9 | + const createKmEditor = () => { |
| 10 | + cy.visitApp('/knowledge-model-editors/create') |
| 11 | + cy.fillFields({ |
| 12 | + name: kmName, |
| 13 | + kmId, |
| 14 | + 'version-major': '1', |
| 15 | + 'version-minor': '0', |
| 16 | + 'version-patch': '0' |
| 17 | + }) |
| 18 | + cy.submitForm() |
| 19 | + cy.url().should('contain', '/knowledge-model-editors/editor/') |
| 20 | + |
| 21 | + const chapter = { title: 'Chapter 1' } |
| 22 | + const question = { |
| 23 | + s_type: 'Value', |
| 24 | + title: 'Question 1', |
| 25 | + } |
| 26 | + editor.createChildren([ |
| 27 | + ['chapter', chapter], |
| 28 | + ['question', question] |
| 29 | + ]) |
| 30 | + } |
| 31 | + |
| 32 | + const createDocumentTemplateEditor = () => { |
| 33 | + cy.visitApp('/document-template-editors/create?selected=dsw:questionnaire-report:1.4.0&edit=true') |
| 34 | + cy.submitForm() |
| 35 | + cy.url().should('contain', '/document-template-editors/dsw:questionnaire-report:1.5.0') |
| 36 | + } |
| 37 | + |
| 38 | + const validateReplies = (validate) => { |
| 39 | + cy.frameLoaded(dataCy('document-preview')) |
| 40 | + cy.iframe().find('pre').then($pre => { |
| 41 | + const templateJson = JSON.parse($pre.text()) |
| 42 | + validate(templateJson['questionnaire']['replies']) |
| 43 | + }) |
| 44 | + } |
| 45 | + |
| 46 | + beforeEach(() => { |
| 47 | + cy.task('branch:delete') |
| 48 | + cy.task('documentTemplate:delete') |
| 49 | + cy.putDefaultAppConfig() |
| 50 | + cy.clearServerCache() |
| 51 | + cy.importTemplate('templates/questionnaire-report.zip') |
| 52 | + |
| 53 | + cy.loginAs('datasteward') |
| 54 | + }) |
| 55 | + |
| 56 | + |
| 57 | + it('preview in browser', () => { |
| 58 | + // Create KM Editor and Document Template Editor |
| 59 | + createKmEditor() |
| 60 | + createDocumentTemplateEditor() |
| 61 | + |
| 62 | + // Set preview in Document Template Editor |
| 63 | + cy.getCy('dt-editor_nav_preview').click() |
| 64 | + cy.getCy('dt-editor_preview-mode_km-editor').click() |
| 65 | + cy.fillFields({ |
| 66 | + th_uuid: kmName, |
| 67 | + s_format: 'JSON Data' |
| 68 | + }) |
| 69 | + |
| 70 | + // Ensure empty replies |
| 71 | + validateReplies(replies => { |
| 72 | + cy.wrap(replies).should('be.empty') |
| 73 | + }) |
| 74 | + |
| 75 | + // Go back to the KM Editor and edit replies |
| 76 | + cy.visitApp('/knowledge-model-editors') |
| 77 | + editor.open(kmId) |
| 78 | + editor.openPreview() |
| 79 | + project.typeAnswer('Question 1', 'This is the question answer') |
| 80 | + cy.getCy('km-editor_preview_save-values').click() |
| 81 | + editor.awaitSave() |
| 82 | + |
| 83 | + // Go back to the Document Template Editor |
| 84 | + cy.visitApp('/document-template-editors') |
| 85 | + cy.clickListingItemAction('dsw:questionnaire-report:1.5.0', 'view') |
| 86 | + cy.getCy('dt-editor_nav_preview').click() |
| 87 | + |
| 88 | + validateReplies(replies => { |
| 89 | + cy.wrap(Object.keys(replies)).should('have.length', 1) |
| 90 | + |
| 91 | + const value = Object.values(replies)[0].value |
| 92 | + cy.wrap(value.type).should('eq', 'StringReply') |
| 93 | + cy.wrap(value.value).should('eq', 'This is the question answer') |
| 94 | + }) |
| 95 | + |
| 96 | + // Back to KM Editor |
| 97 | + cy.visitApp('/knowledge-model-editors') |
| 98 | + editor.open(kmId) |
| 99 | + editor.openPreview() |
| 100 | + project.clearAnswer('Question 1') |
| 101 | + cy.getCy('km-editor_preview_save-values').click() |
| 102 | + editor.awaitSave() |
| 103 | + |
| 104 | + // Back to Document Template Editor and check replies are empty again |
| 105 | + cy.visitApp('/document-template-editors') |
| 106 | + cy.clickListingItemAction('dsw:questionnaire-report:1.5.0', 'view') |
| 107 | + cy.getCy('dt-editor_nav_preview').click() |
| 108 | + |
| 109 | + validateReplies(replies => { |
| 110 | + cy.wrap(replies).should('be.empty') |
| 111 | + }) |
| 112 | + }) |
| 113 | +}) |
0 commit comments