From ad44189208addd45d50faa7b453060241e86514d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harouna=20Traor=C3=A9?= Date: Fri, 27 Oct 2023 12:16:24 +0200 Subject: [PATCH 1/3] form group as area not array --- i18n/en.json | 7 +-- index.js | 2 +- .../@apostrophecms/form-group-widget/index.js | 35 ++++------- .../form-group-widget/views/widget.html | 18 +++--- test/lib/file-utils.js | 2 +- test/test.js | 62 +++++++++++++------ 6 files changed, 67 insertions(+), 59 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 7e09445..6a9ffaf 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -61,11 +61,10 @@ "group": "Group", "groupAdvanced": "Advanced", "groupAfterSubmission": "After submission", + "groupContents": "Groups Contents", + "groupContentsHelp": "Contains all form widgets excepts groups", "groupForm": "Form", - "groupGroups": "Groups", - "groupGroupsContents": "Groups Contents", - "groupGroupsContentsHelp": "Contains all form widgets excepts groups", - "groupGroupsLabel": "Group Label", + "groupLabel": "Group Label", "notFoundForm": "No matching form was found", "queryParamKey": "Key", "queryParamLimit": "Limit Saved Parameter Value Length (characters)", diff --git a/index.js b/index.js index 8640c6b..70426a0 100644 --- a/index.js +++ b/index.js @@ -286,7 +286,7 @@ module.exports = { data, submission }); - return self.db.insert(submission); + return self.db.insertOne(submission); }, async emailSubmission (req, form, data) { await self.sendEmailSubmissions(req, form, data); diff --git a/modules/@apostrophecms/form-group-widget/index.js b/modules/@apostrophecms/form-group-widget/index.js index be17743..ee62211 100644 --- a/modules/@apostrophecms/form-group-widget/index.js +++ b/modules/@apostrophecms/form-group-widget/index.js @@ -18,29 +18,18 @@ module.exports = { return { add: { - groups: { - label: 'aposForm:groupGroups', - type: 'array', - required: true, - titleField: 'label', - inline: true, - fields: { - add: { - label: { - label: 'aposForm:groupGroupsLabel', - type: 'string', - required: true - }, - contents: { - label: 'aposForm:groupGroupsContents', - help: 'aposForm:groupGroupsContentsHelp', - type: 'area', - contextual: false, - options: { - widgets: formWidgets - } - } - } + label: { + label: 'aposForm:groupLabel', + type: 'string', + required: true + }, + contents: { + label: 'aposForm:groupContents', + help: 'aposForm:groupContentsHelp', + type: 'area', + contextual: false, + options: { + widgets: formWidgets } } } diff --git a/modules/@apostrophecms/form-group-widget/views/widget.html b/modules/@apostrophecms/form-group-widget/views/widget.html index f151f10..d1f487c 100644 --- a/modules/@apostrophecms/form-group-widget/views/widget.html +++ b/modules/@apostrophecms/form-group-widget/views/widget.html @@ -1,13 +1,9 @@ +{% set widget = data.widget %} {% set prependIfPrefix = apos.modules['@apostrophecms/form'].prependIfPrefix %} -
- {% for group in data.widget.groups %} -
- {{ group.label }} - {% area group, 'contents' %} -
- {% endfor %} -
+
+ {{ widget.label }} + {% area widget, 'contents' %} +
diff --git a/test/lib/file-utils.js b/test/lib/file-utils.js index 7b7619f..4ef0b70 100644 --- a/test/lib/file-utils.js +++ b/test/lib/file-utils.js @@ -23,7 +23,7 @@ module.exports = { const db = await apos.db.collection('aposAttachments'); - db.remove({}); + db.deleteMany({}); }, insert: async function (filename, apos) { return apos.attachment.insert(apos.task.getReq(), { diff --git a/test/test.js b/test/test.js index 4ecc399..e941eea 100644 --- a/test/test.js +++ b/test/test.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +const assert = require('assert').strict; const testUtil = require('apostrophe/test-lib/test'); const fileUtils = require('./lib/file-utils'); const FormData = require('form-data'); @@ -10,8 +10,8 @@ describe('Forms module', function () { this.timeout(25000); - after(async function () { - testUtil.destroy(apos); + after(function () { + return testUtil.destroy(apos); }); // Existence @@ -25,7 +25,8 @@ describe('Forms module', function () { '@apostrophecms/form-file-field-widget': {}, '@apostrophecms/form-boolean-field-widget': {}, '@apostrophecms/form-conditional-widget': {}, - '@apostrophecms/form-divider-widget': {} + '@apostrophecms/form-divider-widget': {}, + '@apostrophecms/form-group-widget': {} }; let forms; @@ -38,6 +39,7 @@ describe('Forms module', function () { let booleanWidgets; let conditionalWidgets; let dividerWidgets; + let groupWidgets; it('should be a property of the apos object', async function () { apos = await testUtil.create({ @@ -56,7 +58,22 @@ describe('Forms module', function () { } } }, - '@apostrophecms/form': {}, + '@apostrophecms/form': { + options: { + formWidgets: { + '@apostrophecms/form-text-field': {}, + '@apostrophecms/form-textarea-field': {}, + '@apostrophecms/form-select-field': {}, + '@apostrophecms/form-radio-field': {}, + '@apostrophecms/form-checkboxes-field': {}, + '@apostrophecms/form-file-field': {}, + '@apostrophecms/form-boolean-field': {}, + '@apostrophecms/form-conditional': {}, + '@apostrophecms/form-divider': {}, + '@apostrophecms/form-group': {} + } + } + }, ...formWidgets } }); @@ -73,6 +90,7 @@ describe('Forms module', function () { booleanWidgets = apos.modules[`${aposForm}-boolean-field-widget`]; conditionalWidgets = apos.modules[`${aposForm}-conditional-widget`]; dividerWidgets = apos.modules[`${aposForm}-divider-widget`]; + groupWidgets = apos.modules[`${aposForm}-group-widget`]; assert(forms.__meta.name === `${aposForm}`); assert(widgets.__meta.name === `${aposForm}-widget`); @@ -85,6 +103,7 @@ describe('Forms module', function () { assert(booleanWidgets.__meta.name === `${aposForm}-boolean-field-widget`); assert(conditionalWidgets.__meta.name === `${aposForm}-conditional-widget`); assert(dividerWidgets.__meta.name === `${aposForm}-divider-widget`); + assert(groupWidgets.__meta.name === `${aposForm}-group-widget`); }); // Submissions collection exists. @@ -204,25 +223,30 @@ describe('Forms module', function () { assert(form.title === 'First test form'); }); - it('should have the same widgets in conditional widget areas', function () { - const formWidgets = forms.schema.find(field => { - return field.name === 'contents'; - }).options.widgets; + it('should have the same widgets in conditional widget area as the main form widgets area, execpt conditional itself', function () { + const formWidgets = { + ...forms.schema.find(field => field.name === 'contents').options.widgets + }; - // Main form widgets has the conditional widget as an option. - assert(formWidgets['@apostrophecms/form-conditional']); + const conditionalWidgetWidgets = conditionalWidgets.schema.find(field => field.name === 'contents').options.widgets; - delete formWidgets['@apostrophecms/form-conditional']; + const actual = (Object.keys(formWidgets)).sort(); + const expected = (Object.keys(conditionalWidgetWidgets).concat('@apostrophecms/form-conditional')).sort(); - const condWidgets = conditionalWidgets.schema.find(field => { - return field.name === 'contents'; - }).options.widgets; + assert.deepEqual(actual, expected); + }); - assert(Object.keys(formWidgets).length === Object.keys(condWidgets).length); + it('should have the same widgets in group widget area as the main form widgets area, execpt group itself', function () { + const formWidgets = { + ...forms.schema.find(field => field.name === 'contents').options.widgets + }; - for (const widget in condWidgets) { - assert(formWidgets[widget]); - } + const groupWidgetWidgets = groupWidgets.schema.find(field => field.name === 'contents').options.widgets; + + const actual = (Object.keys(formWidgets)).sort(); + const expected = (Object.keys(groupWidgetWidgets).concat('@apostrophecms/form-group')).sort(); + + assert.deepEqual(actual, expected); }); // Submitting gets 200 response From d2e78ddf7c21d32cb0b95fd1d25b27f8de4542ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harouna=20Traor=C3=A9?= Date: Fri, 27 Oct 2023 15:13:22 +0200 Subject: [PATCH 2/3] fix typos --- i18n/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 6a9ffaf..1a1b6e6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -61,8 +61,8 @@ "group": "Group", "groupAdvanced": "Advanced", "groupAfterSubmission": "After submission", - "groupContents": "Groups Contents", - "groupContentsHelp": "Contains all form widgets excepts groups", + "groupContents": "Group Contents", + "groupContentsHelp": "Contains all form widgets except groups", "groupForm": "Form", "groupLabel": "Group Label", "notFoundForm": "No matching form was found", From 58cb35af5cc6ae80c354b049cb7c95603de06d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harouna=20Traor=C3=A9?= Date: Fri, 27 Oct 2023 15:14:31 +0200 Subject: [PATCH 3/3] fix lint issues --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index e941eea..cb1f1b4 100644 --- a/test/test.js +++ b/test/test.js @@ -245,7 +245,7 @@ describe('Forms module', function () { const actual = (Object.keys(formWidgets)).sort(); const expected = (Object.keys(groupWidgetWidgets).concat('@apostrophecms/form-group')).sort(); - + assert.deepEqual(actual, expected); });