Skip to content

Commit

Permalink
cleanup, add/fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Nov 5, 2024
1 parent 897b316 commit 958c9d6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/components/viral/data_table/column_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Viral
module DataTable
# Component responsible for specific column attributes of DataTableComponent
# Component responsible for specific column data of DataTableComponent
class ColumnComponent < Viral::Component
attr_reader :title

Expand Down
8 changes: 4 additions & 4 deletions app/components/viral/data_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class DataTableComponent < Viral::Component
}
def initialize(
data,
row_actions: {},
id: '',
**system_arguments
)
@data = data
@row_actions = row_actions
@render_row_actions = @row_actions.select { |_key, value| value }.count.positive?
@id = id
@system_arguments = system_arguments
end

def system_arguments
{ tag: 'div' }.deep_merge(@system_arguments).tap do |args|
args[:id] = "#{@type}_table"
args[:id] = @id
args[:classes] = class_names(args[:classes], 'overflow-auto scrollbar')
# possibly to be used once implemented into tables with selection
# if @abilities[:select]
# args[:data] ||= {}
# args[:data][:controller] = 'selection'
Expand Down
94 changes: 46 additions & 48 deletions app/views/profiles/personal_access_tokens/_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
<%= turbo_frame_tag "personal_access_tokens" do %>
<% if @active_access_tokens.count.positive? %>
<%= viral_data_table(@active_access_tokens) do |table| %>
<% table.with_column(t("activerecord.attributes.personal_access_token.name")) do |row| %>
<%= row[:name] %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.scopes")) do |row| %>
<%= row[:scopes].join(", ") %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.created_at")) do |row| %>
<%= local_time(row[:created_at], :full_date) %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.last_used_at")) do |row| %>
<% if row[:last_used_at].present? %>
<%= local_time(row[:last_used_at], :full_date) %>
<% else %>
<%= t(".never") %>
<% end %>
<% end %>
<% table.with_column(t(".expires_at")) do |row| %>
<% if row[:expires_at].present? %>
<%= local_time(row[:expires_at], :full_date) %>
<% else %>
<%= t(".never") %>
<% if @active_access_tokens.count.positive? %>
<%= viral_data_table(@active_access_tokens, id: "personal-access-tokens-table") do |table| %>
<% table.with_column(t("activerecord.attributes.personal_access_token.name")) do |row| %>
<%= row[:name] %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.scopes")) do |row| %>
<%= row[:scopes].join(", ") %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.created_at")) do |row| %>
<%= local_time(row[:created_at], :full_date) %>
<% end %>
<% table.with_column(t("activerecord.attributes.personal_access_token.last_used_at")) do |row| %>
<% if row[:last_used_at].present? %>
<%= local_time(row[:last_used_at], :full_date) %>
<% else %>
<%= t(".never") %>
<% end %>
<% end %>
<% table.with_column(t(".expires_at")) do |row| %>
<% if row[:expires_at].present? %>
<%= local_time(row[:expires_at], :full_date) %>
<% else %>
<%= t(".never") %>
<% end %>
<% end %>
<% table.with_column(t(".action")) do |row| %>
<%= link_to(
t(".revoke_button"),
revoke_profile_personal_access_token_path(id: row.id),
data: {
turbo_frame: "personal-access-tokens",
turbo_method: :delete,
turbo_confirm: t(".revoke_confirm")
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer"
) %>
<% end %>
<% end %>
<% else %>
<div class="empty_state_message">
<%= viral_empty(
title: t(".empty_state.title"),
description: t(".empty_state.description"),
icon_name: :document_text
) %>
</div>
<% end %>
<% table.with_column(t(".action")) do |row| %>
<%= link_to(
t(".revoke_button"),
revoke_profile_personal_access_token_path(id: row.id),
data: {
turbo_frame: "personal-access-tokens",
turbo_method: :delete,
turbo_confirm: t(".revoke_confirm")
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer"
) %>
<% end %>
<% end %>
<% else %>
<div class="empty_state_message">
<%= viral_empty(
title: t(".empty_state.title"),
description: t(".empty_state.description"),
icon_name: :document_text
) %>
</div>
<% end %>
<% end %>
25 changes: 20 additions & 5 deletions test/system/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,36 @@ def setup

assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens',
count: @active_token_count)
assert_text token_to_revoke.name

within('#personal-access-tokens-table') do
assert_text token_to_revoke.name
end
within %(tr[id=#{token_to_revoke.id}]) do
click_link I18n.t(:'profiles.personal_access_tokens.personal_access_token.revoke_button')
click_link I18n.t(:'profiles.personal_access_tokens.table.revoke_button')
end

within('#turbo-confirm[open]') do
click_button I18n.t(:'components.confirmation.confirm')
end

assert_no_text token_to_revoke.name
within('#personal-access-tokens-table') do
assert_no_text token_to_revoke.name
end
assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens',
count: @active_token_count - 1)
end

test 'empty personal access tokens state' do
login_as users(:empty_doe)
visit profile_path
click_link I18n.t(:'profiles.sidebar.access_tokens')

assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens',
count: 0)
assert_no_selector 'table#personal-access-tokens-table'

assert_text I18n.t('profiles.personal_access_tokens.table.empty_state.title')
assert_text I18n.t('profiles.personal_access_tokens.table.empty_state.description')
end

test 'can view language selection' do
visit profile_preferences_path

Expand Down

0 comments on commit 958c9d6

Please sign in to comment.