diff --git a/app/components/namespace_tree/row/row_contents_component.html.erb b/app/components/namespace_tree/row/row_contents_component.html.erb index 336d4f65b3..15ea2ebce7 100644 --- a/app/components/namespace_tree/row/row_contents_component.html.erb +++ b/app/components/namespace_tree/row/row_contents_component.html.erb @@ -76,7 +76,7 @@ id="<%= "#{dom_id(@namespace)}-samples-count" %>" class="flex items-center text-sm samples-count" > - <%= viral_icon(name: :beaker, color: :subdued, classes: "h-5 w-5") %><%= @namespace.samples_count %> + <%= viral_icon(name: :beaker, color: :subdued, classes: "h-5 w-5") %><%= @namespace.aggregated_samples_count %> <% end %> <%= viral_tooltip(title: t(:'.stats.projects')) do %> diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index ff2700759c..e9d3d85076 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -12,7 +12,7 @@ class SamplesController < Groups::ApplicationController def index @timestamp = DateTime.current @pagy, @samples = @query.results(limit: params[:limit] || 20, page: params[:page] || 1) - @has_samples = authorized_samples.count.positive? + @has_samples = @group.has_samples? end def search diff --git a/app/models/group.rb b/app/models/group.rb index 1da3376b15..67afbea7f5 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -53,6 +53,7 @@ def of_ancestors_and_self NamespaceGroupLink.where(namespace_id: source_ids) end end + has_many :shared_groups, through: :shared_group_links, source: :namespace has_many :shared_project_namespaces, through: :shared_project_namespace_links, class_name: 'Namespaces::ProjectNamespace', source: :namespace @@ -91,6 +92,28 @@ def shared_namespace_metadata_keys(namespace) metadata_fields end + def aggregated_samples_count # rubocop:disable Metrics/AbcSize + minimum_access_level = Member::AccessLevel::GUEST + + active_shared_namespaces = Namespace + .where( + id: NamespaceGroupLink + .not_expired + .where(group_id: self_and_descendant_ids, group_access_level: minimum_access_level..) + .select(:namespace_id) + ).self_and_descendants.where(type: [Namespaces::ProjectNamespace.sti_name]) + .where.not(id: self_and_descendants_of_type([Namespaces::ProjectNamespace.sti_name]).ids) + + return samples_count unless active_shared_namespaces.any? + + aggregated_samples_count = samples_count + active_shared_namespaces.find_each do |project_namespace| + aggregated_samples_count += project_namespace.project.samples.size + end + + aggregated_samples_count + end + def retrieve_group_activity PublicActivity::Activity.where( trackable_id: id, @@ -108,6 +131,10 @@ def retrieve_group_activity ) end + def has_samples? # rubocop:disable Naming/PredicateName + samples_count.positive? || aggregated_samples_count.positive? + end + def add_to_samples_count(namespaces, addition_amount) namespaces.each do |namespace| namespace.samples_count += addition_amount diff --git a/test/controllers/concerns/project_share_actions_concern_test.rb b/test/controllers/concerns/project_share_actions_concern_test.rb index 53a5d9fe55..9c3c4c4e41 100644 --- a/test/controllers/concerns/project_share_actions_concern_test.rb +++ b/test/controllers/concerns/project_share_actions_concern_test.rb @@ -29,7 +29,7 @@ class ProjectShareActionsConcernTest < ActionDispatch::IntegrationTest }, format: :turbo_stream }) assert_response :success - assert_equal 1, + assert_equal 2, project_namespace.shared_with_group_links.of_ancestors_and_self.count end diff --git a/test/fixtures/groups.yml b/test/fixtures/groups.yml index 4753341cc0..f9ac790484 100644 --- a/test/fixtures/groups.yml +++ b/test/fixtures/groups.yml @@ -75,7 +75,7 @@ group_five: path: group-5 description: Group 5 description puid: INXT_GRP_AAAAAAAAAG - samples_count: 0 + samples_count: 2 subgroup_one_group_five: <<: *DEFAULTS @@ -210,6 +210,7 @@ group_alpha_subgroup1: name: Subgroup 1 path: group-alpha/subgroup-1 description: Subgroup 1 description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_alpha, :uuid) %> puid: INXT_GRP_AAAAAAAAAV samples_count: 1 @@ -409,3 +410,122 @@ group_jeff: owner_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %> puid: INXT_GRP_AAAAAAJEFF samples_count: 0 + +group_india: + <<: *DEFAULTS + name: Group India + path: group-india + description: Group India description + puid: INXT_GRP_AAAAAAAACA + samples_count: 3 + +group_india_subgroup1: + <<: *DEFAULTS + name: Subgroup 1 + path: group-india/subgroup-1 + description: Subgroup 1 description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_india, :uuid) %> + puid: INXT_GRP_AAAAAAAACB + samples_count: 1 + +group_juliett: + <<: *DEFAULTS + name: Group Juliett + path: group-juliett + description: Group Juliett description + puid: INXT_GRP_AAAAAAAACC + samples_count: 3 + +group_juliett_subgroup1: + <<: *DEFAULTS + name: Subgroup 1 + path: group-juliett/subgroup-1 + description: Subgroup 1 description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett, :uuid) %> + puid: INXT_GRP_AAAAAAAACD + samples_count: 1 + +group_kilo: + <<: *DEFAULTS + name: Group Kilo + path: group-kilo + description: Group Kilo description + puid: INXT_GRP_AAAAAAAACE + samples_count: 0 + +group_lima: + <<: *DEFAULTS + name: Group Lima + path: group-lima + description: Group Lima description + puid: INXT_GRP_AAAAAAAACF + samples_count: 0 + +group_mike: + <<: *DEFAULTS + name: Group Mike + path: group-mike + description: Group Mike description + puid: INXT_GRP_AAAAAAAACG + samples_count: 6 + +subgroup_mike_a: + <<: *DEFAULTS + name: Subgroup Mike A + path: subgroup-mike-a + description: Subgroup Mike A description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_mike, :uuid) %> + puid: INXT_GRP_AAAAAAAACH + samples_count: 2 + +subgroup_mike_b: + <<: *DEFAULTS + name: Subgroup Mike B + path: subgroup-mike-b + description: Subgroup Mike B description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_mike, :uuid) %> + puid: INXT_GRP_AAAAAAAACI + samples_count: 2 + +subgroup_mike_a_a: + <<: *DEFAULTS + name: Subgroup Mike A A + path: subgroup-mike-a-a + description: Subgroup Mike A A description + parent_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_a, :uuid) %> + puid: INXT_GRP_AAAAAAAACJ + samples_count: 0 + +group_oscar: + <<: *DEFAULTS + name: Group Oscar + path: group-oscar + description: Group Oscar description + puid: INXT_GRP_AAAAAAAACK + samples_count: 0 + +subgroup_oscar_a: + <<: *DEFAULTS + name: Subgroup Oscar A + path: subgroup-oscar-a + description: Subgroup Oscar A description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_oscar, :uuid) %> + puid: INXT_GRP_AAAAAAAACL + samples_count: 0 + +group_papa: + <<: *DEFAULTS + name: Group Papa + path: group-papa + description: Group Papa description + puid: INXT_GRP_AAAAAAAACM + samples_count: 0 + +subgroup_papa_a: + <<: *DEFAULTS + name: Subgroup Papa A + path: subgroup-papa-a + description: Subgroup Papa A description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_papa, :uuid) %> + puid: INXT_GRP_AAAAAAAACN + samples_count: 0 diff --git a/test/fixtures/members.yml b/test/fixtures/members.yml index 8e482886f3..b8d5ea6c38 100644 --- a/test/fixtures/members.yml +++ b/test/fixtures/members.yml @@ -387,6 +387,48 @@ group_alpha_member_private_ryan: namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_alpha, :uuid) %> access_level: <%= Member::AccessLevel::OWNER %> +group_india_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_india, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_juliett_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_kilo_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_kilo, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_lima_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_lima, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_mike_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_mike, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_oscar_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_oscar, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + +group_papa_member_private_ryan: + user_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + created_by_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_papa, :uuid) %> + access_level: <%= Member::AccessLevel::OWNER %> + group_eleven_member_user_26: user_id: <%= ActiveRecord::FixtureSet.identify(:user26, :uuid) %> created_by_id: <%= ActiveRecord::FixtureSet.identify(:user26, :uuid) %> diff --git a/test/fixtures/namespace_group_links.yml b/test/fixtures/namespace_group_links.yml index 0f7018354e..70a87b7f3f 100644 --- a/test/fixtures/namespace_group_links.yml +++ b/test/fixtures/namespace_group_links.yml @@ -107,3 +107,82 @@ namespace_group_link18: namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %> group_access_level: <%= Member::AccessLevel::ANALYST %> namespace_type: "Project" + +namespace_group_link19: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_five, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link20: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_five, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:project22_namespace, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Project" + +namespace_group_link21: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_india, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia1_namespace, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Project" + +namespace_group_link22: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett_subgroup1, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link23: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_kilo, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link24: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_lima, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link25: + group_id: <%= ActiveRecord::FixtureSet.identify(:group_lima, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_twelve_a, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link26: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_a, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_mike, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link27: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_a_a, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectMike_namespace, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Project" + +namespace_group_link28: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_b, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_twelve, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + expires_at: "2025-01-01" + +namespace_group_link29: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_oscar_a, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_twelve_a_a, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" + +namespace_group_link30: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_oscar_a, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:project30_namespace, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Project" + +namespace_group_link31: + group_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_papa_a, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_lima, :uuid) %> + group_access_level: <%= Member::AccessLevel::ANALYST %> + namespace_type: "Group" diff --git a/test/fixtures/namespaces/project_namespaces.yml b/test/fixtures/namespaces/project_namespaces.yml index 917d7453e8..b977ded3d1 100644 --- a/test/fixtures/namespaces/project_namespaces.yml +++ b/test/fixtures/namespaces/project_namespaces.yml @@ -504,3 +504,61 @@ empty_project_namespace: description: Project that does not contain any samples parent_id: <%= ActiveRecord::FixtureSet.identify(:empty_group, :uuid) %> puid: INXT_PRJ_AAAAAAACBE + +projectIndia_namespace: + <<: *DEFAULTS + name: Project India + path: project-india + description: Project India description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_india, :uuid) %> + puid: INXT_PRJ_AAAAAAAABT + +projectIndia1_namespace: + <<: *DEFAULTS + name: Project India 1 + path: project-india-1 + description: Project India 1 description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_india_subgroup1, :uuid) %> + owner_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + puid: INXT_PRJ_AAAAAAAABU + +projectJuliett_namespace: + <<: *DEFAULTS + name: Project Juliett + path: project-juliett + description: Project Juliett description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett, :uuid) %> + puid: INXT_PRJ_AAAAAAAABV + +projectJuliett1_namespace: + <<: *DEFAULTS + name: Project Juliett 1 + path: project-juliett-1 + description: Project Juliett 1 description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_juliett_subgroup1, :uuid) %> + owner_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + puid: INXT_PRJ_AAAAAAAABW + +projectMike_namespace: + <<: *DEFAULTS + name: Project Mike + path: project-mike + description: Project Mike description + parent_id: <%= ActiveRecord::FixtureSet.identify(:group_mike, :uuid) %> + puid: INXT_PRJ_AAAAAAAABX + +projectMikeA_namespace: + <<: *DEFAULTS + name: Project Mike A + path: project-mike-a + description: Project Mike A description + parent_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_a, :uuid) %> + puid: INXT_PRJ_AAAAAAAABY + +projectMikeB_namespace: + <<: *DEFAULTS + name: Project Mike B + path: project-mike-b + description: Project Mike B description + parent_id: <%= ActiveRecord::FixtureSet.identify(:subgroup_mike_b, :uuid) %> + puid: INXT_PRJ_AAAAAAAABZ diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml index febf8b3c53..ae9b451132 100644 --- a/test/fixtures/projects.yml +++ b/test/fixtures/projects.yml @@ -118,7 +118,7 @@ project21: project22: creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:project22_namespace, :uuid) %> - samples_count: 0 + samples_count: 2 project23: creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> @@ -289,3 +289,38 @@ empty_project: creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:empty_project_namespace, :uuid) %> samples_count: 0 + +projectIndia: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia_namespace, :uuid) %> + samples_count: 2 + +projectIndia1: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia1_namespace, :uuid) %> + samples_count: 1 + +projectJuliett: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectJuliett_namespace, :uuid) %> + samples_count: 2 + +projectJuliett1: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectJuliett1_namespace, :uuid) %> + samples_count: 1 + +projectMike: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectMike_namespace, :uuid) %> + samples_count: 2 + +projectMikeA: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeA_namespace, :uuid) %> + samples_count: 2 + +projectMikeB: + creator_id: <%= ActiveRecord::FixtureSet.identify(:private_ryan, :uuid) %> + namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeB_namespace, :uuid) %> + samples_count: 2 diff --git a/test/fixtures/routes.yml b/test/fixtures/routes.yml index 39367e4a0e..8bde55ee2a 100644 --- a/test/fixtures/routes.yml +++ b/test/fixtures/routes.yml @@ -498,3 +498,108 @@ empty_project_namespace_route: name: Empty Group / Empty Project path: empty-group/empty-project source: empty_project_namespace (Namespace) + +group_india_route: + name: Group India + path: group-india + source: group_india (Namespace) + +project_india_namespace_route: + name: Group India / Project India + path: group-india/project-india + source: projectIndia_namespace (Namespace) + +subgroup_one_group_india_route: + name: Group India / Subgroup 1 + path: group-india/subgroup-1 + source: group_india_subgroup1 (Namespace) + +project_india_1_namespace_route: + name: Group India / Subgroup 1 / Project India 1 + path: group-india/subgroup-1/project-india-1 + source: projectIndia1_namespace (Namespace) + +group_juliett_route: + name: Group Juliett + path: group-juliett + source: group_juliett (Namespace) + +project_juliett_namespace_route: + name: Group Juliett / Project Juliett + path: group-juliett/project-juliett + source: projectJuliett_namespace (Namespace) + +subgroup_one_group_juliett_route: + name: Group Juliett / Subgroup 1 + path: group-juliett/subgroup-1 + source: group_juliett_subgroup1 (Namespace) + +project_juliett_1_namespace_route: + name: Group Juliett / Subgroup 1 / Project Juliett 1 + path: group-juliett/subgroup-1/project-juliett-1 + source: projectJuliett1_namespace (Namespace) + +group_kilo_route: + name: Group Kilo + path: group-kilo + source: group_kilo (Namespace) + +group_lima_route: + name: Group Lima + path: group-lima + source: group_lima (Namespace) + +group_mike_route: + name: Group Mike + path: group-mike + source: group_mike (Namespace) + +projectMike_namespace_route: + name: Group Mike / Project Mike + path: group-mike/project-mike + source: projectMike_namespace (Namespace) + +subgroup_mike_a_route: + name: Group Mike / Subgroup Mike A + path: group-mike/subgroup-mike-a + source: subgroup_mike_a (Namespace) + +projectMikeA_namespace_route: + name: Group Mike / Subgroup Mike A / Project Mike A + path: group-mike/subgroup-mike-a/project-mike-a + source: projectMikeA_namespace (Namespace) + +subgroup_mike_b_route: + name: Group Mike / Subgroup Mike B + path: group-mike/subgroup-mike-b + source: subgroup_mike_b (Namespace) + +projectMikeB_namespace_route: + name: Group Mike / Subgroup Mike B / Project Mike B + path: group-mike/subgroup-mike-b/project-mike-b + source: projectMikeB_namespace (Namespace) + +subgroup_mike_a_a_route: + name: Group Mike / Subgroup Mike A / Subgroup Mike AA + path: group-mike/subgroup-mike-a/subgroup-mike-a-a + source: subgroup_mike_a_a (Namespace) + +group_oscar_route: + name: Group Oscar + path: group-oscar + source: group_oscar (Namespace) + +subgroup_oscar_a_route: + name: Group Oscar / Subgroup Oscar A + path: group-oscar/subgroup-oscar-a + source: subgroup_oscar_a (Namespace) + +group_papa_route: + name: Group Papa + path: group-papa + source: group_papa (Namespace) + +subgroup_papa_a_route: + name: Group Papa / Subgroup Papa A + path: group-papa/subgroup-papa-a + source: subgroup_papa_a (Namespace) diff --git a/test/fixtures/samples.yml b/test/fixtures/samples.yml index a615e9026f..f287bfda7c 100644 --- a/test/fixtures/samples.yml +++ b/test/fixtures/samples.yml @@ -364,3 +364,129 @@ bulk_sample<%= (n) %>: created_at: <%= n.weeks.ago %> updated_at: <%= n.days.ago %> <% end %> + +sample47: + name: Sample 47 + description: Sample 47 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:project22, :uuid) %> + puid: INXT_SAM_AAAAAAAABW + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample48: + name: Sample 48 + description: Sample 48 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:project22, :uuid) %> + puid: INXT_SAM_AAAAAAAABX + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample49: + name: Sample 49 + description: Sample 49 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia, :uuid) %> + puid: INXT_SAM_AAAAAAAABY + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample50: + name: Sample 50 + description: Sample 50 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia, :uuid) %> + puid: INXT_SAM_AAAAAAAABZ + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample51: + name: Sample 51 + description: Sample 51 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectIndia1, :uuid) %> + puid: INXT_SAM_AAAAAAAADA + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample52: + name: Sample 52 + description: Sample 52 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectJuliett, :uuid) %> + puid: INXT_SAM_AAAAAAAADB + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample53: + name: Sample 53 + description: Sample 53 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectJuliett, :uuid) %> + puid: INXT_SAM_AAAAAAAADC + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample54: + name: Sample 54 + description: Sample 54 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectJuliett1, :uuid) %> + puid: INXT_SAM_AAAAAAAADD + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample55: + name: Sample 55 + description: Sample 55 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMike, :uuid) %> + puid: INXT_SAM_AAAAAAAADE + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample56: + name: Sample 56 + description: Sample 56 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMike, :uuid) %> + puid: INXT_SAM_AAAAAAAADF + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample57: + name: Sample 57 + description: Sample 57 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeA, :uuid) %> + puid: INXT_SAM_AAAAAAAADG + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample58: + name: Sample 58 + description: Sample 58 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeA, :uuid) %> + puid: INXT_SAM_AAAAAAAADH + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample59: + name: Sample 59 + description: Sample 59 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeB, :uuid) %> + puid: INXT_SAM_AAAAAAAADI + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> + +sample60: + name: Sample 60 + description: Sample 60 description. + project_id: <%= ActiveRecord::FixtureSet.identify(:projectMikeB, :uuid) %> + puid: INXT_SAM_AAAAAAAADJ + created_at: <%= 1.week.ago %> + updated_at: <%= 1.day.ago %> + attachments_updated_at: <%= 2.hours.ago %> diff --git a/test/models/group_test.rb b/test/models/group_test.rb index 09e163249f..a42cdb8af1 100644 --- a/test/models/group_test.rb +++ b/test/models/group_test.rb @@ -210,6 +210,128 @@ def setup assert_equal %w[metadatafield1 metadatafield2], groups(:group_alpha).metadata_fields end + test '#has_samples' do + assert @group.has_samples? + end + + test 'has_samples should return true for a group with only samples shared from other groups' do + group = groups(:group_kilo) + assert group.has_samples? + end + + test 'has_samples should return false for a group with no direct or shared samples' do + group = groups(:group_two) + assert_not group.has_samples? + end + + test 'group with no samples should have aggregated_samples_count equal to shared groups samples_count' do + group = groups(:group_kilo) + shared_group = groups(:group_twelve) + + assert_equal 0, group.samples_count + assert_equal 4, shared_group.samples_count + assert_equal shared_group.samples_count, group.aggregated_samples_count + end + + test 'group with nothing being shared to, aggregated_samples_count should equal samples_count' do + group12 = groups(:group_twelve) + + assert_equal 4, group12.samples_count + assert_equal group12.samples_count, group12.aggregated_samples_count + end + + test 'aggregated_samples_count should equal samples_count plus samples_counts of groups and projects shared to it' do + group_alpha = groups(:group_alpha) + shared_group = groups(:group_charlie) + shared_project = projects(:projectBravo) + group_alpha_samples_count = group_alpha.samples_count + shared_group_samples_count = shared_group.samples_count + shared_project_samples_count = shared_project.samples.size + aggregated_samples_count = group_alpha_samples_count + shared_group_samples_count + shared_project_samples_count + + assert_equal 2, group_alpha_samples_count + assert_equal 1, shared_group_samples_count + assert_equal 1, shared_project_samples_count + assert_equal aggregated_samples_count, group_alpha.aggregated_samples_count + end + + test 'group with a subproject as a shared project should not include subproject twice in aggregated_samples_count' do + group = groups(:group_india) + + assert_equal 3, group.samples_count + assert_equal group.samples_count, group.aggregated_samples_count + end + + test 'group with a subgroup as a shared group should not include subgroup twice in aggregated_samples_count' do + group = groups(:group_juliett) + + assert_equal 3, group.samples_count + assert_equal group.samples_count, group.aggregated_samples_count + end + + test 'aggregated_samples_count should not include shared projects that are descendants of groups in shared groups' do + assert_equal 8, groups(:group_five).aggregated_samples_count + end + + test 'aggregated_samples_count should not include shared groups that are descendants of groups in shared groups' do + group = groups(:group_lima) + shared_group = groups(:group_twelve) + + assert_equal 0, group.samples_count + assert_equal 4, shared_group.samples_count + assert_equal shared_group.samples_count, group.aggregated_samples_count + end + + test 'shared group is an ancestor, aggregated_samples_count should not include ones own samples_count twice' do + group = groups(:subgroup_mike_a) + shared_group = groups(:group_mike) + + assert_equal 2, group.samples_count + assert_equal 6, shared_group.samples_count + assert_equal shared_group.samples_count, group.aggregated_samples_count + end + + test 'shared project is in an ancestor group, should include it in aggregated_samples_count' do + group = groups(:subgroup_mike_a_a) + shared_project = projects(:projectMike) + + assert_equal 0, group.samples_count + assert_equal 2, shared_project.samples.size + assert_equal shared_project.samples.size, group.aggregated_samples_count + end + + test 'aggregated_samples_count should include projects and groups shared with descendants' do + group = groups(:group_oscar) + subgroup = groups(:subgroup_oscar_a) + + assert_equal 0, group.samples_count + assert_equal 0, subgroup.samples_count + assert_equal 3, subgroup.aggregated_samples_count + assert_equal subgroup.aggregated_samples_count, group.aggregated_samples_count + end + + test 'aggregated_samples_count should not include shared projects/groups of shared groups' do + group = groups(:group_papa) + subgroup = groups(:subgroup_papa_a) + shared_group = groups(:group_lima) + + assert_equal 0, group.samples_count + assert_equal 0, shared_group.samples_count + assert_equal 4, shared_group.aggregated_samples_count + assert_equal 0, subgroup.samples_count + assert_equal 0, subgroup.aggregated_samples_count + assert_equal subgroup.aggregated_samples_count, group.aggregated_samples_count + end + + test 'group with expired links should not include those samples to aggregated_samples_count' do + group = groups(:subgroup_mike_b) + shared_group = groups(:group_twelve) + + assert_equal 2, group.samples_count + assert_equal 4, shared_group.samples_count + assert_equal group.samples_count, group.aggregated_samples_count + end + test 'update samples_count by sample transfer' do project = projects(:project22) assert_difference -> { @group_three.reload.samples_count } => -1, diff --git a/test/system/dashboard/groups_test.rb b/test/system/dashboard/groups_test.rb index 53ab434979..412d81b75c 100644 --- a/test/system/dashboard/groups_test.rb +++ b/test/system/dashboard/groups_test.rb @@ -248,394 +248,17 @@ def teardown end end - test 'should update samples count after a group deletion' do + test 'should display a samples count that includes samples from shared groups and projects' do login_as users(:john_doe) visit dashboard_groups_url + group = groups(:group_three) assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - assert_equal 4, @group12.samples_count + assert_equal 3, group.aggregated_samples_count - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - visit group_url(@subgroup12aa) - click_on I18n.t('groups.sidebar.settings') - click_link I18n.t('groups.sidebar.general') - - assert_selector 'h2', text: I18n.t('groups.sidebar.general') - - assert_selector 'a', text: I18n.t('groups.edit.advanced.delete.submit'), count: 1 - click_link I18n.t('groups.edit.advanced.delete.submit') - - assert_text I18n.t('groups.edit.advanced.delete.confirm') - assert_button I18n.t('components.confirmation.confirm') - click_button I18n.t('components.confirmation.confirm') - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 2, @group12.reload.samples_count - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a group transfer' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - visit group_url(@subgroup12aa) - - click_on I18n.t('groups.sidebar.settings') - click_link I18n.t('groups.sidebar.general') - - assert_selector 'h2', text: I18n.t('groups.edit.advanced.transfer.title') - within %(form[action="/group-12/subgroup-12-a/subgroup-12-a-a/transfer"]) do - assert_selector 'input[type=submit]:disabled' - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@subgroup12b.full_path}']").click - assert_selector 'input[type=submit]:not(:disabled)' - click_on I18n.t('groups.edit.advanced.transfer.submit') - end - - within('#turbo-confirm') do - assert_text I18n.t('components.confirmation.title') - fill_in I18n.t('components.confirmation.confirm_label'), with: @subgroup12aa.path - click_on I18n.t('components.confirmation.confirm') - end - - assert_text I18n.t('groups.transfer.success') - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 4, @group12.reload.samples_count - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 3, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a project deletion' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project31 = projects(:project31) - visit project_edit_path(project31) - assert_selector 'a', text: I18n.t(:'projects.edit.advanced.destroy.submit'), count: 1 - click_link I18n.t(:'projects.edit.advanced.destroy.submit') - - assert_text I18n.t('projects.edit.advanced.destroy.confirm') - assert_button I18n.t('components.confirmation.confirm') - click_button I18n.t('components.confirmation.confirm') - - assert_text I18n.t(:'projects.destroy.success', project_name: project31.name) - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 2, @group12.reload.samples_count - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a project transfer' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project31 = projects(:project31) - visit project_edit_path(project31) - assert_selector 'h2', text: I18n.t('projects.edit.advanced.transfer.title') - within %(form[action="/group-12/subgroup-12-a/subgroup-12-a-a/project-31/-/transfer"]) do - assert_selector 'input[type=submit]:disabled' - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@subgroup12b.full_path}']").click - assert_selector 'input[type=submit]:not(:disabled)' - click_on I18n.t('projects.edit.advanced.transfer.submit') - end - - within('#turbo-confirm') do - assert_text I18n.t('components.confirmation.title') - fill_in I18n.t('components.confirmation.confirm_label'), with: project31.name - click_on I18n.t('components.confirmation.confirm') - end - - assert_text I18n.t('projects.transfer.success') - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 4, @group12.reload.samples_count - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 3, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a sample deletion' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project29 = projects(:project29) - sample32 = samples(:sample32) - visit namespace_project_sample_url(@subgroup12a, project29, sample32) - click_link I18n.t('projects.samples.show.remove_button') - - within('#turbo-confirm[open]') do - click_button I18n.t(:'components.confirmation.confirm') - end - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 3, @group12.reload.samples_count - assert_equal 2, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a sample creation' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project31 = projects(:project31) - visit namespace_project_samples_url(@subgroup12aa, project31) - - click_link I18n.t('projects.samples.index.new_button') - - find('input#sample_name').fill_in with: 'Test Sample' - click_button I18n.t('projects.samples.new.submit_button') - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 5, @group12.reload.samples_count - assert_equal 4, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a sample transfer' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project31 = projects(:project31) - project30 = projects(:project30) - sample34 = samples(:sample34) - visit namespace_project_samples_url(@subgroup12aa, project31) - - find("input[type='checkbox'][id='sample_#{sample34.id}']").click - click_link I18n.t('projects.samples.index.transfer_button') - - within('span[data-controller-connected="true"] dialog') do - assert_text I18n.t('projects.samples.transfers.dialog.description.singular') - within %(turbo-frame[id="list_selections"]) do - assert_text sample34.name - end - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{project30.full_path}']").click - click_on I18n.t('projects.samples.transfers.dialog.submit_button') - end - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 4, @group12.reload.samples_count - assert_equal 2, @subgroup12a.reload.samples_count - assert_equal 2, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a sample clone' do - login_as users(:john_doe) - visit dashboard_groups_url - - assert_selector 'h1', text: I18n.t(:'dashboard.groups.index.title') - - assert_equal 4, @group12.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - project31 = projects(:project31) - project30 = projects(:project30) - sample34 = samples(:sample34) - visit namespace_project_samples_url(@subgroup12aa, project31) - - find("input[type='checkbox'][id='sample_#{sample34.id}']").click - click_link I18n.t('projects.samples.index.clone_button') - - within('span[data-controller-connected="true"] dialog') do - assert_text I18n.t('projects.samples.clones.dialog.description.singular') - within %(turbo-frame[id="list_selections"]) do - assert_text sample34.name - end - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{project30.full_path}']").click - click_on I18n.t('projects.samples.clones.dialog.submit_button') - end - assert_text I18n.t('projects.samples.clones.create.success') - - visit dashboard_groups_url - within("li#group_#{@group12.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 5, @group12.reload.samples_count - assert_equal 3, @subgroup12a.reload.samples_count - assert_equal 2, @subgroup12b.reload.samples_count - - within("#group_#{@group12.id}-samples-count") do - assert_text @group12.samples_count - end - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count + within("#group_#{group.id}-samples-count") do + assert_text group.aggregated_samples_count end end end diff --git a/test/system/groups_test.rb b/test/system/groups_test.rb index 7691c6a681..1acf03b109 100644 --- a/test/system/groups_test.rb +++ b/test/system/groups_test.rb @@ -483,553 +483,6 @@ def teardown end end - test 'should update samples count after a group deletion' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - visit group_url(@subgroup12aa) - click_on I18n.t('groups.sidebar.settings') - click_link I18n.t('groups.sidebar.general') - - assert_selector 'h2', text: I18n.t('groups.sidebar.general') - - assert_selector 'a', text: I18n.t('groups.edit.advanced.delete.submit'), count: 1 - click_link I18n.t('groups.edit.advanced.delete.submit') - - assert_text I18n.t('groups.edit.advanced.delete.confirm') - assert_button I18n.t('components.confirmation.confirm') - click_button I18n.t('components.confirmation.confirm') - - assert_selector 'h1', text: I18n.t('dashboard.groups.index.title') - - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - visit group_url(@group12) - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a group transfer' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - visit group_url(@subgroup12aa) - - click_on I18n.t('groups.sidebar.settings') - click_link I18n.t('groups.sidebar.general') - - assert_selector 'h2', text: I18n.t('groups.edit.advanced.transfer.title') - within %(form[action="/group-12/subgroup-12-a/subgroup-12-a-a/transfer"]) do - assert_selector 'input[type=submit]:disabled' - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@subgroup12b.full_path}']").click - assert_selector 'input[type=submit]:not(:disabled)' - click_on I18n.t('groups.edit.advanced.transfer.submit') - end - - within('#turbo-confirm') do - assert_text I18n.t('components.confirmation.title') - fill_in I18n.t('components.confirmation.confirm_label'), with: @subgroup12aa.path - click_on I18n.t('components.confirmation.confirm') - end - - assert_text I18n.t('groups.transfer.success') - - visit group_url(@group12) - within("li#group_#{@subgroup12b.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 2, @subgroup12aa.reload.samples_count - assert_equal 3, @subgroup12b.reload.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - end - - test 'should update samples count after a project deletion' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - project31 = projects(:project31) - visit project_edit_path(project31) - assert_selector 'a', text: I18n.t(:'projects.edit.advanced.destroy.submit'), count: 1 - click_link I18n.t(:'projects.edit.advanced.destroy.submit') - - assert_text I18n.t('projects.edit.advanced.destroy.confirm') - assert_button I18n.t('components.confirmation.confirm') - click_button I18n.t('components.confirmation.confirm') - - assert_text I18n.t(:'projects.destroy.success', project_name: project31.name) - - visit group_url(@group12) - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 0, @subgroup12aa.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a project transfer' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - project31 = projects(:project31) - visit project_edit_path(project31) - assert_selector 'h2', text: I18n.t('projects.edit.advanced.transfer.title') - within %(form[action="/group-12/subgroup-12-a/subgroup-12-a-a/project-31/-/transfer"]) do - assert_selector 'input[type=submit]:disabled' - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@subgroup12b.full_path}']").click - assert_selector 'input[type=submit]:not(:disabled)' - click_on I18n.t('projects.edit.advanced.transfer.submit') - end - - within('#turbo-confirm') do - assert_text I18n.t('components.confirmation.title') - fill_in I18n.t('components.confirmation.confirm_label'), with: project31.name - click_on I18n.t('components.confirmation.confirm') - end - - assert_text I18n.t('projects.transfer.success') - - visit group_url(@group12) - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 1, @subgroup12a.reload.samples_count - assert_equal 0, @subgroup12aa.reload.samples_count - assert_equal 3, @subgroup12b.reload.samples_count - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - end - - test 'should update samples count after a sample deletion' do - project29 = projects(:project29) - sample32 = samples(:sample32) - - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - assert_equal 1, project29.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{project29.id}-samples-count") do - assert_text project29.samples.size - end - - visit namespace_project_sample_url(@subgroup12a, project29, sample32) - click_link I18n.t('projects.samples.show.remove_button') - - within('#turbo-confirm[open]') do - click_button I18n.t(:'components.confirmation.confirm') - end - - visit group_url(@group12) - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - - assert_equal 2, @subgroup12a.reload.samples_count - assert_equal 2, @subgroup12aa.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - assert_equal 0, project29.reload.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{project29.id}-samples-count") do - assert_text project29.samples.size - end - end - - test 'should update samples count after a sample creation' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - assert_equal 2, @project31.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - - visit namespace_project_samples_url(@subgroup12aa, @project31) - - click_link I18n.t('projects.samples.index.new_button') - - find('input#sample_name').fill_in with: 'Test Sample' - click_button I18n.t('projects.samples.new.submit_button') - - visit group_url(@group12) - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - assert_equal 4, @subgroup12a.reload.samples_count - assert_equal 3, @subgroup12aa.reload.samples_count - assert_equal 1, @subgroup12b.reload.samples_count - assert_equal 3, @project31.reload.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - end - - test 'should update samples count after a sample transfer' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - within("li#group_#{@subgroup12b.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project30.puid - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - assert_equal 2, @project31.samples.size - assert_equal 1, @project30.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - - within("#project_#{@project30.id}-samples-count") do - assert_text @project30.samples.size - end - - visit namespace_project_samples_url(@subgroup12aa, @project31) - - find("input[type='checkbox'][id='sample_#{@sample34.id}']").click - click_link I18n.t('projects.samples.index.transfer_button') - - within('span[data-controller-connected="true"] dialog') do - assert_text I18n.t('projects.samples.transfers.dialog.description.singular') - within %(turbo-frame[id="list_selections"]) do - assert_text @sample34.name - end - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@project30.full_path}']").click - click_on I18n.t('projects.samples.transfers.dialog.submit_button') - end - - visit group_url(@group12) - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - within("li#group_#{@subgroup12b.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project30.puid - - assert_equal 2, @subgroup12a.reload.samples_count - assert_equal 1, @subgroup12aa.reload.samples_count - assert_equal 2, @subgroup12b.reload.samples_count - assert_equal 1, @project31.reload.samples.size - assert_equal 2, @project30.reload.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - - within("#project_#{@project30.id}-samples-count") do - assert_text @project30.samples.size - end - end - - test 'should update samples count after a sample clone' do - visit group_url(@group12) - - assert_selector 'h1', text: @group12.name - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - within("li#group_#{@subgroup12b.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project30.puid - - assert_equal 3, @subgroup12a.samples_count - assert_equal 1, @subgroup12b.samples_count - assert_equal 2, @project31.samples.size - assert_equal 1, @project30.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - - within("#project_#{@project30.id}-samples-count") do - assert_text @project30.samples.size - end - - visit namespace_project_samples_url(@subgroup12aa, @project31) - - find("input[type='checkbox'][id='sample_#{@sample34.id}']").click - click_link I18n.t('projects.samples.index.clone_button') - - within('span[data-controller-connected="true"] dialog') do - assert_text I18n.t('projects.samples.clones.dialog.description.singular') - within %(turbo-frame[id="list_selections"]) do - assert_text @sample34.name - end - find('input#select2-input').click - find("button[data-viral--select2-primary-param='#{@project30.full_path}']").click - click_on I18n.t('projects.samples.clones.dialog.submit_button') - end - assert_text I18n.t('projects.samples.clones.create.success') - - visit group_url(@group12) - - within("li#group_#{@subgroup12a.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @subgroup12aa.puid - - within("li#group_#{@subgroup12aa.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project31.puid - - assert_no_selector "#project_#{@project30.id}-samples-count" - - within("li#group_#{@subgroup12b.id}") do - find('a.folder-toggle-wrap').click - end - assert_text @project30.puid - - assert_equal 3, @subgroup12a.reload.samples_count - assert_equal 2, @subgroup12aa.reload.samples_count - assert_equal 2, @subgroup12b.reload.samples_count - assert_equal 2, @project31.reload.samples.size - assert_equal 2, @project30.reload.samples.size - - within("#group_#{@subgroup12a.id}-samples-count") do - assert_text @subgroup12a.samples_count - end - - within("#group_#{@subgroup12aa.id}-samples-count") do - assert_text @subgroup12aa.samples_count - end - - within("#group_#{@subgroup12b.id}-samples-count") do - assert_text @subgroup12b.samples_count - end - - within("#project_#{@project31.id}-samples-count") do - assert_text @project31.samples.size - end - - within("#project_#{@project30.id}-samples-count") do - assert_text @project30.samples.size - end - end - test 'filter shared groups and projects by puid' do subgroup3 = groups(:subgroup3) visit group_url(@group6) @@ -1129,4 +582,20 @@ def teardown assert_text I18n.t('groups.show.shared_namespaces.no_shared.title') assert_text I18n.t('groups.show.shared_namespaces.no_shared.description') end + + test 'should display a samples count that includes samples from shared groups and projects' do + group_three = groups(:group_three) + subgroup1 = groups(:subgroup1) + visit group_url(group_three) + + assert_selector 'h1', text: group_three.name + + click_on I18n.t(:'groups.show.tabs.shared_namespaces') + + assert_equal 3, subgroup1.aggregated_samples_count + + within("#group_#{subgroup1.id}-samples-count") do + assert_text subgroup1.aggregated_samples_count + end + end end