diff --git a/lib/scope.js b/lib/scope.js index 3fda90bc..07cea98d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -621,7 +621,7 @@ module.exports = { } // ends for every node - if ( page_data.sought_var[0] === `buttons_other`) { + if ( page_data.sought_var[0] === `button_continue`) { // console.log( field_like_names ); // console.log( JSON.stringify( page_data, null, 2 )); } @@ -891,7 +891,7 @@ module.exports = { } // ends for each field row possibility } // ends for each field - if ( page_data.sought_var[0] === `buttons_other`) { + if ( page_data.sought_var[0] === `button_continue`) { // console.log( JSON.stringify( matches, null, 2 )); } return matches; diff --git a/tests/unit_tests/getMatchingRow.test.js b/tests/unit_tests/getMatchingRow.test.js index 6212a570..4769ba3a 100644 --- a/tests/unit_tests/getMatchingRow.test.js +++ b/tests/unit_tests/getMatchingRow.test.js @@ -14,22 +14,24 @@ const getMatchingRow = scope.getMatchingRow; // ============================ // TODO: Add more complex fields. E.g `object_checkboxes` and dropdown with `object`. it("matches the right table and field rows for standard fields", async function() { - let result = await getMatchingRow( scope, { page_data: page_data.standard, story_table: tables.standard }); expect( result ).to.deep.equal( matches.standard ); - }); it("matches the right table and field rows for simple show if fields", async function() { - let result = await getMatchingRow( scope, { page_data: page_data.show_if, story_table: tables.show_if }); expect( result ).to.deep.equal( matches.show_if ); - }); +// `continue button field:` +it(`creates the right data for one continue button`, async function() { + // `continue button field:` + let result1 = await getMatchingRow( scope, { page_data: page_data.button_continue, story_table: tables.button_continue }); + expect( result1 ).to.deep.equal( matches.button_continue ); +}); +// `yesnomaybe:` it("matches the right table and field rows for yesnomaybe buttons", async function() { - let result1 = await getMatchingRow( scope, { page_data: page_data.buttons_yesnomaybe, story_table: tables.buttons_yesnomaybe_yes }); expect( result1 ).to.deep.equal( matches.buttons_yesnomaybe_yes ); @@ -38,12 +40,10 @@ it("matches the right table and field rows for yesnomaybe buttons", async functi let result3 = await getMatchingRow( scope, { page_data: page_data.buttons_yesnomaybe, story_table: tables.buttons_yesnomaybe_none }); expect( result3 ).to.deep.equal( matches.buttons_yesnomaybe_none ); - }); - +// `field:` and `buttons:` it("matches the right table and field rows for other mutiple choice continue buttons", async function() { - let result1 = await getMatchingRow( scope, { page_data: page_data.buttons_other, story_table: tables.buttons_other_1 }); expect( result1 ).to.deep.equal( matches.buttons_other_1 ); @@ -52,7 +52,6 @@ it("matches the right table and field rows for other mutiple choice continue but let result3 = await getMatchingRow( scope, { page_data: page_data.buttons_other, story_table: tables.buttons_other_3 }); expect( result3 ).to.deep.equal( matches.buttons_other_3 ); - }); diff --git a/tests/unit_tests/getPageData.test.js b/tests/unit_tests/getPageData.test.js index a6d42ad5..f67dc21f 100644 --- a/tests/unit_tests/getPageData.test.js +++ b/tests/unit_tests/getPageData.test.js @@ -34,12 +34,20 @@ it(`creates the right data for 'show if' fields`, async function() { expect( result ).to.deep.equal( page_data.show_if ); }); +it(`creates the right data for one continue button`, async function() { + // `continue button field:` + let result = await getPageData( scope, { html: html.button_continue }); + expect( result ).to.deep.equal( page_data.button_continue ); +}); + it(`creates the right data for yesnomaybe buttons`, async function() { + // `yesnomaybe:` let result = await getPageData( scope, { html: html.buttons_yesnomaybe }); expect( result ).to.deep.equal( page_data.buttons_yesnomaybe ); }); it(`creates the right data for other mutiple choice continue buttons`, async function() { + // `field:` and `buttons:` let result = await getPageData( scope, { html: html.buttons_other }); expect( result ).to.deep.equal( page_data.buttons_other ); }); diff --git a/tests/unit_tests/html.fixtures.js b/tests/unit_tests/html.fixtures.js index a9505386..57ab804f 100644 --- a/tests/unit_tests/html.fixtures.js +++ b/tests/unit_tests/html.fixtures.js @@ -326,6 +326,31 @@ html.show_if = ` // ============================ // Buttons // ============================ +// `continue button field:` +html.button_continue = ` +
+
+
+

Button (continue)

+
+
+ +
+ Press one of the following buttons: +
+
+
+ + + + + + + +
+
`; + +// `yesnomaybe:` html.buttons_yesnomaybe = `
@@ -353,6 +378,7 @@ html.buttons_yesnomaybe = `
`; // Multiple choice 'continue' button fields that are not yesnomaybe +// `field:` and `buttons:` html.buttons_other = `
@@ -369,7 +395,7 @@ html.buttons_other = ` - + diff --git a/tests/unit_tests/matches.fixtures.js b/tests/unit_tests/matches.fixtures.js index be25b42f..b452ba2d 100644 --- a/tests/unit_tests/matches.fixtures.js +++ b/tests/unit_tests/matches.fixtures.js @@ -127,6 +127,15 @@ matches.show_if = [ // ============================ // Buttons // ============================ +// `continue button field:` +matches.button_continue = [ + { + "field": { "selector": "button[name=\"YnV0dG9uX2NvbnRpbnVl\"][value=\"True\"]", "tag": "button", "rows": [ { "var_name": "button_continue", "value": "True", "checked": false } ], "type": "submit" }, + "table": { "var_name": "button_continue", "value": "True", "checked": true, }, + } +]; + +// `yesnomaybe:` matches.buttons_yesnomaybe_yes = [ { "field": { "selector": "button[name=\"YnV0dG9uc195ZXNub21heWJl\"][value=\"True\"]", "tag": "button", "rows": [ { "var_name": "buttons_yesnomaybe", "value": "True", "checked": false, } ], "type": "submit" }, @@ -146,7 +155,7 @@ matches.buttons_yesnomaybe_none = [ } ]; - +// `field:` and `buttons:` matches.buttons_other_1 = [ { "field": { "selector": "button[name=\"YnV0dG9uc19vdGhlcg\"][value=\"button_1\"]", "tag": "button", "rows": [ { "var_name": "buttons_other", "value": "button_1", "checked": false, } ], "type": "submit" }, diff --git a/tests/unit_tests/page_data.fixtures.js b/tests/unit_tests/page_data.fixtures.js index 5f5fe575..d6a116d8 100644 --- a/tests/unit_tests/page_data.fixtures.js +++ b/tests/unit_tests/page_data.fixtures.js @@ -384,6 +384,28 @@ page_data.show_if = { // ============================ // Buttons // ============================ +// `continue button field:` +page_data.button_continue = { + "sought_var": [ + "button_continue" + ], + "fields": [ + { + "selector": "button[name=\"YnV0dG9uX2NvbnRpbnVl\"][value=\"True\"]", + "tag": "button", + "rows": [ + { + "var_name": "button_continue", + "value": "True", + "checked": false + } + ], + "type": "submit" + } + ] +}; + +// `yesnomaybe:` // TODO: Shall we allow 'maybe' in the table as a value for `None`? page_data.buttons_yesnomaybe = { "sought_var": [ @@ -430,6 +452,7 @@ page_data.buttons_yesnomaybe = { }; // Multiple choice 'continue' button fields that are not yesnomaybe +// `field:` and `buttons:` page_data.buttons_other = { "sought_var": [ "buttons_other" diff --git a/tests/unit_tests/tables.fixtures.js b/tests/unit_tests/tables.fixtures.js index 967ee416..146dfcbc 100644 --- a/tests/unit_tests/tables.fixtures.js +++ b/tests/unit_tests/tables.fixtures.js @@ -49,6 +49,12 @@ tables.show_if = [ // ============================ // Buttons // ============================ +// `continue button field:` +tables.button_continue = [ + { "var_name": "button_continue", "value": "True", "checked": true, }, // May want to change `checked` +]; + +// `yesnomaybe:` tables.buttons_yesnomaybe_yes = [ { "var_name": "buttons_yesnomaybe", "value": "True", "checked": true, }, // May want to change `checked` ]; @@ -59,6 +65,7 @@ tables.buttons_yesnomaybe_none = [ { "var_name": "buttons_yesnomaybe", "value": "None", "checked": true, }, // May want to change `checked` ]; +// `field:` and `buttons:` tables.buttons_other_1 = [ { "var_name": "buttons_other", "value": "button_1", "checked": true, }, // May want to change `checked` ];