diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/address.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/address.graphql.js new file mode 100644 index 0000000000..dda0b68f6d --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/address.graphql.js @@ -0,0 +1,14 @@ +/* + * + * The "Address" Digital Form pattern. + * + * Pattern documentation: + * https://design.va.gov/patterns/ask-users-for/addresses + * + */ +module.exports = ` + fragment address on ParagraphDigitalFormAddress { + fieldTitle + fieldMilitaryAddressCheckbox + } +`; diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.js index e54079b532..f7710f1b18 100644 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.js +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.js @@ -1,4 +1,7 @@ -const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql'); +const address = require('./address.graphql'); +const phoneAndEmail = require('./phoneAndEmail.graphql'); +const yourPersonalInformation = require('./yourPersonalInformation.graphql'); +const listLoop = require('./listLoop.graphql'); /* * @@ -6,13 +9,20 @@ const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql'); * */ module.exports = ` - ${nameAndDateOfBirth} + ${address} + ${listLoop} + ${phoneAndEmail} + ${yourPersonalInformation} fragment digitalForm on NodeDigitalForm { nid entityLabel fieldVaFormNumber fieldOmbNumber + fieldRespondentBurden + fieldExpirationDate { + value + } fieldChapters { entity { entityId @@ -22,7 +32,10 @@ module.exports = ` entityLabel } } - ...nameAndDateOfBirth + ...address + ...listLoop + ...phoneAndEmail + ...yourPersonalInformation } } } diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.unit.spec.js deleted file mode 100644 index 3f8129cd94..0000000000 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/digitalForm.graphql.unit.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable @department-of-veterans-affairs/axe-check-required */ - -import { expect } from 'chai'; -import digitalForm from './digitalForm.graphql'; - -describe('digitalForm fragment', () => { - it('includes form fields', () => { - expect(digitalForm).to.have.string('nid'); - expect(digitalForm).to.have.string('entityLabel'); - expect(digitalForm).to.have.string('fieldVaFormNumber'); - expect(digitalForm).to.have.string('fieldOmbNumber'); - expect(digitalForm).to.have.string('fieldChapters'); - }); - - describe('chapter fragments', () => { - it('imports the nameAndDateOfBirth fragment', () => { - expect(digitalForm).to.have.string('fragment nameAndDateOfBirth'); - expect(digitalForm).to.have.string('...nameAndDateOfBirth'); - }); - }); -}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/identificationInformation.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/identificationInformation.graphql.js new file mode 100644 index 0000000000..8d583cf6d5 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/identificationInformation.graphql.js @@ -0,0 +1,14 @@ +/* + * + * The "Identification Information" Digital Form pattern. + * + * Pattern documentation: + * https://design.va.gov/patterns/ask-users-for/social-security-number + * + */ +module.exports = ` + fragment identificationInformation on ParagraphDigitalFormIdentificationInfo { + fieldTitle + fieldIncludeVeteranSService + } +`; diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/listLoop.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/listLoop.graphql.js new file mode 100644 index 0000000000..5e468b8aed --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/listLoop.graphql.js @@ -0,0 +1,14 @@ +/* + * + * The "List & Loop" Digital Form pattern. + * + * Pattern documentation: + * https://design.va.gov/patterns/ask-users-for/multiple-responses + * + */ +module.exports = ` +fragment listLoop on ParagraphDigitalFormListLoop { + fieldTitle + fieldOptional +} +`; diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/phoneAndEmail.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/phoneAndEmail.graphql.js new file mode 100644 index 0000000000..d47cdb2dab --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/phoneAndEmail.graphql.js @@ -0,0 +1,14 @@ +/* + * + * The "Phone and Email Address" Digital Form pattern. + * + * Pattern documentation: + * https://design.va.gov/patterns/ask-users-for/phone-numbers + * + */ +module.exports = ` +fragment phoneAndEmail on ParagraphDigitalFormPhoneAndEmail { + fieldTitle + fieldIncludeEmail +} +`; diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/yourPersonalInformation.graphql.js b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/yourPersonalInformation.graphql.js new file mode 100644 index 0000000000..a1785fcc87 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/yourPersonalInformation.graphql.js @@ -0,0 +1,28 @@ +const identificationInformation = require('./identificationInformation.graphql'); +const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql'); + +/* + * + * The "Your personal information" Digital Form pattern. + * + * Pattern documentation: + * https://github.com/department-of-veterans-affairs/vets-website/blob/0ae48c0b017a37d84f6ae425c67c332f4c67fb8b/src/applications/simple-forms/mock-simple-forms-patterns-v3/config/form.js#L40 + * + */ +module.exports = ` + ${identificationInformation} + ${nameAndDateOfBirth} + + fragment yourPersonalInformation on ParagraphDigitalFormYourPersonalInfo { + fieldNameAndDateOfBirth { + entity { + ...nameAndDateOfBirth + } + } + fieldIdentificationInformation { + entity { + ...identificationInformation + } + } + } +`; diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/index.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/index.unit.spec.js deleted file mode 100644 index bd504fb47e..0000000000 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/index.unit.spec.js +++ /dev/null @@ -1,52 +0,0 @@ -/* eslint-disable @department-of-veterans-affairs/axe-check-required */ - -import { expect } from 'chai'; -import { query, postProcess } from './index'; - -describe('digitalForm', () => { - describe('query', () => { - it('returns digital_form entities', () => { - expect(query).to.have.string('digital_form'); - }); - it('imports the digitalForm fragment', () => { - expect(query).to.have.string('fragment digitalForm'); - expect(query).to.have.string('... digitalForm'); - }); - }); - - describe('postProcess', () => { - it('imports postProcessDigitalForm', () => { - const queryResult = { - data: { - nodeQuery: { - entities: [ - { - nid: 71002, - entityLabel: 'Form with One Step', - fieldVaFormNumber: '11111', - fieldOmbNumber: '1111-1111', - fieldChapters: [ - { - entity: { - entityId: '157904', - type: { - entity: { - entityId: 'digital_form_name_and_date_of_bi', - entityLabel: 'Name and Date of Birth', - }, - }, - fieldTitle: 'The Only Step', - fieldIncludeDateOfBirth: true, - }, - }, - ], - }, - ], - }, - }, - }; - - expect(() => postProcess(queryResult)).to.not.throw(); - }); - }); -}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.js b/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.js index 3541cb8a8b..65758289fb 100644 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.js +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.js @@ -1,23 +1,69 @@ const { logDrupal } = require('../../utilities-drupal'); const extractAdditionalFields = entity => { - const additionalFields = {}; + const { entityId } = entity.type.entity; - if (entity.type.entity.entityId === 'digital_form_name_and_date_of_bi') { - additionalFields.includeDateOfBirth = entity.fieldIncludeDateOfBirth; + switch (entityId) { + case 'digital_form_address': + return { + militaryAddressCheckbox: entity.fieldMilitaryAddressCheckbox, + }; + case 'digital_form_list_loop': + return { + optional: entity.fieldOptional, + }; + case 'digital_form_phone_and_email': + return { + includeEmail: entity.fieldIncludeEmail, + }; + default: + return {}; } - - return additionalFields; }; const extractForms = resultObject => resultObject?.data?.nodeQuery?.entities; +const formatDate = dateString => { + const removeLeadingZero = s => s.replace(/^0+/, ''); + const [year, month, day] = dateString.split('-'); + return `${removeLeadingZero(month)}/${removeLeadingZero(day)}/${year}`; +}; + +const stripPrefix = label => label.replace('Digital Form: ', ''); + const normalizeChapter = ({ entity }) => { - return { + const type = entity.type.entity.entityId; + const initialChapter = { id: parseInt(entity.entityId, 10), - chapterTitle: entity.fieldTitle, - type: entity.type.entity.entityId, - pageTitle: entity.type.entity.entityLabel, + type, + }; + + if (type === 'digital_form_your_personal_info') { + const identificationInformation = + entity.fieldIdentificationInformation.entity; + const nameAndDateOfBirth = entity.fieldNameAndDateOfBirth.entity; + + return { + ...initialChapter, + chapterTitle: stripPrefix(entity.type.entity.entityLabel), + pages: [ + { + pageTitle: nameAndDateOfBirth.fieldTitle, + includeDateOfBirth: nameAndDateOfBirth.fieldIncludeDateOfBirth, + }, + { + pageTitle: identificationInformation.fieldTitle, + includeServiceNumber: + identificationInformation.fieldIncludeVeteranSService, + }, + ], + }; + } + + return { + ...initialChapter, additionalFields: extractAdditionalFields(entity), + chapterTitle: entity.fieldTitle, + pageTitle: stripPrefix(entity.type.entity.entityLabel), }; }; @@ -27,7 +73,11 @@ const normalizeForm = (form, logger = logDrupal) => { cmsId: form.nid, formId: form.fieldVaFormNumber, title: form.entityLabel, - ombNumber: form.fieldOmbNumber, + ombInfo: { + expDate: formatDate(form.fieldExpirationDate.value), + ombNumber: form.fieldOmbNumber, + resBurden: form.fieldRespondentBurden, + }, chapters: form.fieldChapters.map(normalizeChapter), }; } catch (error) { diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.unit.spec.js deleted file mode 100644 index d693ef648b..0000000000 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/postProcessDigitalForm.unit.spec.js +++ /dev/null @@ -1,180 +0,0 @@ -/* eslint-disable @department-of-veterans-affairs/axe-check-required */ - -import { expect } from 'chai'; -import sinon from 'sinon'; - -const { postProcessDigitalForm } = require('./postProcessDigitalForm'); - -describe('postProcessDigitalForm', () => { - context('with a well-formed query result', () => { - const queryResult = { - data: { - nodeQuery: { - entities: [ - { - nid: 71002, - entityLabel: 'Form with One Step', - fieldVaFormNumber: '11111', - fieldOmbNumber: '1111-1111', - fieldChapters: [ - { - entity: { - entityId: '157904', - type: { - entity: { - entityId: 'digital_form_name_and_date_of_bi', - entityLabel: 'Name and Date of Birth', - }, - }, - fieldTitle: 'The Only Step', - fieldIncludeDateOfBirth: true, - }, - }, - ], - }, - { - nid: 71004, - entityLabel: 'Form with Two Steps', - fieldVaFormNumber: '222222', - fieldOmbNumber: '1212-1212', - fieldChapters: [ - { - entity: { - entityId: '157906', - type: { - entity: { - entityId: 'digital_form_name_and_date_of_bi', - entityLabel: 'Name and Date of Birth', - }, - }, - fieldTitle: 'First Step', - fieldIncludeDateOfBirth: true, - }, - }, - { - entity: { - entityId: '157907', - type: { - entity: { - entityId: 'digital_form_name_and_date_of_bi', - entityLabel: 'Name and Date of Birth', - }, - }, - fieldTitle: 'Second Step', - fieldIncludeDateOfBirth: false, - }, - }, - ], - }, - ], - }, - }, - }; - let processedResult; - - beforeEach(() => { - processedResult = postProcessDigitalForm(queryResult); - }); - - it('returns a normalized JSON object', () => { - const testForm = processedResult[1]; - const testChapter = testForm.chapters[1]; - - expect(processedResult.length).to.eq(2); - expect(testForm.cmsId).to.eq(71004); - expect(testForm.formId).to.eq('222222'); - expect(testForm.title).to.eq('Form with Two Steps'); - expect(testForm.ombNumber).to.eq('1212-1212'); - expect(testForm.chapters.length).to.eq(2); - expect(testChapter.id).to.eq(157907); - expect(testChapter.chapterTitle).to.eq('Second Step'); - expect(testChapter.type).to.eq('digital_form_name_and_date_of_bi'); - expect(testChapter.pageTitle).to.eq('Name and Date of Birth'); - expect(Object.keys(testChapter.additionalFields).length).to.eq(1); - }); - - context('with a Name and Date of Birth step', () => { - it('includes the appropriate fields', () => { - const { additionalFields } = processedResult[1].chapters[1]; - - expect(additionalFields.includeDateOfBirth).to.eq(false); - }); - }); - }); - - context('with a malformed query result', () => { - let queryResult; - let processedResult; - let logger; - - beforeEach(() => { - logger = sinon.spy(); - }); - - context('when the entire query is bad', () => { - beforeEach(() => { - queryResult = { - wrongKey: 'oops! bad data!', - }; - processedResult = postProcessDigitalForm(queryResult, logger); - }); - - it('logs the error', () => { - expect(logger.calledOnce).to.eq(true); - }); - - it('returns an empty array', () => { - expect(processedResult.length).to.eq(0); - }); - }); - - context('when only one form is malformed', () => { - beforeEach(() => { - queryResult = { - data: { - nodeQuery: { - entities: [ - { - nid: 71002, - entityLabel: 'Form with One Step', - fieldVaFormNumber: '11111', - fieldOmbNumber: '1111-1111', - fieldChapters: [ - { - entity: { - entityId: '157904', - type: { - entity: { - entityId: 'digital_form_name_and_date_of_bi', - entityLabel: 'Name and Date of Birth', - }, - }, - fieldTitle: 'The Only Step', - fieldIncludeDateOfBirth: true, - }, - }, - ], - }, - { - nid: '71004', - entityLabel: 'This form has problems', - fieldVaFormNumber: 222222, - fieldChapters: 'no chapters', - }, - ], - }, - }, - }; - processedResult = postProcessDigitalForm(queryResult, logger); - }); - - it('logs the error', () => { - expect(logger.calledOnce).to.eq(true); - }); - - it('returns the other forms', () => { - expect(processedResult[0].cmsId).to.eq(71002); - }); - }); - }); -}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fixtures/queryResult.json b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fixtures/queryResult.json new file mode 100644 index 0000000000..04172964aa --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fixtures/queryResult.json @@ -0,0 +1,117 @@ +{ + "data": { + "nodeQuery": { + "entities": [ + { + "nid": 71002, + "entityLabel": "Form with One Step", + "fieldVaFormNumber": "11111", + "fieldOmbNumber": "1111-1111", + "fieldRespondentBurden": 48, + "fieldExpirationDate": { + "value": "2025-06-11" + }, + "fieldChapters": [ + { + "entity": { + "entityId": "162008", + "type": { + "entity": { + "entityId": "digital_form_your_personal_info", + "entityLabel": "Digital Form: Your personal information" + } + }, + "fieldNameAndDateOfBirth": { + "entity": { + "fieldTitle": "Name", + "fieldIncludeDateOfBirth": true + } + }, + "fieldIdentificationInformation": { + "entity": { + "fieldTitle": "Identification information", + "fieldIncludeVeteranSService": false + } + } + } + } + ] + }, + { + "nid": 71004, + "entityLabel": "Form with Many Steps", + "fieldVaFormNumber": "222222", + "fieldOmbNumber": "1212-1212", + "fieldRespondentBurden": 30, + "fieldExpirationDate": { + "value": "2027-01-29" + }, + "fieldChapters": [ + { + "entity": { + "entityId": "162008", + "type": { + "entity": { + "entityId": "digital_form_your_personal_info", + "entityLabel": "Digital Form: Your personal information" + } + }, + "fieldNameAndDateOfBirth": { + "entity": { + "fieldTitle": "Name and Date of Birth", + "fieldIncludeDateOfBirth": true + } + }, + "fieldIdentificationInformation": { + "entity": { + "fieldTitle": "Identification information", + "fieldIncludeVeteranSService": false + } + } + } + }, + { + "entity": { + "entityId": "161344", + "type": { + "entity": { + "entityId": "digital_form_address", + "entityLabel": "Digital Form: Address" + } + }, + "fieldTitle": "Generated Address", + "fieldMilitaryAddressCheckbox": false + } + }, + { + "entity": { + "entityId": "161351", + "type": { + "entity": { + "entityId": "digital_form_phone_and_email", + "entityLabel": "Digital Form: Phone and email address" + } + }, + "fieldTitle": "Generated Phone", + "fieldIncludeEmail": false + } + }, + { + "entity": { + "entityId": "162026", + "type": { + "entity": { + "entityId": "digital_form_list_loop", + "entityLabel": "Digital Form: List & Loop" + } + }, + "fieldTitle": "Generated List & Loop", + "fieldOptional": false + } + } + ] + } + ] + } + } +} diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/address.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/address.graphql.unit.spec.js new file mode 100644 index 0000000000..8acd9bf18f --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/address.graphql.unit.spec.js @@ -0,0 +1,13 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import address from '../../fragments/address.graphql'; + +describe('address fragment', () => { + it('includes fieldTitle', () => { + expect(address).to.have.string('fieldTitle'); + }); + it('includes fieldMilitaryAddressCheckbox', () => { + expect(address).to.have.string('fieldMilitaryAddressCheckbox'); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/digitalForm.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/digitalForm.graphql.unit.spec.js new file mode 100644 index 0000000000..deb370785c --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/digitalForm.graphql.unit.spec.js @@ -0,0 +1,30 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import digitalForm from '../../fragments/digitalForm.graphql'; + +describe('digitalForm fragment', () => { + it('includes form fields', () => { + expect(digitalForm).to.have.string('nid'); + expect(digitalForm).to.have.string('entityLabel'); + expect(digitalForm).to.have.string('fieldVaFormNumber'); + expect(digitalForm).to.have.string('fieldChapters'); + }); + + it('include OMB info', () => { + expect(digitalForm).to.have.string('fieldOmbNumber'); + expect(digitalForm).to.have.string('fieldRespondentBurden'); + expect(digitalForm).to.have.string('fieldExpirationDate'); + }); + + describe('chapter fragments', () => { + ['address', 'listLoop', 'phoneAndEmail', 'yourPersonalInformation'].forEach( + fragment => { + it(`imports the ${fragment} fragment`, () => { + expect(digitalForm).to.have.string(`fragment ${fragment}`); + expect(digitalForm).to.have.string(`...${fragment}`); + }); + }, + ); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/identificationInformation.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/identificationInformation.graphql.unit.spec.js new file mode 100644 index 0000000000..4806461c69 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/identificationInformation.graphql.unit.spec.js @@ -0,0 +1,15 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import identificationInformation from '../../fragments/identificationInformation.graphql'; + +describe('identificationInformation fragment', () => { + it('includes fieldTitle', () => { + expect(identificationInformation).to.have.string('fieldTitle'); + }); + it('includes fieldIncludeVeteranSService', () => { + expect(identificationInformation).to.have.string( + 'fieldIncludeVeteranSService', + ); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/listLoop.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/listLoop.graphql.unit.spec.js new file mode 100644 index 0000000000..aec33c7af2 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/listLoop.graphql.unit.spec.js @@ -0,0 +1,14 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import listLoop from '../../fragments/listLoop.graphql'; + +describe('listLoop fragment', () => { + it('includes fieldTitle', () => { + expect(listLoop).to.have.string('fieldTitle'); + }); + + it('includes fieldOptional', () => { + expect(listLoop).to.have.string('fieldOptional'); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/nameAndDateOfBirth.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/nameAndDateOfBirth.graphql.unit.spec.js similarity index 83% rename from src/site/stages/build/drupal/static-data-files/digitalForm/fragments/nameAndDateOfBirth.graphql.unit.spec.js rename to src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/nameAndDateOfBirth.graphql.unit.spec.js index d2cf16bd17..a95de7b171 100644 --- a/src/site/stages/build/drupal/static-data-files/digitalForm/fragments/nameAndDateOfBirth.graphql.unit.spec.js +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/nameAndDateOfBirth.graphql.unit.spec.js @@ -1,7 +1,7 @@ /* eslint-disable @department-of-veterans-affairs/axe-check-required */ import { expect } from 'chai'; -import nameAndDateOfBirth from './nameAndDateOfBirth.graphql'; +import nameAndDateOfBirth from '../../fragments/nameAndDateOfBirth.graphql'; describe('nameAndDateOfBirth fragment', () => { it('includes fieldTitle', () => { diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/phoneAndEmail.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/phoneAndEmail.graphql.unit.spec.js new file mode 100644 index 0000000000..b8649ef9cd --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/phoneAndEmail.graphql.unit.spec.js @@ -0,0 +1,14 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import phoneAndEmail from '../../fragments/phoneAndEmail.graphql'; + +describe('phoneAndEmail fragment', () => { + it('includes fieldTitle', () => { + expect(phoneAndEmail).to.have.string('fieldTitle'); + }); + + it('includes fieldIncludeEmail', () => { + expect(phoneAndEmail).to.have.string('fieldIncludeEmail'); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/yourPersonalInformation.graphql.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/yourPersonalInformation.graphql.unit.spec.js new file mode 100644 index 0000000000..427c302077 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/fragments/yourPersonalInformation.graphql.unit.spec.js @@ -0,0 +1,13 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import yourPersonalInformation from '../../fragments/yourPersonalInformation.graphql'; + +describe('yourPersonalInformation fragment', () => { + ['identificationInformation', 'nameAndDateOfBirth'].forEach(fragment => { + it(`imports the ${fragment} fragment`, () => { + expect(yourPersonalInformation).to.have.string(`fragment ${fragment}`); + expect(yourPersonalInformation).to.have.string(`...${fragment}`); + }); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/index.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/index.unit.spec.js new file mode 100644 index 0000000000..c38bedf07e --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/index.unit.spec.js @@ -0,0 +1,23 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import { query, postProcess } from '../index'; +import queryResult from './fixtures/queryResult.json'; + +describe('digitalForm', () => { + describe('query', () => { + it('returns digital_form entities', () => { + expect(query).to.have.string('digital_form'); + }); + it('imports the digitalForm fragment', () => { + expect(query).to.have.string('fragment digitalForm'); + expect(query).to.have.string('... digitalForm'); + }); + }); + + describe('postProcess', () => { + it('imports postProcessDigitalForm', () => { + expect(() => postProcess(queryResult)).to.not.throw(); + }); + }); +}); diff --git a/src/site/stages/build/drupal/static-data-files/digitalForm/tests/postProcessDigitalForm.unit.spec.js b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/postProcessDigitalForm.unit.spec.js new file mode 100644 index 0000000000..f353b98605 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/digitalForm/tests/postProcessDigitalForm.unit.spec.js @@ -0,0 +1,160 @@ +/* eslint-disable @department-of-veterans-affairs/axe-check-required */ + +import { expect } from 'chai'; +import sinon from 'sinon'; +import queryResult from './fixtures/queryResult.json'; + +const { postProcessDigitalForm } = require('../postProcessDigitalForm'); + +describe('postProcessDigitalForm', () => { + const [oneStepEntity, manyStepEntity] = queryResult.data.nodeQuery.entities; + + context('with a well-formed query result', () => { + let testForm; + + beforeEach(() => { + [, testForm] = postProcessDigitalForm(queryResult); + }); + + it('returns a normalized JSON object', () => { + const queryChapter = manyStepEntity.fieldChapters[1].entity; + const testChapter = testForm.chapters[1]; + + expect(testForm.cmsId).to.eq(71004); + expect(testForm.formId).to.eq('222222'); + expect(testForm.title).to.eq(manyStepEntity.entityLabel); + expect(testForm.chapters.length).to.eq( + manyStepEntity.fieldChapters.length, + ); + expect(testChapter.id).to.eq(Number(queryChapter.entityId)); + expect(testChapter.chapterTitle).to.eq(queryChapter.fieldTitle); + expect(testChapter.type).to.eq(queryChapter.type.entity.entityId); + expect(Object.keys(testChapter.additionalFields).length).to.eq(1); + }); + + it('includes an OMB info object', () => { + const { ombInfo } = testForm; + // towStepEntity.fieldExpirationDate is 2027-01-29 + const formattedDate = '1/29/2027'; + + expect(ombInfo.ombNumber).to.eq(manyStepEntity.fieldOmbNumber); + expect(ombInfo.expDate).to.eq(formattedDate); + expect(ombInfo.resBurden).to.eq(manyStepEntity.fieldRespondentBurden); + }); + + it('removes the "Digital Form" prefix', () => { + const [, testChapter] = testForm.chapters; + + expect(testChapter.pageTitle).to.eq('Address'); + }); + + describe('additionalFields', () => { + [ + ['digital_form_address', 'militaryAddressCheckbox', false], + ['digital_form_list_loop', 'optional', false], + ['digital_form_phone_and_email', 'includeEmail', false], + ].forEach(([type, additionalField, value]) => { + context(`with a ${type} step`, () => { + it('includes the appropriate additional fields', () => { + const { additionalFields } = testForm.chapters.find( + chapter => chapter.type === type, + ); + + expect(additionalFields[additionalField]).to.eq(value); + }); + }); + }); + }); + + describe('Your personal information', () => { + let ypiChapter; + const queryYpi = manyStepEntity.fieldChapters[0].entity; + + beforeEach(() => { + ypiChapter = testForm.chapters.find( + chapter => chapter.type === 'digital_form_your_personal_info', + ); + }); + + it('includes the correct chapter title', () => { + expect(ypiChapter.chapterTitle).to.eq('Your personal information'); + }); + + it('includes a Name and Date of Birth page', () => { + const nameAndDateOfBirth = ypiChapter.pages[0]; + const queryNdob = queryYpi.fieldNameAndDateOfBirth.entity; + + expect(nameAndDateOfBirth.pageTitle).to.eq(queryNdob.fieldTitle); + expect(nameAndDateOfBirth.includeDateOfBirth).to.eq( + queryNdob.fieldIncludeDateOfBirth, + ); + }); + + it('includes an Identification information page', () => { + const identificationInformation = ypiChapter.pages[1]; + const queryIi = queryYpi.fieldIdentificationInformation.entity; + + expect(identificationInformation.pageTitle).to.eq(queryIi.fieldTitle); + expect(identificationInformation.includeServiceNumber).to.eq( + queryIi.fieldIncludeVeteranSService, + ); + }); + }); + }); + + context('with a malformed query result', () => { + let badQueryResult; + let processedResult; + let logger; + + beforeEach(() => { + logger = sinon.spy(); + }); + + context('when the entire query is bad', () => { + beforeEach(() => { + badQueryResult = { + wrongKey: 'oops! bad data!', + }; + processedResult = postProcessDigitalForm(badQueryResult, logger); + }); + + it('logs the error', () => { + expect(logger.calledOnce).to.eq(true); + }); + + it('returns an empty array', () => { + expect(processedResult.length).to.eq(0); + }); + }); + + context('when only one form is malformed', () => { + beforeEach(() => { + badQueryResult = { + data: { + nodeQuery: { + entities: [ + oneStepEntity, + { + nid: '71004', + entityLabel: 'This form has problems', + fieldVaFormNumber: 222222, + fieldChapters: 'no chapters', + }, + ], + }, + }, + }; + processedResult = postProcessDigitalForm(badQueryResult, logger); + }); + + it('logs the error', () => { + expect(logger.calledOnce).to.eq(true); + }); + + it('returns the other forms', () => { + expect(processedResult[0].cmsId).to.eq(71002); + }); + }); + }); +});