Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuchal committed Dec 10, 2023
1 parent 68c1b1c commit 679e605
Show file tree
Hide file tree
Showing 32 changed files with 327 additions and 45 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
4 changes: 2 additions & 2 deletions app/components/admin/users/users_list_row_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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: 2 additions & 0 deletions app/controllers/admin/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def edit
end

def create
puts Current.user.inspect
puts Current.user.user_group.inspect
@tag = SimpleTag.new(simple_tag_params.merge(simple_tag_creation_params))
authorize(@tag, policy_class: Admin::TagPolicy)

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)
8 changes: 8 additions & 0 deletions test/fixtures/group_memberships.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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
Expand Down
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
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
4 changes: 2 additions & 2 deletions test/system/admin/audit_log_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuditLogTest < ApplicationSystemTestCase
sign_in_as(:admin)
end

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

click_button "message-thread-options"
Expand All @@ -18,7 +18,7 @@ class AuditLogTest < ApplicationSystemTestCase
click_link "Export CSV"
end

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

click_link "Nastavenia"
Expand Down
48 changes: 48 additions & 0 deletions test/system/admin/group_management_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "application_system_test_case"

class GroupManagementTest < ApplicationSystemTestCase
setup do
sign_in_as(:admin)
visit root_path
click_link "Nastavenia"
click_link "Skupiny"
end

test "admin create a new group" do
click_link "Vytvoriť skupinu"

fill_in "custom_group_name", with: "Dummy Group"
click_button "Vytvoriť"

fill_in "name_search", with: "Basi"

click_button "Pridať používateľa do skupiny"
click_link "Zatvoriť"

assert_text "Dummy Group"
end

test "admin can add user to group" do
within("##{dom_id(groups(:ssd_signers))}") do
click_link "Zmeniť členov skupiny"
end

fill_in "name_search", with: "Basi"

click_button "Pridať používateľa do skupiny"
assert_text "Basic"
click_link "Zatvoriť"
end

test "admin can delete a group" do
assert_text "Custom group"

within("##{dom_id(groups(:ssd_custom))}") do
accept_alert do
click_button "Zmazať skupinu"
end
end

assert_no_text "Custom group"
end
end
40 changes: 40 additions & 0 deletions test/system/admin/tags_management_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "application_system_test_case"

class TagManagementTest < ApplicationSystemTestCase
setup do
sign_in_as(:admin)
visit root_path
click_link "Nastavenia"
click_link "Štítky"
end

test "admin can create a new simple tag" do
click_link "Vytvoriť štítok"

fill_in "simple_tag_name", with: "Dummy tag"
click_button "Vytvoriť"

assert_text "Dummy tag"
end

test "admin can update a simple tag" do
within("##{dom_id(tags(:ssd_finance))}") do
click_link "Editovať štítok"
end

fill_in "simple_tag_name", with: "Dummy new name"
click_button "Uložiť zmeny"

assert_text "Dummy new name"
end

test "admin can delete a tag" do
within("##{dom_id(tags(:ssd_finance))}") do
accept_alert do
click_button "Zmazať štítok"
end
end

assert_no_text "Finance"
end
end
Loading

0 comments on commit 679e605

Please sign in to comment.