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

[285] Adjust Challenge Phase index query for Evaluators #359

Merged
merged 6 commits into from
Jan 15, 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
11 changes: 7 additions & 4 deletions app/controllers/evaluations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class EvaluationsController < ApplicationController
before_action :set_phase, only: [:submissions]

def index
@challenges = Challenge.joins(phases: :challenge_phases_evaluators).
where(challenge_phases_evaluators: { user_id: current_user.id }).
includes(phases: [:evaluation_form]).
@phases = Phase.joins(:evaluator_submission_assignments).
where(evaluator_submission_assignments: {
user_id: current_user.id,
status: [:assigned, :recused]
}).
includes(:challenge, :evaluation_form).
distinct
end

Expand Down Expand Up @@ -171,4 +174,4 @@ def evaluation_params
end
end
# TODO: Remove this after above refactor
# rubocop:enable all
# rubocop:enable all
56 changes: 26 additions & 30 deletions app/views/evaluations/_phases_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,32 @@
</tr>
</thead>
<tbody>
<% @challenges.each do |challenge| %>
<% challenge.phases.each do |phase| %>
<tr>
<th data-label="Challenge Title" scope="row" class="text-top">
<%= challenge_phase_title(challenge, phase) %>
</th>
<td data-label="Assigned to me" class="text-top">
<%= assigned_submissions_count(current_user, challenge, phase) %>
</td>
<td data-label="Remaining to evaluate" class="text-top">
<%= remaining_evaluations_count(current_user, challenge, phase) %>
</td>
<td data-label="Due by" class="text-top">
<% if phase.evaluation_form %>
<%= phase.evaluation_form.closing_date %>
<% else %>
N/A
<% @phases.each do |phase| %>
<tr>
<th data-label="Challenge Title" scope="row" class="text-top">
<%= challenge_phase_title(phase.challenge, phase) %>
</th>
<td data-label="Assigned to me" class="text-top">
<%= assigned_submissions_count(current_user, phase.challenge, phase) %>
</td>
<td data-label="Remaining to evaluate" class="text-top">
<%= remaining_evaluations_count(current_user, phase.challenge, phase) %>
</td>
<td data-label="Due by" class="text-top">
<% if phase.evaluation_form %>
<%= phase.evaluation_form.closing_date %>
<% else %>
N/A
<% end %>
</td>
<td>
<div class="display-flex flex-column grid-row grid-gap-1 padding-bottom-2">
<%= link_to submissions_evaluation_path(phase), class: "usa-button font-body-2xs text-no-wrap width-full" do %>
View Submissions
<% end %>
</td>
<td>
<div class="display-flex flex-column grid-row grid-gap-1 padding-bottom-2">
<%= link_to submissions_evaluation_path(phase), class: "usa-button font-body-2xs text-no-wrap width-full" do %>
View Submissions
<% end %>
</div>
</div>
</td>
</td>
</tr>
<% end %>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion app/views/evaluations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Evaluations</h1>
<p class="text-normal padding-bottom-2">View challenges with submissions assigned to me to evaluate.</p>

<% if @challenges.empty? %>
<% if @phases.empty? %>
<div class="text-normal">
<p>You currently do not have any challenges.</p>
</div>
Expand Down
96 changes: 96 additions & 0 deletions spec/requests/evaluations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,102 @@
expect(response).to redirect_to(ENV.fetch("PHOENIX_URI", nil))
end
end

context "when logged in as an evaluator" do
let(:evaluator) { create_and_log_in_user(role: 'evaluator') }

let(:challenge_with_submissions) { create(:challenge, title: "Challenge with Submissions", is_multi_phase: false) }
let(:phase_with_submissions) { challenge_with_submissions.phases.first }

let(:multi_phase_challenge) { create(:challenge, title: "Multi-Phase Challenge", is_multi_phase: true) }
let(:phase1) { create(:phase, challenge: multi_phase_challenge) }
let(:phase2) { create(:phase, challenge: multi_phase_challenge) }

let(:challenge_without_submissions) { create(:challenge, title: "Challenge without Submissions", is_multi_phase: false) }
let(:phase_without_submissions) { challenge_without_submissions.phases.first }

before do
ChallengePhasesEvaluator.create!(challenge: challenge_with_submissions, phase: phase_with_submissions, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: multi_phase_challenge, phase: phase1, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: challenge_without_submissions, phase: phase_without_submissions, user: evaluator)
end

it "only shows phases with assigned or recused submissions" do
# Submissions for single phase challenge
assigned_submission = create(:submission, phase: phase_with_submissions, challenge: challenge_with_submissions)
create(:evaluator_submission_assignment,
submission: assigned_submission,
evaluator: evaluator,
status: :assigned
)

recused_submission = create(:submission, phase: phase_with_submissions, challenge: challenge_with_submissions)
create(:evaluator_submission_assignment,
submission: recused_submission,
evaluator: evaluator,
status: :recused
)

unassigned_submission = create(:submission, phase: phase_with_submissions, challenge: challenge_with_submissions)
create(:evaluator_submission_assignment,
submission: unassigned_submission,
evaluator: evaluator,
status: :unassigned
)

recused_unassigned_submission = create(:submission, phase: phase_with_submissions, challenge: challenge_with_submissions)
create(:evaluator_submission_assignment,
submission: recused_unassigned_submission,
evaluator: evaluator,
status: :recused_unassigned
)

# Submissions for multi-phase challenge
multi_phase_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_submission,
evaluator: evaluator,
status: :assigned
)

multi_phase_recused_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_recused_submission,
evaluator: evaluator,
status: :recused
)

multi_phase_unassigned_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_unassigned_submission,
evaluator: evaluator,
status: :unassigned
)

multi_phase_recused_unassigned_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_recused_unassigned_submission,
evaluator: evaluator,
status: :recused_unassigned
)

get evaluations_path

expect(response.body).to include(challenge_with_submissions.title)
expect(response.body).not_to include(challenge_without_submissions.title)

expect(response.body.scan(/data-label="Challenge Title"/).count).to eq(2)
expect(response.body.scan(/#{multi_phase_challenge.title}/).count).to eq(1)

within("#phase_#{phase_with_submissions.id}") do
expect(page).to have_css('td[data-label="Assigned to me"]', text: '2')
end

within("#phase_#{phase1.id}") do
expect(page).to have_css('td[data-label="Assigned to me"]', text: '2')
end
end
end
end

describe "GET /evaluations/:id/submissions" do
Expand Down
Loading