diff --git a/lib/scope.js b/lib/scope.js index 07cea98d..c69abe38 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -554,7 +554,7 @@ module.exports = { let field_like_names = await scope.getFieldNamesDict( scope, { $: $ }); // Will deal with `option` once inside `select` - let all_nodes = $( `canvas, fieldset button, .form-group input, .form-group select, .form-group textarea` ); + let all_nodes = $( `canvas, fieldset button, .daquestionactionbutton, .form-group input, .form-group select, .form-group textarea` ); page_data.fields = []; for ( let node of all_nodes ) { @@ -582,6 +582,15 @@ module.exports = { // Often used in the variable name let encoded_name = $node.attr( `name` ); + if ( $( node ).hasClass( 'daquestionactionbutton' ) ) { + let href = node.attribs.href; + let match = href.match( /action=([^&]*)/ ); + if ( match ) { + encoded_name = match[1]; + } else { + throw( `Cannot find the action button on this page. This shouldn't be possible. Talk to the developers.` ); + } + } // ==================== // Table rows @@ -621,7 +630,7 @@ module.exports = { } // ends for every node - if ( page_data.sought_var[0] === `button_continue`) { + if ( page_data.sought_var[0] === `button_event_action`) { // console.log( field_like_names ); // console.log( JSON.stringify( page_data, null, 2 )); } @@ -643,6 +652,7 @@ module.exports = { let selector = `${ node.name }`; // element tag if ( node.attribs.name ) { selector += `[name="${ node.attribs.name }"]`; } if ( node.attribs.value ) { selector += `[value="${ node.attribs.value }"]`; } + if ( $( node ).attr( 'data-linknum' )) { selector += `[data-linknum="${ $( node ).attr( 'data-linknum' ) }"]`; } // Make sure this selector matches only one node let matching_nodes = $( selector ); @@ -730,6 +740,15 @@ module.exports = { layer_1_decoded = field_like_names[ layer_1_decoded ]; } + try { + let action_button_json = JSON.parse( layer_1_decoded ); + if ( action_button_json.action ) { layer_1_decoded = action_button_json.action } + } catch ( error ) { + // Things that are not action buttons can't be parsed this way. + // A special error for action buttons requires passing the node in here too, which is a lot to pass in. + // TODO: Should we move this back into `getPageData()`? + } + // May have the setting value as well as the var_name let checkbox_1_match = layer_1_decoded.match( /^(.*)\[B'(.*)'\]/ ); let checkbox_2_match = layer_1_decoded.match( /^(.*)\[R'(.*)'\]/ ); @@ -816,6 +835,7 @@ module.exports = { return buffer.toString( `base64` ); }, + // TODO: Change name to 'getMatchingRows' getMatchingRow: async function ( scope, { story_table, page_data }) { /* Given html_data and a list of objects describing fields and values, * returns the matching fields and the data necessary to set those values. @@ -880,6 +900,10 @@ module.exports = { case 'textarea': if ( names_match ) { rows_match = true; } break; + + case 'a': + if ( names_match ) { rows_match = true; } + break; } if ( rows_match ) { @@ -891,8 +915,8 @@ module.exports = { } // ends for each field row possibility } // ends for each field - if ( page_data.sought_var[0] === `button_continue`) { - // console.log( JSON.stringify( matches, null, 2 )); + if ( page_data.sought_var[0] === `button_event_action`) { + // console.log( JSON.stringify( matches, null )); } return matches; }, // Ends scope.getMatchingRow() diff --git a/tests/unit_tests/getMatchingRow.test.js b/tests/unit_tests/getMatchingRow.test.js index 4769ba3a..e9a3138c 100644 --- a/tests/unit_tests/getMatchingRow.test.js +++ b/tests/unit_tests/getMatchingRow.test.js @@ -25,7 +25,6 @@ it("matches the right table and field rows for simple show if fields", async fun // `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 ); }); @@ -54,5 +53,9 @@ it("matches the right table and field rows for other mutiple choice continue but expect( result3 ).to.deep.equal( matches.buttons_other_3 ); }); - +// `field:` and `action buttons:` +it(`creates the right data for one continue button`, async function() { + let result1 = await getMatchingRow( scope, { page_data: page_data.buttons_event_action, story_table: tables.buttons_event_action }); + expect( result1 ).to.deep.equal( matches.buttons_event_action ); +}); diff --git a/tests/unit_tests/getPageData.test.js b/tests/unit_tests/getPageData.test.js index f67dc21f..701bbf59 100644 --- a/tests/unit_tests/getPageData.test.js +++ b/tests/unit_tests/getPageData.test.js @@ -52,6 +52,12 @@ it(`creates the right data for other mutiple choice continue buttons`, async fun expect( result ).to.deep.equal( page_data.buttons_other ); }); +it(`creates the right data for an event action button`, async function() { + // `field:` and `action buttons:` + let result = await getPageData( scope, { html: html.buttons_event_action }); + expect( result ).to.deep.equal( page_data.buttons_event_action ); +}); + /* Fields: diff --git a/tests/unit_tests/html.fixtures.js b/tests/unit_tests/html.fixtures.js index 57ab804f..6d9d08eb 100644 --- a/tests/unit_tests/html.fixtures.js +++ b/tests/unit_tests/html.fixtures.js @@ -20,7 +20,6 @@ html.standard = `
Excludes proxy vars (x, i, j, etc.) or choices created with objects.
-