From 5ba2a8f3c862ff2b5a1fa495ea5522b91f3b716f Mon Sep 17 00:00:00 2001 From: blacksmith-welder Date: Tue, 21 Jan 2025 22:14:34 +0200 Subject: [PATCH] Subject edit --- staff_features/shared/step_definitions.rb | 24 ++++++++- .../subjects/step_definitions/subject_edit.rb | 54 +++++++++++++++++++ staff_features/subjects/subject_edit.feature | 18 +++---- 3 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 staff_features/subjects/step_definitions/subject_edit.rb diff --git a/staff_features/shared/step_definitions.rb b/staff_features/shared/step_definitions.rb index 1f281c2..e0504f1 100644 --- a/staff_features/shared/step_definitions.rb +++ b/staff_features/shared/step_definitions.rb @@ -225,6 +225,16 @@ end end +When 'the user clears {string} in the {string} form' do |label, form_title| + section_title = find('h3', text: form_title) + section = section_title.ancestor('section') + expect(section[:id]).to_not eq nil + + within section do + select '', from: label + end +end + When 'the user checks {string}' do |label| check label, match: :first end @@ -234,7 +244,13 @@ end When 'the user changes the {string} field to {string}' do |field, value| - fill_in field, with: value, match: :first + field = find_field(field, match: :first) + + if field.tag_name == 'select' + field.select value.strip + else + field.fill_in with: value + end end When 'the user changes the {string} field' do |field| @@ -255,6 +271,12 @@ expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*updated$/i) end +Then('the {string} saved message is displayed') do |string| + wait_for_ajax if current_url.include? 'resources' + + expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*saved$/i) +end + Then('the {string} deleted message is displayed') do |string| expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*deleted$/i) end diff --git a/staff_features/subjects/step_definitions/subject_edit.rb b/staff_features/subjects/step_definitions/subject_edit.rb new file mode 100644 index 0000000..0d83f25 --- /dev/null +++ b/staff_features/subjects/step_definitions/subject_edit.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +Given 'the Subject appears in the search results list' do + visit "#{STAFF_URL}/subjects" + + fill_in 'filter-text', with: "subject_term_#{@uuid}" + + within '.search-filter' do + find('button').click + end + + search_result_rows = all('#tabledSearchResults tbody tr') + expect(search_result_rows.length).to eq 1 + + within search_result_rows[0] do + element = find('a', text: 'Edit') + + @subject_id = URI.decode_www_form_component(element[:href]).split('/').pop + end +end + +Then 'the Subject is opened in the edit mode' do + uri = current_url.split('/') + + action = uri.pop + subject_id = uri.pop + + expect(action).to eq 'edit' + expect(subject_id).to eq @subject_id +end + +Given 'the Subject is opened in the view mode' do + visit "#{STAFF_URL}/subjects/#{@subject_id}" +end + +Given 'the Subject is opened in edit mode' do + visit "#{STAFF_URL}/subjects/#{@subject_id}/edit" +end + +Given 'the Subject has one Metadata Rights Declarations' do + click_on 'Add Metadata Rights Declaration' + + select 'This record is made available under an Universal 1.0 Public Domain Dedication Creative Commons license.', from: 'License' + + click_on 'Save' + + expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Saved' +end + +Then 'the Subject does not have Metadata Rights Declarations' do + elements = all('#subject_metadata_rights_declarations_ li') + + expect(elements.length).to eq 0 +end diff --git a/staff_features/subjects/subject_edit.feature b/staff_features/subjects/subject_edit.feature index f4cf19a..5669bdc 100644 --- a/staff_features/subjects/subject_edit.feature +++ b/staff_features/subjects/subject_edit.feature @@ -14,20 +14,14 @@ Feature: Subject Edit Given the Subject is opened in edit mode When the user changes the '' field to '' And the user clicks on 'Save' - Then the 'Subject' updated message is displayed + Then the 'Subject' saved message is displayed Then the field '' has value '' Examples: - | Field | NewValue | - | Authority ID | Test Authority ID | - | Scope Note | Test Scope Note | - Scenario: Subject is not updated after changes are reverted + | Field | NewValue | + | Scope Note | Test Scope Note | + Scenario: Subject is not updated Given the Subject is opened in edit mode - When the user changes the 'Term' field - And the user clicks on 'Revert Changes' - Then the Subject Term field has the original value - Scenario: Delete required sub-record of a Subject fails - Given the Subject is opened in edit mode - When the user selects 'empty Source' from 'Source' in the 'Besic Information' form + When the user clears 'Source' in the 'Basic Information' form And the user clicks on 'Save' Then the following error messages are displayed | Source - Property is required but was missing | @@ -37,5 +31,5 @@ Feature: Subject Edit When the user clicks on remove icon in the 'Metadata Rights Declarations' form And the user clicks on 'Confirm Removal' And the user clicks on 'Save' - Then the 'Subject' updated message is displayed + Then the 'Subject' saved message is displayed And the Subject does not have Metadata Rights Declarations