-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
032c55f
commit 53ccbde
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'Score', js: true do | ||
let(:exercise) { create(:hello_world) } | ||
let(:user) { create(:external_user) } | ||
let(:scoring_response_full_score) do | ||
[{ | ||
status: :ok, | ||
stdout: '', | ||
stderr: '', | ||
waiting_for_container_time: 0, | ||
container_execution_time: 0, | ||
file_role: 'teacher_defined_test', | ||
count: 1, | ||
failed: 0, | ||
error_messages: [], | ||
passed: 1, | ||
score: 1.0, | ||
filename: 'index.html_spec.rb', | ||
message: 'Well done.', | ||
weight: 2.0, | ||
}] | ||
end | ||
let(:scoring_response_zero_points) do | ||
[{ | ||
status: :ok, | ||
stdout: '', | ||
stderr: '', | ||
waiting_for_container_time: 0, | ||
container_execution_time: 0, | ||
file_role: 'teacher_defined_test', | ||
count: 1, | ||
failed: 0, | ||
error_messages: [], | ||
passed: 1, | ||
score: 0.0, | ||
filename: 'index.html_spec.rb', | ||
message: 'Well done.', | ||
weight: 2.0, | ||
}] | ||
end | ||
|
||
before do | ||
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) | ||
end | ||
|
||
context 'when LTI outcomes are supported' do | ||
before do | ||
allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true) | ||
visit(implement_exercise_path(exercise)) | ||
allow(Submission).to receive(:find).and_return(submission) | ||
allow(submission).to receive(:calculate_score).and_return(scoring_response) | ||
allow(submission).to receive(:normalized_score).and_return(normalized_score) | ||
allow_any_instance_of(SubmissionsController).to receive(:send_score).and_return(status:, score_sent: sent_score) | ||
click_button(I18n.t('exercises.editor.score')) | ||
end | ||
|
||
context 'when the full score is reached' do | ||
let(:submission) { create(:submission, exercise:, user:, score: 1.0) } | ||
let(:scoring_response) { scoring_response_full_score } | ||
let(:normalized_score) { 1 } | ||
let(:sent_score) { 1 } | ||
|
||
context 'when scoring is successful' do | ||
let(:status) { 'success' } | ||
|
||
it 'shows a full score notification' do | ||
# Text needs to be split because it includes the embedded url in Html which is not shown in the notification | ||
# We only compare the shown notification text | ||
expect(page).to have_content(I18n.t('exercises.submit.full_score').split('.').first) | ||
expect(page).to have_link(nil, href: redirect_after_submit_submission_path(submission)) | ||
end | ||
end | ||
|
||
context 'when scoring is to late' do | ||
let(:normalized_score) { 0.7 } | ||
let(:status) { 'success' } | ||
|
||
it 'shows a scoring to late notification' do | ||
expect(page).to have_content(I18n.t('exercises.submit.too_late')) | ||
end | ||
end | ||
|
||
context 'when scoring fails' do | ||
let(:status) { 'error' } # unsupported also works | ||
|
||
it 'shows a scoring failure notification' do | ||
expect(page).to have_content(I18n.t('exercises.submit.failure')) | ||
end | ||
end | ||
end | ||
|
||
context 'when full score is not reached' do | ||
let(:submission) { create(:submission, exercise:, user:, score: 0.0) } | ||
let(:scoring_response) { scoring_response_zero_points } | ||
let(:normalized_score) { 0 } | ||
let(:status) { 'success' } | ||
let(:sent_score) { 0 } | ||
end | ||
end | ||
|
||
context 'when LTI outcomes are not supported' do | ||
before do | ||
allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(false) | ||
visit(implement_exercise_path(exercise)) | ||
click_button(I18n.t('exercises.editor.score')) | ||
sleep 10 | ||
end | ||
|
||
it 'does not send scores' do | ||
expect_any_instance_of(SubmissionsController).not_to receive(:send_score) | ||
end | ||
|
||
it 'shows execution environments full notification' do | ||
expect(page).to have_content(I18n.t('exercises.editor.depleted')) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters