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

Subject Delete #76

Merged
merged 3 commits into from
Feb 5, 2025
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
12 changes: 11 additions & 1 deletion staff_features/shared/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
current_url.include?("digital_objects/#{@digital_object_id}/edit")
end

When 'the user hovers on {string} in the dropdown menu' do |string|
within '.dropdown-menu' do
element = find(:xpath, "//button[contains(text(), '#{string}')] | //a[contains(text(), '#{string}')]")

element.hover
end
end

When 'the user clicks on {string} in the record toolbar' do |string|
within '.record-toolbar' do
click_on_string string
Expand All @@ -73,7 +81,9 @@
When 'the user clicks on {string} in the dropdown menu' do |string|
dropdown_menu = all('.dropdown-menu').first

within dropdown_menu do
dropdown_menus = all('.dropdown-menu')

within dropdown_menus.first do |dropdown_menu|
elements = dropdown_menu.all(:xpath, ".//*[contains(text(), '#{string}')]")

elements.each do |element|
Expand Down
33 changes: 33 additions & 0 deletions staff_features/subjects/step_definitions/subject_delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

When 'the user checks the checkbox of the Subject' do
find('#multiselect-item').check
row = find('tr.selected')
input = row.find('input')
expect(input.value).to include 'subjects'

@subject_id = input.value.split('/').pop
end

Then 'the Subject is deleted' do
expect(@subject_id).to_not eq nil

visit "#{STAFF_URL}/subjects/#{@subject_id}/edit"

expect(find('h2').text).to eq 'Record Not Found'

expected_text = "The record you've tried to access may no longer exist or you may not have permission to view it."
expect(page).to have_text expected_text
end

Given('the user is on the Subject view page') do
visit "#{STAFF_URL}/subjects/#{@subject_id}"
end

Then 'the user is still on the Subject view page' do
expect(find('h2').text).to eq "subject_term_#{@uuid} Subject"
end

Then 'the Subjects page is displayed' do
expect(find('h2').text).to have_text 'Subjects'
end
136 changes: 136 additions & 0 deletions staff_features/subjects/step_definitions/subject_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# frozen_string_literal: true

Given 'a Subject has been created' do
visit "#{STAFF_URL}/subjects/new"

fill_in 'subject_terms__0__term_', with: "subject_term_#{@uuid}"
select 'Art & Architecture Thesaurus', from: 'subject_source_'
select 'Cultural context', from: 'subject_terms__0__term_type_'

click_on 'Save'
expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Created'

uri_parts = current_url.split('/')
uri_parts.pop
@subject_id = uri_parts.pop
end

Then 'the two Subjects are displayed sorted by ascending identifier' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[1]).to have_text @accession_a_uuid
expect(search_result_rows[0]).to have_text @accession_b_uuid
end

Then 'the two Subjects are displayed sorted by ascending level' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[1]).to have_text @accession_a_uuid
expect(search_result_rows[0]).to have_text @accession_b_uuid
end

When 'the user filters by text with the Subject term' do
fill_in 'Filter by text', with: "subject_term_#{@uuid}"

find('#filter-text').send_keys(:enter)

rows = []
checks = 0

while checks < 5
checks += 1

begin
rows = all('tr', text: @uuid)
rescue Selenium::WebDriver::Error::JavascriptError
sleep 1
end

break if rows.length == 1
end
end

Given 'two Subjects have been created with a common keyword in their term' do
@shared_subject_uuid = SecureRandom.uuid
@subject_a_uuid = SecureRandom.uuid
@subject_b_uuid = SecureRandom.uuid

visit "#{STAFF_URL}/subjects/new"
fill_in 'subject_terms__0__term_', with: "Subject A #{@subject_a_uuid} #{@shared_subject_uuid}"
select 'Art & Architecture Thesaurus', from: 'subject_source_'
select 'Cultural context', from: 'subject_terms__0__term_type_'
click_on 'Save'
expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Created'
uri_parts = current_url.split('/')
uri_parts.pop
@subject_a_id = uri_parts.pop

visit "#{STAFF_URL}/subjects/new"
fill_in 'subject_terms__0__term_', with: "Subject B #{@subject_b_uuid} #{@shared_subject_uuid}"
select 'Art & Architecture Thesaurus', from: 'subject_source_'
select 'Cultural context', from: 'subject_terms__0__term_type_'
click_on 'Save'
expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Created'
uri_parts = current_url.split('/')
uri_parts.pop
@subject_b_id = uri_parts.pop
end

Then 'the Subject is in the search results' do
expect(page).to have_css('tr', text: @uuid)
end

Then 'the two Subjects are displayed sorted by descending title' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[1]).to have_text @subject_a_uuid
expect(search_result_rows[0]).to have_text @subject_b_uuid
end

Then 'the Subject view page is displayed' do
expect(find('h2').text).to eq "subject_term_#{@uuid} Subject"
expect(current_url).to eq "#{STAFF_URL}/subjects/#{@subject_id}"
end

Given 'the two Subjects are displayed sorted by ascending term' do
visit "#{STAFF_URL}/subjects"

fill_in 'filter-text', with: @shared_subject_uuid

within '.search-filter' do
find('button').click
end

search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[0]).to have_text @subject_a_uuid
expect(search_result_rows[1]).to have_text @subject_b_uuid
end

Then 'the two Subjects are displayed sorted by descending term' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[1]).to have_text @subject_a_uuid
expect(search_result_rows[0]).to have_text @subject_b_uuid
end

Then 'the two Subjects are displayed sorted by ascending created date' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[0]).to have_text @subject_a_uuid
expect(search_result_rows[1]).to have_text @subject_b_uuid
end

Then 'the two Subjects are displayed sorted by ascending modified date' do
search_result_rows = all('#tabledSearchResults tbody tr')

expect(search_result_rows.length).to eq 2
expect(search_result_rows[0]).to have_text @subject_a_uuid
expect(search_result_rows[1]).to have_text @subject_b_uuid
end
25 changes: 25 additions & 0 deletions staff_features/subjects/subject_delete.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Subject Delete
Background:
Given an administrator user is logged in
And a Subject has been created
Scenario: Subject is deleted from the search results
When the user clicks on 'Browse'
And the user clicks on 'Subjects'
And the user filters by text with the Subject term
And the user checks the checkbox of the Subject
And the user clicks on 'Delete'
And the user clicks on 'Delete Records'
Then the 'Subjects' deleted message is displayed
And the Subject is deleted
Scenario: Subject is deleted from the view page
Given the user is on the Subject view page
When the user clicks on 'Delete'
And the user clicks on 'Delete' in the modal
Then the Subjects page is displayed
And the 'Subject' deleted message is displayed
And the Subject is deleted
Scenario: Cancel Subject delete from the view page
Given the user is on the Subject view page
When the user clicks on 'Delete'
And the user clicks on 'Cancel'
Then the user is still on the Subject view page
35 changes: 35 additions & 0 deletions staff_features/subjects/subject_view.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Subject View
Background:
Given an administrator user is logged in
Scenario: Search Subject by title
Given a Subject has been created
When the user clicks on 'Browse'
And the user clicks on 'Subjects'
And the user filters by text with the Subject term
Then the Subject is in the search results
Scenario: View Subject from the search results
Given a Subject has been created
When the user clicks on 'Browse'
And the user clicks on 'Subjects'
And the user filters by text with the Subject term
And the user clicks on 'View'
Then the Subject view page is displayed
Scenario: Sort Subjects by term
Given two Subjects have been created with a common keyword in their term
And the two Subjects are displayed sorted by ascending term
When the user clicks on 'Terms'
Then the two Subjects are displayed sorted by descending term
Scenario: Sort Subjects by date created
Given two Subjects have been created with a common keyword in their term
And the two Subjects are displayed sorted by ascending term
When the user clicks on 'Terms Ascending'
And the user hovers on 'Created' in the dropdown menu
And the user clicks on 'Ascending' in the dropdown menu
Then the two Subjects are displayed sorted by ascending created date
Scenario: Sort Subjects by modified date
Given two Subjects have been created with a common keyword in their term
And the two Subjects are displayed sorted by ascending term
When the user clicks on 'Terms Ascending'
And the user hovers on 'Modified' in the dropdown menu
And the user clicks on 'Ascending' in the dropdown menu
Then the two Subjects are displayed sorted by ascending modified date
Loading