diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 576789dc..62014e7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,8 +45,6 @@ jobs: run: bundle exec rails assets:precompile - name: Set up database schema run: bin/rails db:schema:load - - name: Set up database schema - run: bin/rails db:seed - name: Copy env file run: cp .env.example .env - name: Run tests diff --git a/.rubocop.yml b/.rubocop.yml index cd7849d3..c6eb01f5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -65,3 +65,7 @@ RSpec/ContextWording: RSpec/ExampleLength: Exclude: - 'spec/features/*' + +RSpec/NoExpectationExample: + Exclude: + - 'spec/features/**/*' diff --git a/app/controllers/system_admin/dashboard_controller.rb b/app/controllers/system_admin/dashboard_controller.rb new file mode 100644 index 00000000..2c9e5b42 --- /dev/null +++ b/app/controllers/system_admin/dashboard_controller.rb @@ -0,0 +1,7 @@ +module SystemAdmin + class DashboardController < ApplicationController + def show + @kpis = Kpis.new + end + end +end diff --git a/app/javascript/packs/stylesheets/custom.scss b/app/javascript/packs/stylesheets/custom.scss new file mode 100644 index 00000000..aef3eea0 --- /dev/null +++ b/app/javascript/packs/stylesheets/custom.scss @@ -0,0 +1,27 @@ +.dashboard { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-gap: 20px; /* Adjust this for your desired gap between columns */ +} + +.kpi-widget { + background-color: #1d70b8; + border-radius: 5px; + padding: 15px; + text-align: center; + + .title { + font-size: 25px; + font-weight: bold; + color: #fff; + } + + .value { + font-size: 70px; + font-weight: bold; + color: #fff; + display: block; + padding: 0; + margin: 0; + } +} diff --git a/app/javascript/packs/stylesheets/govuk.scss b/app/javascript/packs/stylesheets/govuk.scss index 6ff0f057..2a697b78 100644 --- a/app/javascript/packs/stylesheets/govuk.scss +++ b/app/javascript/packs/stylesheets/govuk.scss @@ -1,2 +1,3 @@ -$govuk-assets-path: "~govuk-frontend/govuk/assets/"; -@import "govuk-frontend/govuk/all"; \ No newline at end of file +$govuk-assets-path: '~govuk-frontend/govuk/assets/'; +@import 'govuk-frontend/govuk/all'; +@import 'custom'; diff --git a/app/models/kpis.rb b/app/models/kpis.rb new file mode 100644 index 00000000..aa745c56 --- /dev/null +++ b/app/models/kpis.rb @@ -0,0 +1,9 @@ +class Kpis + def initialize + @applications = Applicant.all + end + + def total_applications + @applications.count + end +end diff --git a/app/views/system_admin/dashboard/show.html.erb b/app/views/system_admin/dashboard/show.html.erb new file mode 100644 index 00000000..d8725da5 --- /dev/null +++ b/app/views/system_admin/dashboard/show.html.erb @@ -0,0 +1,6 @@ +
+
+

Applications

+

<%= @kpis.total_applications %>

+
+
diff --git a/config/routes.rb b/config/routes.rb index fe12906a..d371c82a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,5 +26,6 @@ # TODO: route constraint, only signed-in admins should be able to access scope module: :system_admin, path: "system-admin" do resources :applicants, only: %i[index show edit update] + get "/dashboard", to: "dashboard#show" end end diff --git a/spec/features/admin_console/dashboard_spec.rb b/spec/features/admin_console/dashboard_spec.rb new file mode 100644 index 00000000..88812e72 --- /dev/null +++ b/spec/features/admin_console/dashboard_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "Dashboard" do + include AdminHelpers + + it "shows the Total Applications widget" do + given_there_are_5_applications + given_i_am_signed_as_an_admin + when_i_am_in_the_dashboard_page + then_i_can_see_the_applications_widget + end + + def given_there_are_5_applications + create_list(:applicant, 5) + end + + def when_i_am_in_the_dashboard_page + visit(dashboard_path) + end + + def then_i_can_see_the_applications_widget + within ".kpi-widget.applications" do + expect(page).to have_content("Applications") + expect(page).to have_content("5") + end + end +end diff --git a/spec/models/kpis_spec.rb b/spec/models/kpis_spec.rb new file mode 100644 index 00000000..cd0832dd --- /dev/null +++ b/spec/models/kpis_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +RSpec.describe Kpis do + describe "#total_applications" do + it "returns the total number of applications" do + create_list(:applicant, 5) + + stats = described_class.new + + expect(stats.total_applications).to eq(5) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 409c64b6..c9a6633d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -84,7 +84,7 @@ # # order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run. # # --seed 1234 - # config.order = :random + config.order = :random # # # Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce diff --git a/spec/support/admin_helpers.rb b/spec/support/admin_helpers.rb new file mode 100644 index 00000000..8bc7fa93 --- /dev/null +++ b/spec/support/admin_helpers.rb @@ -0,0 +1,5 @@ +module AdminHelpers + def given_i_am_signed_as_an_admin + page.driver.browser.authorize ENV.fetch("ADMIN_USERNAME", nil), ENV.fetch("ADMIN_PASSWORD", nil) + end +end