Skip to content

Commit

Permalink
Revert "Revert "Admin management display page""
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoHsuProgrammingLab authored Oct 31, 2024
1 parent 7a95457 commit 22819ef
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ heroku run rails db:seed
* Sai Nithin
* Vinayaka Hegde
* [Legacy Code](https://github.com/tamu-edu-students/csce606-ELRC-Synergistic-Leadership-Theory)


4 changes: 3 additions & 1 deletion rails_root/app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#admins_controller.rb
# frozen_string_literal: true

# admins_controller.rb
class AdminsController < ApplicationController
def index
@survey_responses = SurveyResponse.get_all_responses(page: params[:page], per_page: 20)
Expand Down
3 changes: 3 additions & 0 deletions rails_root/app/helpers/admins_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# frozen_string_literal: true

# helper method for the admin controller
module AdminsHelper
end
8 changes: 4 additions & 4 deletions rails_root/app/models/survey_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class SurveyResponse < ApplicationRecord
belongs_to :profile,
class_name: 'SurveyProfile'

has_many :invitations,
foreign_key: :parent_response_id,
class_name: 'Invitation',
dependent: :destroy
has_many :invitations,
foreign_key: :parent_response_id,
class_name: 'Invitation',
dependent: :destroy

def self.create_from_params(user_id, params)
# FIXME: When we look up things and fail, we should use more descriptive exceptions instead of ActiveRecord::RecordNotFound
Expand Down
28 changes: 16 additions & 12 deletions rails_root/app/views/admins/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
<div class="table-responsive">
<table class = "table">
<thead>
<tr>
<th>ID</th>
<th>Profile</th>
<th>Share Code</th>
<th>Created At</th>
</tr>
<tr>
<th>ID</th>
<th>Profile</th>
<th>Share Code</th>
<th>Created At</th>
<th>View Survey</th>
</tr>
</thead>
<% if @survey_responses.present? %>
<tbody>
<% @survey_responses.each do |response| %>
<tr>
<td><%= response.id %></td>
<td><%= response.profile.user_id %></td>
<td><%= response.share_code %></td>
<td><%= response.created_at.strftime('%Y-%m-%d %H:%M:%S') %></td>
</tr>
<tr>
<td><%= response.id %></td>
<td><%= response.profile.user_id %></td>
<td><%= response.share_code %></td>
<td><%= response.created_at.strftime('%Y-%m-%d %H:%M:%S') %></td>
<td>
<%= link_to 'View Survey', survey_response_path(response) %>
</td>
</tr>
<% end %>
</tbody>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions rails_root/app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<li class="nav-item">
<%= link_to "About", about_path, class: "nav-link #{'active' if current_page?(about_path)}" %>
</li>
<li class="nav-item">
<%= link_to "Admin Dashboard", admin_dashboard_path, class: "nav-link" %> <!-- Admin Dashboard Link -->
</li>

<li class="nav-item">
<%# <%= link_to "Survey Responses", survey_responses_path, class: "nav-link #{'active' if current_page?(survey_responses_path)}" %>
</li>
Expand Down
4 changes: 3 additions & 1 deletion rails_root/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

get 'home/index'
get 'about', to: 'about#index'
get '/admin', to: 'admins#index'
get '/admin', to: 'admins#index', as: 'admin_dashboard'
#get 'survey_responses/:id', to: 'survey_responses#show', as: 'survey_response'


# get 'survey', to: 'survey_responses#new', as: 'survey'
# get 'survey/page/:page', to: 'survey_responses#survey', as: 'survey_page'
Expand Down
12 changes: 12 additions & 0 deletions rails_root/features/admin_management.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Admin Dashboard Access
I want to see the Admin Dashboard link
So that I can access administrative functions

Background:
Given I am on the homepage
And I try to login

Scenario: Principal sees "Admin Dashboard" link and clicks it
Then I should see "Admin Dashboard" in the header
When I click on "Admin Dashboard"
Then I should be on the Admin Dashboard page
29 changes: 29 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,29 @@
# frozen_string_literal: true

# 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:)
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
2 changes: 2 additions & 0 deletions rails_root/spec/helpers/admins_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_helper'

# Specs in this file have access to a helper object that includes
Expand Down
32 changes: 32 additions & 0 deletions rails_root/spec/requests/admin_dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

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
11 changes: 6 additions & 5 deletions rails_root/spec/requests/admins_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe "Admins", type: :request do
describe "GET /index" do
it "returns http success" do
get "/admins/index"
RSpec.describe 'Admins', type: :request do
describe 'GET /index' do
it 'returns http success' do
get '/admins/index'
expect(response).to have_http_status(:success)
end
end

end
4 changes: 3 additions & 1 deletion rails_root/spec/views/admins/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe "admins/index.html.erb", type: :view do
RSpec.describe 'admins/index.html.erb', type: :view do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 22819ef

Please sign in to comment.