Skip to content

Commit

Permalink
feat: read-only form fields should not be marked as required
Browse files Browse the repository at this point in the history
otherwise it leads to error messages that are not cleared when the value changes
  • Loading branch information
matthieu-foucault committed Jul 24, 2020
1 parent a9d16aa commit a188335
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 1,707 deletions.
3 changes: 0 additions & 3 deletions app/cypress/integration/application-form-validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ describe('When reviewing a submitted application as an analyst', () => {
cy.visit(fuelFormUrl);
cy.contains('Add a fuel').click();
cy.contains('Next Page').click();
cy.get('#root_0_fuelUnits +div .error-detail').contains(
'is a required property'
);
cy.get('#root_0_quantity +div .error-detail').contains(
'is a required property'
);
Expand Down
1,897 changes: 254 additions & 1,643 deletions app/tests/integration/Forms/__snapshots__/Form.test.tsx.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -542,37 +542,37 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
Object {
"gases": Array [
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": -20000000,
"annualEmission": 50000000,
"gasDescription": "in qui",
"gasType": "mollit eu esse",
"gwp": -60000000,
},
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": -80000000,
"annualEmission": 20000000,
"gasDescription": "mollit eu esse",
"gasType": "culpa",
"gwp": -20000000,
},
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": -40000000,
"annualEmission": 40000000,
"gasDescription": "culpa",
"gasType": "est dolor",
"gwp": -80000000,
},
],
"sourceTypeName": "est dolor",
},
Object {
"gases": Array [
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": 0,
"annualEmission": 10000000,
"gasDescription": "est dolor",
"gasType": "consequat Ut Duis",
"gwp": -40000000,
},
Object {
"annualCO2e": -60000000,
Expand All @@ -582,40 +582,26 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
"gwp": 0,
},
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": -20000000,
"annualEmission": 50000000,
"gasDescription": "in qui",
"gasType": "mollit eu esse",
"gwp": -60000000,
},
],
"sourceTypeName": "est dolor",
"sourceTypeName": "mollit eu esse",
},
Object {
"gases": Array [
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
},
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
},
Object {
"annualCO2e": -60000000,
"annualEmission": 30000000,
"gasDescription": "consequat Ut Duis",
"gasType": "in qui",
"gwp": 0,
"annualCO2e": -80000000,
"annualEmission": 20000000,
"gasDescription": "mollit eu esse",
"gasType": "culpa",
"gwp": -20000000,
},
],
"sourceTypeName": "est dolor",
"sourceTypeName": "consequat Ut Duis",
},
],
}
Expand Down Expand Up @@ -656,8 +642,6 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
"required": Array [
"gasType",
"annualEmission",
"gwp",
"annualCO2e",
],
"type": "object",
},
Expand Down Expand Up @@ -812,12 +796,26 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
formData={
Array [
Object {
"comments": "in qui",
"emissionCategoryRowId": -20000000,
"comments": "consequat Ut Duis",
"emissionCategoryRowId": -60000000,
"fuelRowId": -40000000,
"fuelUnits": "est dolor",
"fuelUnits": "in qui",
"quantity": 0,
},
Object {
"comments": "culpa",
"emissionCategoryRowId": -40000000,
"fuelRowId": -20000000,
"fuelUnits": "est dolor",
"quantity": -80000000,
},
Object {
"comments": "in qui",
"emissionCategoryRowId": -20000000,
"fuelRowId": 0,
"fuelUnits": "mollit eu esse",
"quantity": -60000000,
},
]
}
liveValidate={false}
Expand Down Expand Up @@ -853,7 +851,6 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
"required": Array [
"fuelRowId",
"quantity",
"fuelUnits",
"emissionCategoryRowId",
],
"type": "object",
Expand Down Expand Up @@ -974,16 +971,25 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
formData={
Array [
Object {
"comments": "in qui",
"comments": "mollit eu esse",
"isEnergyProduct": false,
"productAmount": 0,
"productRowId": -60000000,
"productUnits": "in qui",
"requiresEmissionAllocation": false,
"requiresProductAmount": true,
},
Object {
"comments": "consequat Ut Duis",
"isEnergyProduct": false,
"productRowId": -40000000,
"requiresEmissionAllocation": false,
"requiresProductAmount": false,
},
Object {
"comments": "est dolor",
"comments": "culpa",
"isEnergyProduct": false,
"productRowId": -80000000,
"productRowId": -20000000,
"requiresEmissionAllocation": false,
"requiresProductAmount": false,
},
Expand Down Expand Up @@ -1043,7 +1049,6 @@ exports[`ApplicationDetailsPdf should render application pdf donwload link 1`] =
},
"required": Array [
"productAmount",
"productUnits",
],
},
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ exports[`The ProductionFields Component with archived product should match the s
},
"required": Array [
"productAmount",
"productUnits",
],
},
Object {
Expand Down Expand Up @@ -385,7 +384,6 @@ exports[`The ProductionFields Component with published product should match the
},
"required": Array [
"productAmount",
"productUnits",
],
},
Object {
Expand Down
2 changes: 1 addition & 1 deletion schema/data/prod/form_json/emission.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"type": "string"
}
},
"required": ["gasType", "annualEmission", "gwp", "annualCO2e"]
"required": ["gasType", "annualEmission"]
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion schema/data/prod/form_json/fuel.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"type": "number"
}
},
"required": ["fuelRowId", "quantity", "fuelUnits","emissionCategoryRowId"]
"required": ["fuelRowId", "quantity","emissionCategoryRowId"]
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion schema/data/prod/form_json/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"type": "string"
}
},
"required": ["productAmount", "productUnits"]
"required": ["productAmount"]
},
{
"properties": {
Expand Down

0 comments on commit a188335

Please sign in to comment.