Skip to content
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
11 changes: 10 additions & 1 deletion app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle testid-username" href="#" data-bs-toggle="dropdown"
aria-expanded="false" aria-label="User menu for <%= session[:username] %>"><%= session[:username] %></a>
<ul class="dropdown-menu">
<ul class="dropdown-menu" id="user-dropdown-menu">
<%# Guarded with &. because the enclosing condition tests session[:user_id],
but current_user is a find_by that returns nil for a session pointing at a
user who no longer exists. %>
<% if current_user&.admin? %>
<li><h6 class="dropdown-header">Admin Tools</h6></li>
<li><a class="dropdown-item" href="<%= blazer_path %>">Dashboards</a></li>
<li><a class="dropdown-item" href="<%= good_job_path %>">Background Jobs</a></li>
<li><hr class="dropdown-divider"></li>
<% end %>
<li><a class="dropdown-item testid-logout-button" href="/logout/">Logout</a></li>
</ul>
</li>
Expand Down
16 changes: 16 additions & 0 deletions features/navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ Feature: Navigation
And I should see "Login with bCourses" in the navbar
And I should not see "Offerings" in the navbar
And I should not see "Logout" in the navbar

Scenario: Admin user sees admin tools in navbar dropdown
Given a course exists
And I am logged in as an admin
And I am on the "Courses page"
Then I should see "Admin Tools" in the navbar dropdown
And I should see "Dashboards" in the navbar dropdown
And I should see "Background Jobs" in the navbar dropdown

Scenario: Non-admin user does not see admin tools in navbar dropdown
Given a course exists
And I am logged in as a teacher
And I am on the "Courses page"
Then I should not see "Admin Tools" in the navbar dropdown
And I should not see "Dashboards" in the navbar dropdown
And I should not see "Background Jobs" in the navbar dropdown
6 changes: 4 additions & 2 deletions features/step_definitions/custom_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
end
end

Given(/^(?:I am|I'm|I) (?:logged|log) in as a (teacher|ta|student)$/i) do |role|
Given(/^(?:I am|I'm|I) (?:logged|log) in as an? (teacher|ta|student|admin)$/i) do |role|
emails = {
'teacher' => 'user1@berkeley.edu',
'ta' => 'user2@berkeley.edu',
'student' => 'user3@berkeley.edu'
'student' => 'user3@berkeley.edu',
# Not part of `a course exists`, so this is created on demand.
'admin' => 'admin@berkeley.edu'
}
email = emails[role.downcase]
user = User.find_by(email: email) || create(role.to_sym, email: email)
Expand Down
12 changes: 12 additions & 0 deletions features/step_definitions/navigation_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
end
end

Then(/^I should see "(.*?)" in the navbar dropdown$/) do |text|
within('#user-dropdown-menu') do
expect(page).to have_content(text)
end
end

Then(/^I should not see "(.*?)" in the navbar dropdown$/) do |text|
within('#user-dropdown-menu') do
expect(page).not_to have_content(text)
end
end

When(/^I navigate to any page other than the "(.*?)"$/) do |excluded_page|
# Currently included home and courses page
case excluded_page
Expand Down
Loading