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

test(rspec): rework recently failing tests #7590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions spec/features/course/admin/component_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
enabled_components = course.enabled_components
components.each do |component|
expect(page).to have_selector('label', text: component.display_name)
option = find('label', text: component.display_name).find('input', visible: false)
expect(option.checked?).to be(enabled_components.include?(component))
within find('label', text: component.display_name) do
if enabled_components.include?(component)
expect(page).to have_field(type: 'checkbox', checked: true, visible: false)
else
expect(page).to have_field(type: 'checkbox', checked: false, visible: false)
end
end
end
end

Expand All @@ -31,13 +36,12 @@
control.click
expect_toastify('Your changes have been saved. Refresh to see the new changes.')

option = control.find('input', visible: false)
expect(option).not_to be_checked
expect(control).to have_field(type: 'checkbox', checked: false, visible: false)

control.click
expect_toastify('Your changes have been saved. Refresh to see the new changes.')

expect(option).to be_checked
expect(control).to have_field(type: 'checkbox', checked: true, visible: false)
end
end
end
Expand Down
24 changes: 14 additions & 10 deletions spec/features/course/assessment/submission/past_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
assessment: assessment,
creator: student)
end
# Forum post response questions currently don't show 'Past Answers' element
let(:past_answer_count) do
submission.assessment.questions.reject do |q|
q.question_type == 'ForumPostResponse'
end.count
end

context 'As a Course Student' do
let(:user) { student }

scenario 'I can view my past answers' do
visit edit_course_assessment_submission_path(course, assessment, submission)
past_answers = all('span', text: 'Past Answers')
# Ensure all 'Past Answers' labels are rendered before continuing
expect(page).to have_selector('span', text: 'Past Answers', count: past_answer_count)

expect do
past_answers.each(&:click)
wait_for_page
end.to change { all('label', text: 'Past Answers').count }.by(past_answers.count)
all('span', text: 'Past Answers').each(&:click)
# Label selector matches both the expanded 'Past Answers' section and the labels we clicked
expect(page).to have_selector('label', text: 'Past Answers', count: past_answer_count * 2)
end
end

Expand All @@ -38,12 +44,10 @@

scenario "I can view my student's past answers" do
visit edit_course_assessment_submission_path(course, assessment, submission)
past_answers = all('span', text: 'Past Answers')
expect(page).to have_selector('span', text: 'Past Answers', count: past_answer_count)

expect do
past_answers.each(&:click)
wait_for_page
end.to change { all('label', text: 'Past Answers').count }.by(past_answers.count)
all('span', text: 'Past Answers').each(&:click)
expect(page).to have_selector('label', text: 'Past Answers', count: past_answer_count * 2)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
find('button', text: 'Forum Participation Disbursement').click

within find(content_tag_selector(students[0])) do
expect(find('input').value).to eq('100')
expect(page).to have_field(type: 'text', with: '100')
end

start_date = (4.weeks.ago + 1.minute).strftime('%d-%m-%Y %I:%M')
Expand All @@ -45,26 +45,25 @@
within find('.forum-participation-search-panel') do
find('button.filter-btn-submit').click
end
wait_for_page

# The first student gets 400 (2 * weekly_cap) for the 2-week span since his
# participation score is higher than the rest due to the additional upvote.
within find(content_tag_selector(students[0])) do
expect(find('input').value).to eq('400')
expect(page).to have_field(type: 'text', with: '400')
end
# The other two students get the same experience points because they have the
# same participation score.
within find(content_tag_selector(students[1])) do
expect(find('input').value).to eq('200')
expect(page).to have_field(type: 'text', with: '200')
end
within find(content_tag_selector(students[2])) do
expect(find('input').value).to eq('200')
expect(page).to have_field(type: 'text', with: '200')
end

expect do
find('button.forum-btn-submit').click
wait_for_page
end.to change(Course::ExperiencePointsRecord, :count).by(3)
expect_toastify("Experience points disbursed to #{students.count} recipients.")
end.to change(Course::ExperiencePointsRecord, :count).by(students.count)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/features/system/admin/components_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

within find("tr#component_#{component.key}") do
if enabled_components.include?(component.key.to_s)
expect(page).to have_selector('input:checked', visible: false)
expect(page).to have_field(type: 'checkbox', checked: true, visible: false)
else
expect(page).to have_selector('input:not(:checked)', visible: false)
expect(page).to have_field(type: 'checkbox', checked: false, visible: false)
end
end
end
Expand All @@ -39,11 +39,11 @@

element_to_modify.find('input', visible: false).click
expect_toastify('Instance component setting was updated successfully.')
expect(element_to_modify).to have_selector('input:not(:checked)', visible: false)
expect(element_to_modify).to have_field(type: 'checkbox', checked: false, visible: false)

element_to_modify.find('input', visible: false).click
expect_toastify('Instance component setting was updated successfully.')
expect(element_to_modify).to have_selector('input:checked', visible: false)
expect(element_to_modify).to have_field(type: 'checkbox', checked: true, visible: false)
end
end
end