From 5f412a721255a906e2913ddb6d3b693889ac2278 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Mon, 17 Jun 2024 14:45:51 -0600 Subject: [PATCH 1/4] Fix "Create a new plan" features test The "Create Plan UI" For DMP Assistant diverges from that of DMP Roadmap. This commit adapts the tests within `spec/features/plans_spec.rb` to work with DMP Assistant's UI and logic. --- spec/features/plans_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/features/plans_spec.rb b/spec/features/plans_spec.rb index ab19e371e3..5a8cb2f082 100644 --- a/spec/features/plans_spec.rb +++ b/spec/features/plans_spec.rb @@ -10,7 +10,7 @@ @org = create(:org) @research_org = create(:org, :organisation, :research_institute, name: 'Test Research Org', templates: 1) - @funding_org = create(:org, :funder, name: 'Test Funder Org', templates: 1) + @funding_org = create(:org, :funder, templates: 1, name: Rails.application.config.default_funder_name) @template = create(:template, org: @org) @user = create(:user, org: @org) sign_in(@user) @@ -32,16 +32,14 @@ # ) end - xit 'User creates a new Plan', :js do - # TODO: Revisit this after we start refactoring/building out or tests for - # the new create plan workflow. For some reason the plans/new.js isn't - # firing here but works fine in the UI with manual testing - # Action + it 'User creates a new Plan', :js do click_link 'Create plan' fill_in :plan_title, with: 'My test plan' choose_suggestion('plan_org_org_name', @research_org) - choose_suggestion('plan_funder_org_name', @funding_org) + within('#plan_template_id') do + select @default_template.title + end click_button 'Create plan' # Expectations @@ -51,6 +49,6 @@ expect(page).to have_css("input[type=text][value='#{@plan.title}']") expect(@plan.title).to eql('My test plan') expect(@plan.org_id).to eql(@research_org.id) - expect(@plan.funder_id).to eql(@funding_org.id) + expect(@plan.template_id).to eql(@default_template.id) end end From c83b307cb0d5e441ba61c62f2e9b214f0bdbf949 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Mon, 17 Jun 2024 15:00:07 -0600 Subject: [PATCH 2/4] Fix spec/features/locales_spec.rb tests (1/2) Copy/paste same file from DMP Roadmap --- spec/features/locales_spec.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/features/locales_spec.rb b/spec/features/locales_spec.rb index 0153fc8a2d..bdbb6d0aa4 100644 --- a/spec/features/locales_spec.rb +++ b/spec/features/locales_spec.rb @@ -12,20 +12,20 @@ [ Language.where( default_language: true, - name: 'English (CA)', - abbreviation: 'en-CA' + name: 'English', + abbreviation: 'en-GB' ).first_or_create, Language.where( default_language: false, - name: 'English (GB)', - abbreviation: 'en-GB' + name: 'German', + abbreviation: 'de' ).first_or_create, Language.where( default_language: false, - name: 'Français (CA)', - abbreviation: 'fr-CA' + name: 'Portugese', + abbreviation: 'pt-BR' ).first_or_create ] @@ -34,7 +34,7 @@ let!(:user) { create(:user, language: languages.first) } before do - locales = %w[en-GB en-CA fr-CA] + locales = %w[en-GB de pt-BR] I18n.available_locales = locales I18n.locale = locales.first sign_in(user) @@ -49,8 +49,10 @@ context 'when new locale has no region' do scenario 'user changes their locale' do - skip 'We are now expecting locales to have region' - create_plan_text = 'Créer des plans' + create_plan_text = I18n.with_locale(:de) do + _('Create plan') + end + click_link 'Language' expect(current_path).to eql(plans_path) expect(page).not_to have_text(create_plan_text) @@ -63,12 +65,14 @@ context 'when new locale has region' do scenario 'user changes their locale' do - create_plan_text = 'Créer des plans' + create_plan_text = I18n.with_locale('pt-BR') do + _('Create plan') + end click_link 'Language' expect(current_path).to eql(plans_path) expect(page).not_to have_text(create_plan_text) - click_link 'Français (CA)' + click_link 'Portugese' expect(current_path).to eql(plans_path) expect(page).to have_text(create_plan_text) end From 1aa9933e9136c157b9249f2c67c55de4a6d0cabe Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Mon, 17 Jun 2024 17:08:18 -0600 Subject: [PATCH 3/4] Fix spec/features/locales_spec.rb tests (2/2) This commit adapts commit da3a9eddb to DMP Assistant. - When selecting a locale, a corresponding `dmp_logo_XX.png` file must be present within the asset pipeline. If the .png file does not exist, an error is encountered. For example, the following is encountered when `click_link 'German'` is executed within this test: ``` Failure/Error: <%= link_to(image_tag(current_locale_logo, ActionView::Template::Error: The asset "dmp_logo_de.png" is not present in the asset pipeline. ``` Thus, this file has been modified to only include the available locales within DMP Assistant. --- spec/features/locales_spec.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/spec/features/locales_spec.rb b/spec/features/locales_spec.rb index bdbb6d0aa4..4ad032abaf 100644 --- a/spec/features/locales_spec.rb +++ b/spec/features/locales_spec.rb @@ -12,20 +12,14 @@ [ Language.where( default_language: true, - name: 'English', - abbreviation: 'en-GB' + name: 'English (CA)', + abbreviation: 'en-CA' ).first_or_create, Language.where( default_language: false, - name: 'German', - abbreviation: 'de' - ).first_or_create, - - Language.where( - default_language: false, - name: 'Portugese', - abbreviation: 'pt-BR' + name: 'Français (CA)', + abbreviation: 'fr-CA' ).first_or_create ] @@ -34,7 +28,7 @@ let!(:user) { create(:user, language: languages.first) } before do - locales = %w[en-GB de pt-BR] + locales = %w[en-CA fr-CA] I18n.available_locales = locales I18n.locale = locales.first sign_in(user) @@ -49,7 +43,7 @@ context 'when new locale has no region' do scenario 'user changes their locale' do - create_plan_text = I18n.with_locale(:de) do + create_plan_text = I18n.with_locale(:'fr-CA') do _('Create plan') end @@ -57,7 +51,7 @@ expect(current_path).to eql(plans_path) expect(page).not_to have_text(create_plan_text) - click_link 'German' + click_link 'Français (CA)' expect(current_path).to eql(plans_path) expect(page).to have_text(create_plan_text) end @@ -65,14 +59,14 @@ context 'when new locale has region' do scenario 'user changes their locale' do - create_plan_text = I18n.with_locale('pt-BR') do + create_plan_text = I18n.with_locale('fr-CA') do _('Create plan') end click_link 'Language' expect(current_path).to eql(plans_path) expect(page).not_to have_text(create_plan_text) - click_link 'Portugese' + click_link 'Français (CA)' expect(current_path).to eql(plans_path) expect(page).to have_text(create_plan_text) end From 8e90edbc408532b9f40a9efe3cd1812c34fabd9c Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Mon, 17 Jun 2024 17:44:40 -0600 Subject: [PATCH 4/4] Set/Override config.default_funder_id for tests The 'User creates a new Plan' test will not pass unless an org exists within the db such that `org.id == Rails.application.config.default_funder_id`. However, we have `config.default_funder_id = Rails.application.secrets.default_funder_id` within `config/application.rb`. This secret is not read while executing the tests via our GitHub actions. Thus, we are overriding/setting that value within the test itself. --- spec/features/plans_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/features/plans_spec.rb b/spec/features/plans_spec.rb index 5a8cb2f082..ccae427cb5 100644 --- a/spec/features/plans_spec.rb +++ b/spec/features/plans_spec.rb @@ -10,7 +10,8 @@ @org = create(:org) @research_org = create(:org, :organisation, :research_institute, name: 'Test Research Org', templates: 1) - @funding_org = create(:org, :funder, templates: 1, name: Rails.application.config.default_funder_name) + @funding_org = create(:org, :funder, templates: 1) + Rails.application.config.default_funder_id = @funding_org.id @template = create(:template, org: @org) @user = create(:user, org: @org) sign_in(@user)