Skip to content

Commit

Permalink
Merge pull request #241 from solver-it-sro/add-tests
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
jsuchal authored Dec 11, 2023
2 parents be480ad + 9872233 commit 7a3f004
Show file tree
Hide file tree
Showing 36 changed files with 477 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex" id="<%= dom_id(@group) %>">
<div class="relative inline-flex items-center justify-center w-16 h-16 overflow-hidden bg-blue-600 rounded-full">
<span class="text-white text-2xl font-normal"><%= @group.name[0] %></span>
</div>
Expand All @@ -18,11 +18,11 @@
</div>
<div class="justify-start items-start gap-2 flex">
<% if @group.editable? %>
<%= link_to edit_members_admin_tenant_group_path(@group.tenant, @group), data: { turbo_frame: "modal" } do %>
<%= link_to edit_members_admin_tenant_group_path(@group.tenant, @group), title: "Zmeniť členov skupiny", data: { turbo_frame: "modal" } do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<% if @group.destroyable? %>
<%= button_to admin_tenant_group_path(@group.tenant, @group), method: :delete, data: { turbo_confirm: "Naozaj chcete zmazať skupinu '#{@group.name}'?" } do %>
<%= button_to admin_tenant_group_path(@group.tenant, @group), title: "Zmazať skupinu", method: :delete, data: { turbo_confirm: "Naozaj chcete zmazať skupinu '#{@group.name}'?" } do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/components/admin/groups/user_add_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="text-center text-gray-900 text-lg font-medium leading-loose"><%= @user.name %></div>
<div class="text-center text-gray-500 text-base font-normal leading-normal"><%= @user.email %></div>
</div>
<%= button_to admin_tenant_group_group_memberships_path(Current.tenant, @group, group_membership: { group_id: @group.id, user_id: @user.id }), method: :post, data: { turbo_frame: "modal" } do %>
<%= button_to admin_tenant_group_group_memberships_path(Current.tenant, @group, group_membership: { group_id: @group.id, user_id: @user.id }), title: "Pridať používateľa do skupiny", method: :post, data: { turbo_frame: "modal" } do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
</div>
6 changes: 3 additions & 3 deletions app/components/admin/tags/tags_list_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="self-stretch p-6 border-b border-gray-200 items-center gap-4 inline-flex">
<div class="self-stretch p-6 border-b border-gray-200 items-center gap-4 inline-flex" id="<%= dom_id(@tag) %>">
<div class="grow shrink basis-0 gap-1">
<div class="text-gray-900 text-lg font-medium leading-loose">
<%= render Common::TagComponent.new(@tag) %>
</div>
</div>
<%= render Admin::Tags::VisibilityToggleComponent.new(@tag) %>
<div class="justify-start items-start gap-2 flex">
<%= link_to edit_admin_tenant_tag_path(@tag.tenant, @tag), data: { turbo_frame: "modal" } do %>
<%= link_to edit_admin_tenant_tag_path(@tag.tenant, @tag), title: "Editovať štítok", data: { turbo_frame: "modal" } do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_to admin_tenant_tag_path(@tag.tenant, @tag), method: :delete, data: { turbo_confirm: "Naozaj chcete zmazať štítok '#{@tag.name}'? Štítok bude zmazaný aj zo všetkých vlákien!" } do %>
<%= button_to admin_tenant_tag_path(@tag.tenant, @tag), title: "Zmazať štítok", method: :delete, data: { turbo_confirm: "Naozaj chcete zmazať štítok '#{@tag.name}'? Štítok bude zmazaný aj zo všetkých vlákien!" } do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= tag.turbo_frame id: "tag-form-visible-#{@tag.id}" do %>
<%= form_with model: @tag, url: admin_tenant_tag_path(Current.tenant, @tag), method: :patch do |form| %>
<%= form_with model: @tag, url: admin_tenant_tag_path(Current.tenant, @tag), title: "Zmeniť viditeľnosť štítku", method: :patch do |form| %>
<%= form.hidden_field :visible, value: [email protected] %>
<%= form.button class: "#{@tag.visible ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @tag.visible.to_s } do %>
<span class="sr-only">Use setting</span>
Expand Down
6 changes: 3 additions & 3 deletions app/components/admin/users/users_list_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex" id="<%= dom_id(@user) %>">
<div class="relative inline-flex items-center justify-center w-16 h-16 overflow-hidden bg-blue-600 rounded-full">
<span class="text-white text-2xl font-normal"><%= @user.name[0] %></span>
</div>
Expand All @@ -16,11 +16,11 @@
<%= render Common::ShowButtonComponent.new %>
<% end %>
<% end %>
<%= link_to edit_admin_tenant_user_path(@user.tenant, @user) do %>
<%= link_to edit_admin_tenant_user_path(@user.tenant, @user), title: "Editovať používateľa" do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<% if Pundit.policy(Current.user, [:admin, @user]).destroy? %>
<%= button_to admin_tenant_user_path(@user.tenant, @user), method: :delete do %>
<%= button_to admin_tenant_user_path(@user.tenant, @user), method: :delete, title: "Vymazať používateľa" do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/components/filters/filters_list_row_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</div>
</div>
<div class="justify-start items-start gap-2 flex">
<%= link_to edit_filter_path(@filter) do %>
<%= link_to edit_filter_path(@filter), title: "Upraviť filter" do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= link_to filter_path(@filter), data: { turbo_confirm: "Naozaj?", turbo_method: :delete } do %>
<%= link_to filter_path(@filter), title: "Zmazať filter", data: { turbo_confirm: "Naozaj?", turbo_method: :delete } do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/components/settings/rules/action_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<% if @enabled %>
<div>
<% if @new %>
<%= button_tag type: "submit", formaction: settings_automation_actions_path(index: @index), formmethod: :post do %>
<%= button_tag type: "submit", title: "Pridať akciu", formaction: settings_automation_actions_path(index: @index), formmethod: :post do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% else %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= button_tag type: "submit", title: "Zmazať akciu", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(index: @index), formmethod: :patch do %>
<%= button_tag type: "submit", title: "Upraviť akciu", formaction: settings_automation_action_path(index: @index), formmethod: :patch do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<%= @form.hidden_field :action_object_id %>
<% if @editable %>
<div class="flex">
<%= button_tag type: "submit", formaction: settings_automation_action_path(index: @index), formmethod: :post do %>
<%= button_tag type: "submit", title: "Upraviť akciu", formaction: settings_automation_action_path(index: @index), formmethod: :post do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= button_tag type: "submit", title: "Zmazať akciu", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6">
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6" id="<%= dom_id(@automation_rule) %>">
<div class="flex flex-col justify-start items-start flex-grow relative gap-1">
<p class="flex-grow-0 flex-shrink-0 text-lg text-left text-gray-900">
<span class="flex-grow-0 flex-shrink-0 text-lg text-left text-gray-900">Správy, kde</span>
Expand Down Expand Up @@ -26,10 +26,10 @@
</p>
</div>
<div class="flex justify-start items-start flex-grow-0 flex-shrink-0 gap-2">
<%= link_to edit_settings_automation_rule_path(@automation_rule) do %>
<%= link_to edit_settings_automation_rule_path(@automation_rule), title: "Upraviť pravidlo" do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_to settings_automation_rule_path(@automation_rule), method: :delete do %>
<%= button_to settings_automation_rule_path(@automation_rule), method: :delete, title: "Zmazať pravidlo" do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= tag.turbo_frame id: "condition-#{@index}", class: "flex justify-between self-stretch grow" do %>
<div class="flex justify-stretch gap-2">
<div class="flex justify-stretch gap-2" id="<%= dom_id(@form.object)%>">
<%= @form.hidden_field :id %>
<% if @form.object.attr.in? ['box'] %>
<%= @form.select :attr, @attr_list, {}, onchange: "this.form.requestSubmit(this.form.querySelector(\"#rerender\"))", class: "mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %>
Expand All @@ -15,14 +15,14 @@
<% if @enabled %>
<div>
<% if @new %>
<%= button_tag type: "submit", formaction: settings_automation_conditions_path(index: @index), formmethod: :post do %>
<%= button_tag type: "submit", title: "Pridať podmienku", formaction: settings_automation_conditions_path(index: @index), formmethod: :post do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% else %>
<%= button_tag type: "submit", formaction: settings_automation_condition_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= button_tag type: "submit", title: "Zmazať podmienku", formaction: settings_automation_condition_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_condition_path(index: @index), formmethod: :patch do %>
<%= button_tag type: "submit", title: "Upraviť podmienku", formaction: settings_automation_condition_path(index: @index), formmethod: :patch do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= tag.turbo_frame id: "condition-#{@index}", class: "flex justify-start self-stretch grow" do %>
<div class="flex justify-between items-center self-stretch flex-grow flex-shrink-0 relative">
<div class="flex justify-between items-center self-stretch flex-grow flex-shrink-0 relative" id="<%= dom_id(@form.object) %>">
<div class="flex gap-1">
<%= @form.hidden_field :id %>
<% if @form.object.attr.in? ['box'] %>
Expand All @@ -19,10 +19,10 @@
</div>
<% if @editable %>
<div class="flex">
<%= button_tag type: "submit", formaction: settings_automation_condition_path(index: @index), formmethod: :post, data: { turbo_frame: "condition-#{@index}" } do %>
<%= button_tag type: "submit", title: "Upraviť podmienku", formaction: settings_automation_condition_path(index: @index), formmethod: :post, data: { turbo_frame: "condition-#{@index}" } do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_condition_path(id: @form.object.id, index: @index), formmethod: :delete, data: { turbo_frame: "condition-#{@index}" } do %>
<%= button_tag type: "submit", title: "Zmazať podmienku", formaction: settings_automation_condition_path(id: @form.object.id, index: @index), formmethod: :delete, data: { turbo_frame: "condition-#{@index}" } do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def clean_session
def load_current_user
Current.user = User.find(session[:user_id]) if session[:user_id]
Current.tenant = Tenant.find(session[:tenant_id]) if session[:tenant_id]
Current.box = Current.tenant.boxes.find(session[:box_id]) if session[:box_id]
Current.box = Current.tenant.boxes.find(session[:box_id]) if session[:box_id] # TODO handle case when box was deleted
end

def valid_session?(session)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/automation_rules_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Settings::AutomationRulesController < ApplicationController
before_action :set_automation_rule, only: %i[show edit edit_actions update destroy]
before_action :set_automation_rule, only: %i[edit update destroy]
before_action :set_form_automation_rule, only: %i[header_step conditions_step actions_step create]
before_action :transform_delete_destroy, only: %i[create update]

Expand Down
14 changes: 12 additions & 2 deletions test/fixtures/automation/actions.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
one_one:
automation_rule: one
type: Automation::AddMessageThreadTagAction
action_object: ssd_external_visible (Tag)

one:
automation_rule: two
type: Automation::AddMessageThreadTagAction
action_object: ssd_construction (Tag)

two:
automation_rule: three
automation_rule: two
type: Automation::AddMessageThreadTagAction
action_object: ssd_office (Tag)

three:
automation_rule: four
automation_rule: three
type: Automation::AddMessageThreadTagAction
action_object: ssd_print (Tag)

four:
automation_rule: four
type: Automation::AddMessageThreadTagAction
action_object: ssd_external_visible (Tag)
12 changes: 12 additions & 0 deletions test/fixtures/group_memberships.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ ssd_basic_basic_user:
user: basic
group: ssd_basic_user

ssd_basic_two_basic_two_user:
user: basic_two
group: ssd_basic_two_user

ssd_admin_admin_user:
user: admin
group: ssd_admin_user

ssd_basic_all:
user: basic
group: ssd_all

ssd_admin_admin:
user: admin
group: ssd_admins
15 changes: 15 additions & 0 deletions test/fixtures/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ ssd_basic_user:
type: UserGroup
tenant: ssd

ssd_basic_two_user:
name: Another User
type: UserGroup
tenant: ssd

ssd_admin_user:
name: Admin user
type: UserGroup
tenant: ssd

ssd_custom:
name: Custom group
type: CustomGroup
tenant: ssd

ssd_signers:
name: Podpisovaci
type: SignerGroup
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/message_threads_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ ssd_main_general_other:
message_thread: ssd_main_general
tag: ssd_other

ssd_main_general_everything:
message_thread: ssd_main_general
tag: ssd_everything

ssd_main_issue_finance:
message_thread: ssd_main_issue
tag: ssd_finance

ssd_main_issue_hidden:
message_thread: ssd_main_issue
tag: ssd_hidden

ssd_main_delivery_everything:
message_thread: ssd_main_delivery
tag: ssd_everything
3 changes: 3 additions & 0 deletions test/fixtures/messages_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ ssd_main_general_two_external:
message: ssd_main_general_two
tag: ssd_external

ssd_main_general_one_everything:
message: ssd_main_general_one
tag: ssd_everything
5 changes: 3 additions & 2 deletions test/fixtures/tag_groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ finance_basic_user:
tag: ssd_finance
group: ssd_basic_user

#two:
# tag: two
everything_ssd_admins:
tag: ssd_everything
group: ssd_admins
1 change: 1 addition & 0 deletions test/fixtures/tenants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ssd:
name: SSD
feature_flags: ['audit_log']

solver:
name: Solver
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ basic:
email: [email protected]
tenant: ssd

basic_two:
name: Another user
email: [email protected]
tenant: ssd

admin:
name: Admin user
email: [email protected]
Expand Down
1 change: 1 addition & 0 deletions test/models/automation/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Automation::RuleTest < ActiveSupport::TestCase
Govbox::Message.create_message_with_thread!(govbox_message)
travel_to(15.minutes.from_now) { GoodJob.perform_inline }
message = Message.last
message.reload

assert_includes message.thread.tags, tags(:ssd_construction)
end
Expand Down
34 changes: 34 additions & 0 deletions test/system/admin/audit_log_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "application_system_test_case"

class AuditLogTest < ApplicationSystemTestCase
setup do
sign_in_as(:admin)
end

test "admin can access thread audit logs" do
visit message_thread_path(message_threads(:ssd_main_general))

click_button "message-thread-options"
click_link "Auditné záznamy"

assert_text "Auditné záznamy pre vlákno"

click_link "Export CSV"
end

test "admin can access user audit logs" do
visit root_path

click_link "Nastavenia"

click_link "Používatelia"

within("#user_#{users(:admin).id}") do
click_link "Auditné záznamy používateľa"
end

assert_text "Auditné záznamy pre používateľa"

click_link "Export CSV"
end
end
Loading

0 comments on commit 7a3f004

Please sign in to comment.