Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #149, dropdown options created from objects are not selected #151

Merged
merged 1 commit into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,16 @@ module.exports = {
* - Birthdate fields that will be showing up relatively soon
* - Time fields?
*/
let base64_name = await scope.base64( scope, var_name );
let base64_var_name = await scope.base64( scope, var_name );

// Will catch some radio and checkbox inputs too, which will then be rejected
// Note: I think `showif`s with `code` don't use `data-saveas`
let to_manipulate = await Promise.race([
scope.page.waitForSelector(`button[name="${base64_name}"][value="${value}"]`), // button
scope.page.waitForSelector(`:not(button)[name="${base64_name}"]`), // others (not showif)
scope.page.waitForSelector(`*[data-saveas="${base64_name}"] input`), // text input showif
scope.page.waitForSelector(`*[data-saveas="${base64_name}"] textarea`), // textarea showif
scope.page.waitForSelector(`*[data-saveas="${base64_name}"] select`), // select showif/hideif
scope.page.waitForSelector(`button[name="${base64_var_name}"][value="${value}"]`), // button
scope.page.waitForSelector(`:not(button)[name="${base64_var_name}"]`), // others (not showif)
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] input`), // text input showif
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] textarea`), // textarea showif
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] select`), // select showif/hideif
]);

// Throw error for checkboxes and radios
Expand Down Expand Up @@ -353,36 +353,36 @@ module.exports = {
let wants_to_sign = set_to === '/sign';

// All the possible variations of name attribute values
let base64_name = await scope.base64( scope, var_name );
let base64_id_of_first_choice = base64_name + '_0';
let base64_var_name = await scope.base64( scope, var_name );
let base64_id_of_first_choice = base64_var_name + '_0';
let { name_attr_B, name_attr_R } = await scope.checkboxNameAttribute( scope, var_name, choice_name );

// Note: I think `showif`s with `code` don't use `data-saveas`
// Note: Choices created without variable names cannot be language agnostic

let selectors = [
`button[name="${ base64_name }"][value="${ choice_name }"]`, // button
`button[name="${ base64_name }"][value="${ set_to }"]`, // button
`*[data-saveas="${ base64_name }"] input`, // text input showif
`*[data-saveas="${ base64_name }"] textarea`, // textarea showif
`*[data-saveas="${ base64_name }"] select`, // select showif/hideif
`button[name="${ base64_var_name }"][value="${ choice_name }"]`, // button
`button[name="${ base64_var_name }"][value="${ set_to }"]`, // button
`*[data-saveas="${ base64_var_name }"] input`, // text input showif
`*[data-saveas="${ base64_var_name }"] textarea`, // textarea showif
`*[data-saveas="${ base64_var_name }"] select`, // select/dropdown showif/hideif
// Radios and checkboxes
// radio: `name` = base64 var name, `choice_name` = var name of choice
// `yesno`/`noyes` checkbox: `name` = base64 var name, choice always 'True'
// checkbox: `name` = base64 var name + stuff + base64 choice var name + stuff (see function)
`input[name="${ base64_name }"][value="${ choice_name }"]`, // radio
`input[name="${ base64_name }"][value="${ set_to }"]`, // radio
`*[data-saveas="${ base64_name }"] input[value="${ choice_name }"]`, // radio showif
`*[data-saveas="${ base64_name }"] input[value="${ set_to }"]`, // radio showif
`input[name="${ base64_name }"][value="True"]`, // yesno/noyes checkbox
`*[data-saveas="${ base64_name }"] input[value="True"]`, // yesno/noyes checkbox showif
`input[name="${ base64_var_name }"][value="${ choice_name }"]`, // radio
`input[name="${ base64_var_name }"][value="${ set_to }"]`, // radio
`*[data-saveas="${ base64_var_name }"] input[value="${ choice_name }"]`, // radio showif
`*[data-saveas="${ base64_var_name }"] input[value="${ set_to }"]`, // radio showif
`input[name="${ base64_var_name }"][value="True"]`, // yesno/noyes checkbox
`*[data-saveas="${ base64_var_name }"] input[value="True"]`, // yesno/noyes checkbox showif
// Finds the group by looking for the first checkbox in the group using id, then works its way back out again
// 'none of the above' checkbox showif???
`input[name="${ name_attr_B }"]`, // checkbox
`input[name="${ name_attr_R }"]`, // checkbox alt
];

let handle = await scope.page.evaluateHandle(({ selectors, base64_id_of_first_choice, base64_name }) => {
let handle = await scope.page.evaluateHandle(({ selectors, base64_id_of_first_choice, base64_var_name }) => {
for ( let selector of selectors ) {
// `set_to` may sometimes not be appropriate for some of the selectors.
// It's a bit of a wild child, but we need to stay true to it so it'll
Expand All @@ -404,15 +404,15 @@ module.exports = {
}

// others (not showif)
let other = document.querySelector(`:not(button)[name="${ base64_name }"]`);
let other = document.querySelector(`:not(button)[name="${ base64_var_name }"]`);
if ( other ) { return other; }

// signature page will need special treatment
let is_signature_page = document.getElementsByClassName('dasignature')[0];
if ( is_signature_page ) { return 'signature'; }

return null;
}, { selectors, base64_id_of_first_choice, base64_name });
}, { selectors, base64_id_of_first_choice, base64_var_name });

// <canvas> can take longer to load. All online signature pages have canvases.
if ( handle.constructor.name !== 'ElementHandle' ) {
Expand Down Expand Up @@ -463,7 +463,18 @@ module.exports = {
await scope.afterStep(scope); // No showifs for this one?
},
SELECT: async function ( scope, { handle, set_to }) {
await handle.select( set_to );
// A dropdown's option value can be one of two things
// Try to find the element using the first value
let option = await scope.page.$(`option[value="${ set_to }"]`);
if ( option ) {
await handle.select( set_to ); // And use that value to set it

// If that value isn't on the page, it should be the second type of value
} else {
let base64_name = await scope.base64( scope, set_to );
await handle.select( base64_name );
}

await scope.afterStep(scope, { waitForShowIf: true });
},
CANVAS: async function ( scope, { handle, set_to }) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docassemble-cucumber",
"version": "1.2.2",
"version": "1.2.2-hf-object-dropdowns.1",
"description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
"main": "lib/index.js",
"scripts": {
Expand Down