diff options
Diffstat (limited to 'spec/views')
13 files changed, 218 insertions, 284 deletions
diff --git a/spec/views/admin/application_settings/_ai_access.html.haml_spec.rb b/spec/views/admin/application_settings/_ai_access.html.haml_spec.rb deleted file mode 100644 index e9e640f7cc6..00000000000 --- a/spec/views/admin/application_settings/_ai_access.html.haml_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'admin/application_settings/_ai_access.html.haml', feature_category: :code_suggestions do - let_it_be(:admin) { build_stubbed(:admin) } - let(:page) { Capybara::Node::Simple.new(rendered) } - - before do - allow(::Gitlab).to receive(:org_or_com?).and_return(false) # Will not render partial for .com or .org - assign(:application_setting, application_setting) - allow(view).to receive(:current_user) { admin } - allow(view).to receive(:expanded).and_return(true) - end - - context 'when ai_access_token is not set' do - let(:application_setting) { build(:application_setting) } - - it 'renders an empty password field' do - render - expect(rendered).to have_field('Personal access token', type: 'password') - expect(page.find_field('Personal access token').value).to be_blank - end - end - - context 'when ai_access_token is set' do - let(:application_setting) do - build(:application_setting, ai_access_token: 'ai_access_token', - instance_level_code_suggestions_enabled: true) - end - - it 'renders masked password field' do - render - expect(rendered).to have_field('Enter new personal access token', type: 'password') - expect(page.find_field('Enter new personal access token').value).to eq(ApplicationSettingMaskedAttrs::MASK) - end - end -end diff --git a/spec/views/admin/application_settings/general.html.haml_spec.rb b/spec/views/admin/application_settings/general.html.haml_spec.rb index ee518041fbd..3b3a8a675a0 100644 --- a/spec/views/admin/application_settings/general.html.haml_spec.rb +++ b/spec/views/admin/application_settings/general.html.haml_spec.rb @@ -114,29 +114,31 @@ RSpec.describe 'admin/application_settings/general.html.haml' do end end - describe 'instance-level code suggestions settings', feature_category: :code_suggestions do + # for the licensed tests, refer to ee/spec/views/admin/application_settings/general.html.haml_spec.rb + describe 'instance-level code suggestions settings', :without_license, feature_category: :code_suggestions do before do allow(::Gitlab).to receive(:org_or_com?).and_return(gitlab_org_or_com?) render end - context 'when on .com or .org' do - let(:gitlab_org_or_com?) { true } - + shared_examples 'does not render the form' do it 'does not render the form' do expect(rendered).not_to have_field('application_setting_instance_level_code_suggestions_enabled') expect(rendered).not_to have_field('application_setting_ai_access_token') end end + context 'when on .com or .org' do + let(:gitlab_org_or_com?) { true } + + it_behaves_like 'does not render the form' + end + context 'when not on .com and not on .org' do let(:gitlab_org_or_com?) { false } - it 'renders the form' do - expect(rendered).to have_field('application_setting_instance_level_code_suggestions_enabled') - expect(rendered).to have_field('application_setting_ai_access_token') - end + it_behaves_like 'does not render the form' end end end diff --git a/spec/views/devise/registrations/new.html.haml_spec.rb b/spec/views/devise/registrations/new.html.haml_spec.rb deleted file mode 100644 index 55025424573..00000000000 --- a/spec/views/devise/registrations/new.html.haml_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'devise/registrations/new', feature_category: :user_management do - describe 'broadcast messaging' do - before do - allow(view).to receive(:devise_mapping).and_return(Devise.mappings[:user]) - allow(view).to receive(:resource).and_return(build(:user)) - allow(view).to receive(:resource_name).and_return(:user) - allow(view).to receive(:registration_path_params).and_return({}) - allow(view).to receive(:glm_tracking_params).and_return({}) - allow(view).to receive(:arkose_labs_enabled?).and_return(true) - end - - it 'does not render the broadcast layout' do - render - - expect(rendered).not_to render_template('layouts/_broadcast') - end - - context 'when SaaS', :saas do - it 'does not render the broadcast layout' do - render - - expect(rendered).not_to render_template('layouts/_broadcast') - end - end - end -end diff --git a/spec/views/devise/sessions/new.html.haml_spec.rb b/spec/views/devise/sessions/new.html.haml_spec.rb index adfe68824c5..70ca0bb2195 100644 --- a/spec/views/devise/sessions/new.html.haml_spec.rb +++ b/spec/views/devise/sessions/new.html.haml_spec.rb @@ -102,27 +102,6 @@ RSpec.describe 'devise/sessions/new' do end end - describe 'broadcast messaging' do - before do - stub_devise - disable_captcha - end - - it 'renders the broadcast layout' do - render - - expect(rendered).to render_template('layouts/_broadcast') - end - - context 'when SaaS', :saas do - it 'does not render the broadcast layout' do - render - - expect(rendered).not_to render_template('layouts/_broadcast') - end - end - end - def disable_other_signin_methods allow(view).to receive(:password_authentication_enabled_for_web?).and_return(false) allow(view).to receive(:omniauth_enabled?).and_return(false) diff --git a/spec/views/layouts/application.html.haml_spec.rb b/spec/views/layouts/application.html.haml_spec.rb index a3613329984..825e295b73d 100644 --- a/spec/views/layouts/application.html.haml_spec.rb +++ b/spec/views/layouts/application.html.haml_spec.rb @@ -3,74 +3,91 @@ require 'spec_helper' RSpec.describe 'layouts/application' do - let(:user) { create(:user) } + context 'when user is signed in' do + let(:user) { create(:user) } - before do - allow(view).to receive(:current_user).and_return(user) - allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user)) - end + before do + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user)) + end - it_behaves_like 'a layout which reflects the application theme setting' - it_behaves_like 'a layout which reflects the preferred language' + it_behaves_like 'a layout which reflects the application theme setting' + it_behaves_like 'a layout which reflects the preferred language' - describe "visual review toolbar" do - context "ENV['REVIEW_APPS_ENABLED'] is set to true" do - before do - stub_env( - 'REVIEW_APPS_ENABLED' => true, - 'REVIEW_APPS_MERGE_REQUEST_IID' => '123' - ) + describe "visual review toolbar" do + context "ENV['REVIEW_APPS_ENABLED'] is set to true" do + before do + stub_env( + 'REVIEW_APPS_ENABLED' => true, + 'REVIEW_APPS_MERGE_REQUEST_IID' => '123' + ) + end + + it 'renders the visual review toolbar' do + render + + expect(rendered).to include('review-app-toolbar-script') + end end - it 'renders the visual review toolbar' do - render + context "ENV['REVIEW_APPS_ENABLED'] is set to false" do + before do + stub_env('REVIEW_APPS_ENABLED', false) + end - expect(rendered).to include('review-app-toolbar-script') + it 'does not render the visual review toolbar' do + render + + expect(rendered).not_to include('review-app-toolbar-script') + end end end - context "ENV['REVIEW_APPS_ENABLED'] is set to false" do - before do - stub_env('REVIEW_APPS_ENABLED', false) + context 'body data elements for pageview context' do + let(:body_data) do + { + body_data_page: 'projects:issues:show', + body_data_page_type_id: '1', + body_data_project_id: '2', + body_data_namespace_id: '3' + } end - it 'does not render the visual review toolbar' do + before do + allow(view).to receive(:body_data).and_return(body_data) render - - expect(rendered).not_to include('review-app-toolbar-script') end - end - end - context 'body data elements for pageview context' do - let(:body_data) do - { - body_data_page: 'projects:issues:show', - body_data_page_type_id: '1', - body_data_project_id: '2', - body_data_namespace_id: '3' - } - end + it 'includes the body element page' do + expect(rendered).to include('data-page="projects:issues:show"') + end - before do - allow(view).to receive(:body_data).and_return(body_data) - render - end + it 'includes the body element page_type_id' do + expect(rendered).to include('data-page-type-id="1"') + end - it 'includes the body element page' do - expect(rendered).to include('data-page="projects:issues:show"') - end + it 'includes the body element project_id' do + expect(rendered).to include('data-project-id="2"') + end - it 'includes the body element page_type_id' do - expect(rendered).to include('data-page-type-id="1"') + it 'includes the body element namespace_id' do + expect(rendered).to include('data-namespace-id="3"') + end end + end - it 'includes the body element project_id' do - expect(rendered).to include('data-project-id="2"') + context 'when user is not signed in' do + before do + allow(view).to receive(:current_user).and_return(nil) + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(nil)) + Feature.enable(:super_sidebar_logged_out) end - it 'includes the body element namespace_id' do - expect(rendered).to include('data-namespace-id="3"') + it 'renders the new marketing header for logged-out users' do + allow(view).to receive(:render) + allow(view).to receive(:render).with({ template: "layouts/application" }, {}).and_call_original + render + expect(view).to have_received(:render).with({ partial: "layouts/header/super_sidebar_logged_out" }) end end end diff --git a/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb b/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb new file mode 100644 index 00000000000..89a03d72a90 --- /dev/null +++ b/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'layouts/header/_super_sidebar_logged_out', feature_category: :navigation do + before do + allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(nil)) + Feature.enable(:super_sidebar_logged_out) + end + + context 'on gitlab.com' do + before do + allow(Gitlab).to receive(:com?).and_return(true) + render + end + + it 'renders marketing links' do + expect(rendered).to have_content('Why GitLab') + expect(rendered).to have_content('Pricing') + expect(rendered).to have_content('Contact Sales') + end + end + + context 'on self-managed' do + it 'does not render marketing links' do + render + expect(rendered).not_to have_content('Why GitLab') + expect(rendered).not_to have_content('Pricing') + expect(rendered).not_to have_content('Contact Sales') + end + end + + it 'renders links to Explore and Sign-in and Register' do + render + expect(rendered).to have_content('Explore') + expect(rendered).to have_content('Sign in') + expect(rendered).to have_content('Register') + end +end diff --git a/spec/views/profiles/keys/_key.html.haml_spec.rb b/spec/views/profiles/keys/_key.html.haml_spec.rb index 4d14ce7c909..9ce6779d3ae 100644 --- a/spec/views/profiles/keys/_key.html.haml_spec.rb +++ b/spec/views/profiles/keys/_key.html.haml_spec.rb @@ -39,7 +39,7 @@ RSpec.describe 'profiles/keys/_key.html.haml', feature_category: :system_access it 'renders "Unavailable" for last used' do render - expect(rendered).to have_text('Last used: Unavailable') + expect(rendered).to have_text('Unavailable') end end @@ -62,7 +62,7 @@ RSpec.describe 'profiles/keys/_key.html.haml', feature_category: :system_access it 'renders "Never" for last used' do render - expect(rendered).to have_text('Last used: Never') + expect(rendered).to have_text('Never') end end end @@ -85,11 +85,11 @@ RSpec.describe 'profiles/keys/_key.html.haml', feature_category: :system_access expect(rendered).to have_text(usage_type_text) displayed_buttons.each do |button| - expect(rendered).to have_text(button) + expect(rendered).to have_css("button[aria-label=#{button}]") end hidden_buttons.each do |button| - expect(rendered).not_to have_text(button) + expect(rendered).not_to have_css("button[aria-label=#{button}]") end end end @@ -103,17 +103,17 @@ RSpec.describe 'profiles/keys/_key.html.haml', feature_category: :system_access it 'renders "Never" for expires' do render - expect(rendered).to have_text('Expires: Never') + expect(rendered).to have_text('Never') end end context 'when the key has expired' do let_it_be(:key) { create(:personal_key, :expired, user: user) } - it 'renders "Expired:" as the expiration date label' do + it 'renders "Expired" as the expiration date label' do render - expect(rendered).to have_text('Expired:') + expect(rendered).to have_text('Expired') end end diff --git a/spec/views/projects/commits/show.html.haml_spec.rb b/spec/views/projects/commits/show.html.haml_spec.rb index e5e9906a798..9393ba046dc 100644 --- a/spec/views/projects/commits/show.html.haml_spec.rb +++ b/spec/views/projects/commits/show.html.haml_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe 'projects/commits/show.html.haml' do - let(:project) { create(:project, :repository) } - let(:commits) { [project.commit] } + let_it_be(:project) { create(:project, :repository) } + + let(:commits) { [commit] } + let(:commit) { project.commit } let(:path) { 'path/to/doc.md' } before do @@ -32,4 +34,32 @@ RSpec.describe 'projects/commits/show.html.haml' do expect(rendered).to have_link(href: "#{project_commits_path(project, path)}?format=atom") end end + + context 'commits date headers' do + let(:user) { build(:user, timezone: timezone) } + let(:committed_date) { Time.find_zone('UTC').parse('2023-01-01') } + + before do + allow(view).to receive(:current_user).and_return(user) + allow(commit).to receive(:committed_date).and_return(committed_date) + + render + end + + context 'when timezone is UTC' do + let(:timezone) { 'UTC' } + + it "renders commit date header in user's timezone" do + expect(rendered).to include('data-day="2023-01-01"') + end + end + + context 'when timezone is UTC-6' do + let(:timezone) { 'America/Mexico_City' } + + it "renders commit date header in user's timezone" do + expect(rendered).to include('data-day="2022-12-31"') + end + end + end end diff --git a/spec/views/projects/issues/show.html.haml_spec.rb b/spec/views/projects/issues/show.html.haml_spec.rb index 3f1496a24ce..e316ff58b95 100644 --- a/spec/views/projects/issues/show.html.haml_spec.rb +++ b/spec/views/projects/issues/show.html.haml_spec.rb @@ -5,129 +5,6 @@ require 'spec_helper' RSpec.describe 'projects/issues/show' do include_context 'project show action' - context 'when the issue is closed' do - before do - allow(issue).to receive(:closed?).and_return(true) - allow(view).to receive(:current_user).and_return(user) - end - - context 'when the issue was moved' do - let(:new_issue) { create(:issue, project: project, author: user) } - - before do - issue.moved_to = new_issue - end - - context 'when user can see the moved issue' do - before do - project.add_developer(user) - end - - it 'shows "Closed (moved)" if an issue has been moved and closed' do - render - - expect(rendered).to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed (moved)') - end - - it 'shows "Closed (moved)" if an issue has been moved and discussion is locked' do - allow(issue).to receive(:discussion_locked).and_return(true) - render - - expect(rendered).to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed (moved)') - end - - it 'links "moved" to the new issue the original issue was moved to' do - render - - expect(rendered).to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'moved') - end - - it 'does not show "closed (moved)" if an issue has been moved and reopened (not closed)' do - allow(issue).to receive(:closed?).and_return(false) - - render - - expect(rendered).not_to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed (moved)') - end - end - - context 'when user cannot see moved issue' do - it 'does not show moved issue link' do - render - - expect(rendered).not_to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'moved') - end - end - end - - context 'when the issue was duplicated' do - let(:new_issue) { create(:issue, project: project, author: user) } - - before do - issue.duplicated_to = new_issue - end - - context 'when user can see the duplicated issue' do - before do - project.add_developer(user) - end - - it 'shows "Closed (duplicated)" if an issue has been duplicated' do - render - - expect(rendered).to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed (duplicated)') - end - - it 'links "duplicated" to the new issue the original issue was duplicated to' do - render - - expect(rendered).to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'duplicated') - end - end - - context 'when user cannot see duplicated issue' do - it 'does not show duplicated issue link' do - render - - expect(rendered).not_to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'duplicated') - end - end - end - - it 'shows "Closed" if an issue has not been moved or duplicated' do - render - - expect(rendered).to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed') - end - - it 'shows "Closed" if discussion is locked' do - allow(issue).to receive(:discussion_locked).and_return(true) - render - - expect(rendered).to have_selector('.issuable-status-badge-closed:not(.hidden)', text: 'Closed') - end - end - - context 'when the issue is open' do - before do - allow(issue).to receive(:closed?).and_return(false) - allow(issue).to receive(:discussion_locked).and_return(false) - end - - it 'shows "Open" if an issue has been moved' do - render - - expect(rendered).to have_selector('.issuable-status-badge-open:not(.hidden)', text: 'Open') - end - - it 'shows "Open" if discussion is locked' do - allow(issue).to receive(:discussion_locked).and_return(true) - render - - expect(rendered).to have_selector('.issuable-status-badge-open:not(.hidden)', text: 'Open') - end - end - context 'when the issue is related to a sentry error' do it 'renders a stack trace' do sentry_issue = double(:sentry_issue, sentry_issue_identifier: '1066622') diff --git a/spec/views/projects/pages/_pages_settings.html.haml_spec.rb b/spec/views/projects/pages/_pages_settings.html.haml_spec.rb new file mode 100644 index 00000000000..4f54ddbdb60 --- /dev/null +++ b/spec/views/projects/pages/_pages_settings.html.haml_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'projects/pages/_pages_settings', feature_category: :pages do + let_it_be(:project) { build_stubbed(:project, :repository) } + let_it_be(:user) { build_stubbed(:user) } + + before do + assign(:project, project) + allow(view).to receive(:current_user).and_return(user) + end + + context 'for pages unique domain' do + it 'shows the unique domain toggle' do + render + + expect(rendered).to have_content('Use unique domain') + end + end +end diff --git a/spec/views/pwa/manifest.json.erb_spec.rb b/spec/views/pwa/manifest.json.erb_spec.rb new file mode 100644 index 00000000000..a5075bfe6fe --- /dev/null +++ b/spec/views/pwa/manifest.json.erb_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'pwa/manifest', feature_category: :navigation do + describe 'view caching', :use_clean_rails_memory_store_fragment_caching do + let(:appearance) { build_stubbed(:appearance, pwa_name: 'My GitLab') } + + context 'when appearance is unchanged' do + it 'reuses the cached view' do + allow(view).to receive(:current_appearance).and_return(appearance) + allow(view).to receive(:appearance_pwa_name).and_call_original + render + render + + expect(view).to have_received(:appearance_pwa_name).once + end + end + + context 'when appearance has changed' do + let(:changed_appearance) { build_stubbed(:appearance, pwa_name: 'My new GitLab') } + + it 'does not use the cached view' do + allow(view).to receive(:current_appearance).and_return(appearance) + allow(view).to receive(:appearance_pwa_name).and_call_original + render + + allow(view).to receive(:current_appearance).and_return(changed_appearance) + render + + expect(view).to have_received(:appearance_pwa_name).twice + expect(rendered).to have_content 'My new GitLab' + end + end + end +end diff --git a/spec/views/registrations/welcome/show.html.haml_spec.rb b/spec/views/registrations/welcome/show.html.haml_spec.rb index 866f4f62493..4188bd7e956 100644 --- a/spec/views/registrations/welcome/show.html.haml_spec.rb +++ b/spec/views/registrations/welcome/show.html.haml_spec.rb @@ -6,6 +6,7 @@ RSpec.describe 'registrations/welcome/show', feature_category: :onboarding do let_it_be(:user) { create(:user) } before do + allow(view).to receive(:onboarding_status).and_return(Onboarding::Status.new({}, {}, user)) allow(view).to receive(:current_user).and_return(user) allow(view).to receive(:welcome_update_params).and_return({}) diff --git a/spec/views/shared/_label_row.html.haml_spec.rb b/spec/views/shared/_label_row.html.haml_spec.rb index eb277930c1d..ef5a479d736 100644 --- a/spec/views/shared/_label_row.html.haml_spec.rb +++ b/spec/views/shared/_label_row.html.haml_spec.rb @@ -25,8 +25,8 @@ RSpec.describe 'shared/_label_row.html.haml' do expect(rendered).to have_text(label.title) end - it 'has a non-linked label title' do - expect(rendered).not_to have_link(label.title) + it 'has a linked label title' do + expect(rendered).to have_link(label.title) end it 'has Issues link' do @@ -57,8 +57,8 @@ RSpec.describe 'shared/_label_row.html.haml' do expect(rendered).to have_text(label.title) end - it 'has a non-linked label title' do - expect(rendered).not_to have_link(label.title) + it 'has a linked label title' do + expect(rendered).to have_link(label.title) end it 'has Issues link' do @@ -85,8 +85,8 @@ RSpec.describe 'shared/_label_row.html.haml' do expect(rendered).to have_text(label.title) end - it 'has a non-linked label title' do - expect(rendered).not_to have_link(label.title) + it 'has a linked label title' do + expect(rendered).to have_link(label.title) end it 'has Issues link' do @@ -111,8 +111,8 @@ RSpec.describe 'shared/_label_row.html.haml' do expect(rendered).to have_text(label.title) end - it 'has a non-linked label title' do - expect(rendered).not_to have_link(label.title) + it 'has a linked label title' do + expect(rendered).to have_link(label.title) end it 'does not show Issues link' do |