Skip to content

Commit

Permalink
Subject View (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdimopulu authored Feb 5, 2025
1 parent 7caae0a commit 3fed532
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 1 deletion.
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
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
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

0 comments on commit 3fed532

Please sign in to comment.