diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index a54e0351d2f1c3a9f6fb53e0a6fec2eb37bbe522..7e69cf1d6857553d19834e46bcbff49fafe42988 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -8,6 +8,9 @@ - @left_sidebar = true - @content_class = [@content_class, project_classes(@project)].compact.join(" ") +- content_for :flash_message do + = render "layouts/header/storage_enforcement_banner", namespace: @project.namespace + - content_for :project_javascripts do - project = @target_project || @project - if current_user diff --git a/ee/spec/features/boards/scoped_issue_board_spec.rb b/ee/spec/features/boards/scoped_issue_board_spec.rb index ad5765f99a9b902ca979b0fe3f7b43437df2263b..57bed59dc2e8f85055429e4e32cf322f83450628 100644 --- a/ee/spec/features/boards/scoped_issue_board_spec.rb +++ b/ee/spec/features/boards/scoped_issue_board_spec.rb @@ -390,7 +390,7 @@ expect(page).to have_selector('.board-card', count: 0) - expect(page).not_to have_selector('.gl-alert-body') + expect(page).not_to have_text('Unable to save your changes. Please try again.') end end @@ -422,7 +422,7 @@ update_board_scope('current_iteration', false) expect(page).to have_selector('.board-card', count: 3) - expect(page).not_to have_selector('.gl-alert-body') + expect(page).not_to have_text('Unable to save your changes. Please try again.') end end end @@ -439,7 +439,7 @@ click_button 'Save changes' - expect(page).to have_selector('.gl-alert-body') + expect(page).to have_text('Unable to save your changes. Please try again.') end end end diff --git a/spec/features/groups_spec.rb b/spec/features/groups_spec.rb index 31390b110e7f7e8b1830e39664ef2d23e26fe0c3..58443b66858a51698ca14d936dc52c068804ebeb 100644 --- a/spec/features/groups_spec.rb +++ b/spec/features/groups_spec.rb @@ -499,8 +499,6 @@ def remove_with_confirm(button_text, confirm_with) let_it_be_with_refind(:user) { create(:user) } before do - stub_feature_flags(namespace_storage_limit_bypass_date_check: false) - group.add_owner(user) sign_in(user) end @@ -509,8 +507,8 @@ def remove_with_confirm(button_text, confirm_with) let_it_be(:storage_enforcement_date) { Date.today + 30 } before do - allow_next_found_instance_of(Group) do |g| - allow(g).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) end end @@ -520,8 +518,8 @@ def remove_with_confirm(button_text, confirm_with) end it 'does not display the banner in a paid group page' do - allow_next_found_instance_of(Group) do |g| - allow(g).to receive(:paid?).and_return(true) + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:paid?).and_return(true) end visit group_path(group) expect_page_not_to_have_storage_enforcement_banner @@ -531,12 +529,13 @@ def remove_with_confirm(button_text, confirm_with) visit group_path(group) expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) find('.js-storage-enforcement-banner [data-testid="close-icon"]').click + wait_for_requests page.refresh expect_page_not_to_have_storage_enforcement_banner storage_enforcement_date = Date.today + 13 - allow_next_found_instance_of(Group) do |g| - allow(g).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) end page.refresh expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) @@ -547,6 +546,7 @@ def remove_with_confirm(button_text, confirm_with) # This test should break and be rewritten after the implementation of the storage_enforcement_date # TBD: https://gitlab.com/gitlab-org/gitlab/-/issues/350632 it 'does not display the banner in the group page' do + stub_feature_flags(namespace_storage_limit_bypass_date_check: false) visit group_path(group) expect_page_not_to_have_storage_enforcement_banner end diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index db64f84aa76c6919ddfaf5e185c146c32f5b3e3a..f6f9c7f0d3c767159951b834f09a6ac468605d64 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -440,6 +440,99 @@ end end + describe 'storage_enforcement_banner', :js do + let_it_be(:group) { create(:group) } + let_it_be_with_refind(:user) { create(:user) } + let_it_be(:project) { create(:project, group: group) } + + before do + group.add_maintainer(user) + sign_in(user) + end + + context 'with storage_enforcement_date set' do + let_it_be(:storage_enforcement_date) { Date.today + 30 } + + before do + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + end + end + + it 'displays the banner in the project page' do + visit project_path(project) + expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + end + + context 'when in a subgroup project page' do + let_it_be(:subgroup) { create(:group, parent: group) } + let_it_be(:project) { create(:project, namespace: subgroup) } + + it 'displays the banner' do + visit project_path(project) + expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + end + end + + context 'when in a user namespace project page' do + let_it_be(:project) { create(:project, namespace: user.namespace) } + + before do + allow_next_found_instance_of(Namespaces::UserNamespace) do |namspace| + allow(namspace).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + end + end + + it 'displays the banner' do + visit project_path(project) + expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + end + end + + it 'does not display the banner in a paid group project page' do + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:paid?).and_return(true) + end + visit project_path(project) + expect_page_not_to_have_storage_enforcement_banner + end + + it 'does not display the banner if user has previously closed unless threshold has changed' do + visit project_path(project) + expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + find('.js-storage-enforcement-banner [data-testid="close-icon"]').click + wait_for_requests + page.refresh + expect_page_not_to_have_storage_enforcement_banner + + storage_enforcement_date = Date.today + 13 + allow_next_found_instance_of(Group) do |grp| + allow(grp).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + end + page.refresh + expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + end + end + + context 'with storage_enforcement_date not set' do + # This test should break and be rewritten after the implementation of the storage_enforcement_date + # TBD: https://gitlab.com/gitlab-org/gitlab/-/issues/350632 + it 'does not display the banner in the group page' do + stub_feature_flags(namespace_storage_limit_bypass_date_check: false) + visit project_path(project) + expect_page_not_to_have_storage_enforcement_banner + end + end + end + + def expect_page_to_have_storage_enforcement_banner(storage_enforcement_date) + expect(page).to have_text "From #{storage_enforcement_date} storage limits will apply to this namespace" + end + + def expect_page_not_to_have_storage_enforcement_banner + expect(page).not_to have_text "storage limits will apply to this namespace" + end + def remove_with_confirm(button_text, confirm_with, confirm_button_text = 'Confirm') click_button button_text fill_in 'confirm_name_input', with: confirm_with