Commit 3fd4fe97 authored by Robert Hunt's avatar Robert Hunt

MR review feedback

- Restructure expiry date partial to receive the credential object
- Restructure expiry date partial to be clearer
- Changed PAT and SSH partials to have slightly wider columns and pass
in the credential object
- Updated specs to use TestHelper rather than Timecop
- Updated specs to use before_all rather than before
- Updated multiple expect specs to use :aggregate_failures
parent 57edb519
- if expiry_date&.past? || expiry_date&.today?
%span.d-inline-flex.align-items-center.text-danger.has-tooltip{ title: _('This credential has expired'), data: { testid: 'expiry-date-icon' } }
= sprite_icon('error', size: 16, css_class: "gl-icon mr-1")
= expiry_date.to_date
- if credential.expires?
- expiry_date = credential.expires_at.to_date
- date_classes = 'd-flex align-items-center has-tooltip h-100 justify-content-end justify-content-md-start'
- elsif expiry_date.present?
- if expires_soon
%span.d-inline-flex.align-items-center.text-warning{ data: { testid: 'expiry-date-icon' } }
- if credential.expired?
%span{ class: date_classes + ' text-danger', title: _('This credential has expired'), data: { testid: 'expiry-date-icon' } }
= sprite_icon('error', size: 16, css_class: "gl-icon mr-1")
= expiry_date
- elsif credential.expires_soon?
%span{ class: date_classes + ' text-warning', data: { testid: 'expiry-date-icon' } }
= sprite_icon('warning', size: 16, css_class: "gl-icon mr-1")
= expiry_date.to_date
= expiry_date
- else
= expiry_date.to_date
= expiry_date
- else
= _('Never')
.table-holder
.thead-white.text-nowrap.gl-responsive-table-row.table-row-header{ role: 'row' }
.table-section.section-40{ role: 'rowheader' }= _('Owner')
.table-section.section-30{ role: 'rowheader' }= _('Scope')
.table-section.section-10{ role: 'rowheader' }= _('Created On')
.table-section.section-10{ role: 'rowheader' }= _('Expiration')
.table-section.section-10{ role: 'rowheader' }= _('Revoked')
.table-section.section-20{ role: 'rowheader' }= _('Scope')
.table-section.section-15{ role: 'rowheader' }= _('Created On')
.table-section.section-15{ role: 'rowheader' }= _('Expiration')
.table-section.section-15{ role: 'rowheader' }= _('Revoked')
= render partial: 'shared/credentials_inventory/personal_access_tokens/personal_access_token', collection: credentials
......@@ -4,22 +4,22 @@
= _('Owner')
.table-mobile-content
= render 'shared/credentials_inventory/users/user_detail', user: personal_access_token.user
.table-section.section-30
.table-section.section-20
.table-mobile-header{ role: 'rowheader' }
= _('Scope')
.table-mobile-content.ws-normal
- scopes = personal_access_token.scopes
= scopes.present? ? scopes.join(", ") : _('No Scopes')
.table-section.section-10
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Created On')
.table-mobile-content
= personal_access_token.created_at.to_date
.table-section.section-10
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Expiration')
.table-mobile-content
= render 'shared/credentials_inventory/expiry_date', expiry_date: personal_access_token.expires_at, expires_soon: personal_access_token.expires_soon?
.table-mobile-content.h-100
= render 'shared/credentials_inventory/expiry_date', credential: personal_access_token
.table-section.section-10
.table-mobile-header{ role: 'rowheader' }
= _('Revoked')
......
......@@ -17,5 +17,5 @@
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Expiration')
.table-mobile-content
= render 'shared/credentials_inventory/expiry_date', expiry_date: ssh_key.expires_at, expires_soon: ssh_key.expires_soon?
.table-mobile-content.h-100
= render 'shared/credentials_inventory/expiry_date', credential: ssh_key
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'credentials inventory expiry date' do
it 'shows the expiry date' do
visit credentials_path
......@@ -9,22 +11,34 @@ RSpec.shared_examples 'credentials inventory expiry date' do
end
RSpec.shared_examples 'credentials inventory expiry date before' do
before do
travel_to(date_time)
end
after do
travel_back
end
it 'shows the expiry without any warnings' do
Timecop.freeze(20.days.ago) do
visit credentials_path
visit credentials_path
expect(first_row).not_to have_selector('[data-testid="expiry-date-icon"]')
end
expect(first_row).not_to have_selector('[data-testid="expiry-date-icon"]')
end
end
RSpec.shared_examples 'credentials inventory expiry date close or past' do
before do
travel_to(date_time)
end
after do
travel_back
end
it 'adds a warning to the expiry date' do
Timecop.freeze(date_time) do
visit credentials_path
visit credentials_path
expect(first_row).to have_selector('[data-testid="expiry-date-icon"]', class: css_class)
end
expect(first_row).to have_selector('[data-testid="expiry-date-icon"]', class: css_class)
end
end
......@@ -32,17 +46,19 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
let_it_be(:user) { group_managed_account ? managed_user : create(:user, name: 'David') }
context 'when a personal access token is active' do
before do
before_all do
create(:personal_access_token,
user: user,
created_at: '2019-12-10',
updated_at: '2020-06-22',
expires_at: nil)
end
before do
visit credentials_path
end
it 'shows the details with no revoked date' do
it 'shows the details with no revoked date', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('api')
expect(first_row.text).to include('2019-12-10')
......@@ -52,9 +68,9 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
end
context 'when a personal access token has an expiry' do
let(:expiry_date) { 1.day.since.to_date.to_s }
let_it_be(:expiry_date) { 1.day.since.to_date.to_s }
before do
before_all do
create(:personal_access_token,
user: user,
created_at: '2019-12-10',
......@@ -63,6 +79,8 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
end
context 'and is not expired' do
let(:date_time) { 20.days.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date before'
end
......@@ -85,18 +103,20 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
end
context 'when a personal access token is revoked' do
before do
before_all do
create(:personal_access_token,
:revoked,
user: user,
created_at: '2019-12-10',
updated_at: '2020-06-22',
expires_at: nil)
end
before do
visit credentials_path
end
it 'shows the details with a revoked date' do
it 'shows the details with a revoked date', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('api')
expect(first_row.text).to include('2019-12-10')
......@@ -109,17 +129,19 @@ RSpec.shared_examples_for 'credentials inventory SSH keys' do |group_managed_acc
let_it_be(:user) { group_managed_account ? managed_user : create(:user, name: 'David') }
context 'when a SSH key is active' do
before do
before_all do
create(:personal_key,
user: user,
created_at: '2019-12-09',
last_used_at: '2019-12-10',
expires_at: nil)
end
before do
visit credentials_path
end
it 'shows the details with no expiry' do
it 'shows the details with no expiry', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('2019-12-09')
expect(first_row.text).to include('2019-12-10')
......@@ -128,9 +150,9 @@ RSpec.shared_examples_for 'credentials inventory SSH keys' do |group_managed_acc
end
context 'when a SSH key has an expiry' do
let(:expiry_date) { 1.day.since.to_date.to_s }
let_it_be(:expiry_date) { 1.day.since.to_date.to_s }
before do
before_all do
create(:personal_key,
user: user,
created_at: '2019-12-10',
......@@ -139,6 +161,8 @@ RSpec.shared_examples_for 'credentials inventory SSH keys' do |group_managed_acc
end
context 'and is not expired' do
let(:date_time) { 20.days.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date before'
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment