Skip to content

Conversation

@johnpinto1
Copy link
Contributor

@johnpinto1 johnpinto1 commented Mar 10, 2025

THIS PR IS GOING TO BE RECREATED WITH RAILS 7 CODE. SO CLOSING THIS.

A Conditional Question (with action: "remove" and in a Phase with multiple sections) for this bug can be described structurally as follows:

Conditional Question: Q2. Will your data be open?,
    Answer Options: "Yes", "No", "Don't Know"
   
    If answer "Yes", then 
        [Action: "remove",
               [Section 1, Q5. What data will be publicly shared?],
               [Section 2, Q12. What type of organisations will you share your data?]
        ]
    Else if answer "No"
        [ Action: "remove",
               [Section 1, "Q7. Under what licence will be the data/code released?"]
               [Section 2, "Q25. Which persons/organisations will you share your data with?],
               [ Section 3, "Q30. Will your data be placed in a research data repository?"]]
   Else if answer "Don't know"
      Do nothing.

Bug Description:
Currently in the code if we answer several questions in a phase in various sections, then subsequently answer an option of a Conditional question that removes some of the questions answered. The removed answers are hidden in UI, but the answers to the hidden questions remain persisted in the database and are hidden in the UI, not cleared. As a result if we change our answer to the same Conditional Question the removed questions with the "stale/old" answers reappear.

Expected Behavior
We would expect the removed questions answers to be deleted from the database and cleared from the UI. So if we change our answer to the same Conditional Question the removed questions should reappear without the "stale/old" answers. Further the removed questions could be in different sections in phase.

Testing
Attached is a script for testing in your development environment and running the content in a Rails console.
Test_script_for_setup_template_with_conditional_question.txt

We found convenient to use the seeds file to populate the database as follows:

➜ bin/rails db:environment:set RAILS_ENV=development
➜ rails db:schema:load
➜ rails db:seed

We then brought up a Rails console and ran the content of the test script by copying and pasting.
Selection_054

  1. We switch to development branch to view the bug by following test suggestions below.
  2. Next we switch fix-for-conditional-question-removed-answers-not-being-deleted branch to test if it has been resolved.

You can view the template we created as the Admin User you logged in as.
Selection_053

Here is the structure of the conditional question we are testing, namely question
"Q2. Will your data be open? THE CONDITIONAL QUESTION"

Selection_052

Testing suggestions
With each branch login as user with email: [email protected] and password: password123 .

Create a plan with organisation Conditional Tests Organisation and no funder, e.g.,

Selection_051

Then fill in answers to following sets of questions:

  1. Q5 (checkbox), Q9 (radiobuttons), Q14 (textarea), Q17 (text), Q18 (date), Q20 (dropdown) (which will be removed by condition option Yes)
  2. Q6 (dropdown), Q7 (textarea), Q10 (text), Q11 (date), Q16 (radiobuttons), Q19 (checkbox)) (which will be removed by condition option No)

You can use the same plan for both branches. You just need to fill in the values again to test each time.

Now answer question "Q2. Will your data be open? THE CONDITIONAL QUESTION" with
Yes, No and Don't know

Selection_055

As mentioned above, the branch for issue, should show the expected behaviour:

We would expect the removed questions answers to be deleted from the database and cleared from the UI. So if we change our answer to the same Conditional Question the removed questions should reappear without the "stale/old" answers. Further the removed questions could be in different sections in phase.

John Pinto added 2 commits March 7, 2025 11:02
     In the case of a conditional question with answers that removed questions from different sections of a phase, any answers of removed questions were not removed, just hidden. Nor were the removed answers deleted in the database.

        Changes:
        - Fixed the broken functionality.

Rspec tests updated in next commit.
@github-actions
Copy link

1 Warning
⚠️ This PR is too big! Consider breaking it down into smaller PRs.

Generated by 🚫 Danger

@johnpinto1 johnpinto1 marked this pull request as draft March 11, 2025 16:33
@johnpinto1 johnpinto1 self-assigned this Mar 11, 2025
@johnpinto1
Copy link
Contributor Author

THIS PR IS GOING TO BE RECREATED WITH RAILS 7 CODE. SO CLOSING THIS.

@johnpinto1 johnpinto1 closed this Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants