Skip to content

Commit

Permalink
step definition and rspec tests cases for admin dashboard access feat…
Browse files Browse the repository at this point in the history
…ure added.
  • Loading branch information
kunal-singh-tamu committed Oct 25, 2024
1 parent ee47412 commit ef3e6b7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rails_root/features/step_definitions/admin_management_steps.rb
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
30 changes: 30 additions & 0 deletions rails_root/spec/requests/admin_dashboard_spec.rb
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

0 comments on commit ef3e6b7

Please sign in to comment.