-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
step definition and rspec tests cases for admin dashboard access feat…
…ure added.
- Loading branch information
1 parent
ee47412
commit ef3e6b7
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
rails_root/features/step_definitions/admin_management_steps.rb
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,27 @@ | ||
# Step definition for navigating to the homepage | ||
Given('I am on the homepage') do | ||
visit root_path | ||
expect(page).to have_current_path(root_path) # Ensure the user is on the homepage | ||
end | ||
|
||
Given('I have logged in as a {string}') do |role| | ||
# Create a user with the specified role (principal, teacher, superintendent) | ||
@user = FactoryBot.create(:survey_profile, role: role) | ||
allow_any_instance_of(ApplicationController).to receive(:current_user_id).and_return(@user.user_id) | ||
end | ||
|
||
Then('I should see {string} in the header') do |link_text| | ||
# Check that the Admin Dashboard link is present | ||
expect(page).to have_link(link_text) | ||
end | ||
|
||
When('I click on {string}') do |link_text| | ||
# Click the Admin Dashboard link | ||
click_link(link_text) | ||
end | ||
|
||
Then('I should be on the Admin Dashboard page') do | ||
# Verify that the user is redirected to the Admin Dashboard page | ||
expect(current_path).to eq(admin_dashboard_path) | ||
expect(page).to have_content('Admin Dashboard') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "Admin Dashboard Access", type: :request do | ||
# Create a user with the principal role (you can change this to other roles if needed) | ||
let(:user) { FactoryBot.create(:survey_profile, role: 'Teacher') } | ||
|
||
before do | ||
allow_any_instance_of(SurveyResponsesController).to receive(:current_user_id).and_return(user.user_id) | ||
end | ||
|
||
describe "GET / (Homepage)" do | ||
it "displays the Admin Dashboard link in the header" do | ||
# Visit the homepage | ||
get root_path | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(response.body).to include('Admin Dashboard') | ||
end | ||
end | ||
|
||
describe "GET /admin_dashboard" do | ||
it "redirects to the Admin Dashboard page when clicked" do | ||
# Visit the Admin Dashboard page | ||
get admin_dashboard_path | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(response.body).to include('Admin Dashboard') | ||
end | ||
end | ||
end |