Skip to content

Commit

Permalink
Add Optional Environment Banner (#212)
Browse files Browse the repository at this point in the history
Currently, if an organization uses Test Track for multiple environments
(e.g. production and stage), it can be a bit difficult to discern at
first glance for which environment a user is managing a given split
test.

This proposed change gives users the option to set a
`DEPLOYMENT_ENV_LABEL` variable in the `.env` or `.env.local` file,
which will subsequently be rendered in a bright red banner, like so:

![Screenshot 2024-03-20 at 5 23
52 PM](https://github.com/Betterment/test_track/assets/67171899/f273fb03-dd86-433d-bd7b-77268bf27ae5)


The banner is intentionally a tad obnoxious to make it glaringly obvious
to the user which environment they are in.

When no `DEPLOYMENT_ENV_LABEL` variable is set, the header renders as
usual:

![Screenshot 2024-03-20 at 5 23
24 PM](https://github.com/Betterment/test_track/assets/67171899/fc01c995-b5d0-40ac-ac97-1421a725c449)


I envision organizations using the existing state for production and the
banner state for a non-production environment (or perhaps vice-versa).
  • Loading branch information
qcannon committed Apr 1, 2024
1 parent 555c0d6 commit 7ba7ebc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $app_width: $container-xl;
@import "typography/base";
@import "typography/utilities";

@import "components/banner";
@import "components/flash";
@import "components/tables";
@import "components/inputs";
Expand Down
16 changes: 16 additions & 0 deletions app/assets/stylesheets/components/_banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.banner {
background-color: #ff6759;
height: 22px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.banner-text {
color: white;
font-size: 13px;
text-transform: uppercase;
font-weight: 500;
margin-bottom: 0;
}
4 changes: 4 additions & 0 deletions app/helpers/application_layout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def page_title
content_for(:page_title) || 'Test Track Admin'
end

def deployment_env_label
ENV.fetch('DEPLOYMENT_ENV_LABEL', nil)
end

def site_layout_header_classes
classes = ['Header']
classes << "color-bg-accent-emphasis"
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
</head>

<body class="<%= site_layout_body_css_classes %>">
<% if deployment_env_label.present? %>
<div class="banner">
<p class="banner-text"><%= deployment_env_label %></p>
</div>
<% end %>
<div class="<%= site_layout_header_classes %>">
<% if content_for?(:header) %>
<%= yield(:header) %>
Expand Down
12 changes: 12 additions & 0 deletions spec/helpers/application_layout_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
end
end

describe '#deployment_env_label' do
it 'returns the value of the DEPLOYMENT_ENV_LABEL environment variable' do
with_env DEPLOYMENT_ENV_LABEL: 'stage' do
expect(helper.deployment_env_label).to eq 'stage'
end
end

it 'returns nil when no DEPLOYMENT_ENV_LABEL environment variable is set' do
expect(helper.deployment_env_label).to be_nil
end
end

describe '#header_modifier' do
context 'when the header_modifier content_for has been provided' do
before do
Expand Down
43 changes: 43 additions & 0 deletions spec/requests/admin/split_details_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

RSpec.describe Admin::SplitsController do
include Warden::Test::Helpers

describe 'GET /admin' do
let(:admin) { FactoryBot.create(:admin) }
let(:deployment_env_label) { 'Stage Environment' }
let(:banner_tag) { "<p class=\"banner-text\">" }

before do
login_as admin
end

context 'when no DEPLOYMENT_ENV_LABEL is set' do
it 'renders without environment label banner' do
get '/admin'

expect(response).to have_http_status :ok

expect(response.body).not_to include(banner_tag)
expect(response.body).not_to include(deployment_env_label)
end
end

context 'when DEPLOYMENT_ENV_LABEL is set' do
around do |example|
with_env DEPLOYMENT_ENV_LABEL: deployment_env_label do
example.run
end
end

it 'renders with environment label banner' do
get '/admin'

expect(response).to have_http_status :ok

expect(response.body).to include(banner_tag)
expect(response.body).to include(deployment_env_label)
end
end
end
end

0 comments on commit 7ba7ebc

Please sign in to comment.