diff options
Diffstat (limited to 'spec/views')
15 files changed, 257 insertions, 114 deletions
diff --git a/spec/views/admin/application_settings/_package_registry.html.haml_spec.rb b/spec/views/admin/application_settings/_package_registry.html.haml_spec.rb index 18a2e29adab..cb41f2e636e 100644 --- a/spec/views/admin/application_settings/_package_registry.html.haml_spec.rb +++ b/spec/views/admin/application_settings/_package_registry.html.haml_spec.rb @@ -47,7 +47,7 @@ RSpec.describe 'admin/application_settings/_package_registry' do it 'does not display the plan name when there is only one plan' do subject - expect(page).not_to have_content('Default') + expect(page).not_to have_selector('a[data-action="plan0"]') end end diff --git a/spec/views/admin/application_settings/ci_cd.html.haml_spec.rb b/spec/views/admin/application_settings/ci_cd.html.haml_spec.rb index 4d40bf5671e..e4ebdd706d4 100644 --- a/spec/views/admin/application_settings/ci_cd.html.haml_spec.rb +++ b/spec/views/admin/application_settings/ci_cd.html.haml_spec.rb @@ -15,42 +15,17 @@ RSpec.describe 'admin/application_settings/ci_cd.html.haml' do end describe 'CI CD Runner Registration' do - context 'when feature flag is enabled' do - before do - stub_feature_flags(runner_registration_control: true) - end + it 'has the setting section' do + render - it 'has the setting section' do - render - - expect(rendered).to have_css("#js-runner-settings") - end - - it 'renders the correct setting section content' do - render - - expect(rendered).to have_content("Runner registration") - expect(rendered).to have_content("If no options are selected, only administrators can register runners.") - end + expect(rendered).to have_css("#js-runner-settings") end - context 'when feature flag is disabled' do - before do - stub_feature_flags(runner_registration_control: false) - end - - it 'does not have the setting section' do - render - - expect(rendered).not_to have_css("#js-runner-settings") - end - - it 'does not render the correct setting section content' do - render + it 'renders the correct setting section content' do + render - expect(rendered).not_to have_content("Runner registration") - expect(rendered).not_to have_content("If no options are selected, only administrators can register runners.") - end + expect(rendered).to have_content("Runner registration") + expect(rendered).to have_content("If no options are selected, only administrators can register runners.") end end end diff --git a/spec/views/admin/broadcast_messages/index.html.haml_spec.rb b/spec/views/admin/broadcast_messages/index.html.haml_spec.rb index e1dc76428df..ba998085bf9 100644 --- a/spec/views/admin/broadcast_messages/index.html.haml_spec.rb +++ b/spec/views/admin/broadcast_messages/index.html.haml_spec.rb @@ -3,20 +3,22 @@ require 'spec_helper' RSpec.describe 'admin/broadcast_messages/index' do - describe 'Target roles select and table column' do - let(:feature_flag_state) { true } + let(:role_targeted_broadcast_messages) { true } + let(:vue_broadcast_messages) { false } - let_it_be(:message) { create(:broadcast_message, broadcast_type: 'banner', target_access_levels: [Gitlab::Access::GUEST, Gitlab::Access::DEVELOPER]) } + let_it_be(:message) { create(:broadcast_message, broadcast_type: 'banner', target_access_levels: [Gitlab::Access::GUEST, Gitlab::Access::DEVELOPER]) } - before do - assign(:broadcast_messages, BroadcastMessage.page(1)) - assign(:broadcast_message, BroadcastMessage.new) + before do + assign(:broadcast_messages, BroadcastMessage.page(1)) + assign(:broadcast_message, BroadcastMessage.new) - stub_feature_flags(role_targeted_broadcast_messages: feature_flag_state) + stub_feature_flags(role_targeted_broadcast_messages: role_targeted_broadcast_messages) + stub_feature_flags(vue_broadcast_messages: vue_broadcast_messages) - render - end + render + end + describe 'Target roles select and table column' do it 'rendered' do expect(rendered).to have_content('Target roles') expect(rendered).to have_content('Owner') @@ -24,7 +26,7 @@ RSpec.describe 'admin/broadcast_messages/index' do end context 'when feature flag is off' do - let(:feature_flag_state) { false } + let(:role_targeted_broadcast_messages) { false } it 'is not rendered' do expect(rendered).not_to have_content('Target roles') @@ -33,4 +35,18 @@ RSpec.describe 'admin/broadcast_messages/index' do end end end + + describe 'Vue application' do + it 'is not rendered' do + expect(rendered).not_to have_selector('#js-broadcast-messages') + end + + context 'when feature flag is on' do + let(:vue_broadcast_messages) { true } + + it 'is rendered' do + expect(rendered).to have_selector('#js-broadcast-messages') + end + end + end end diff --git a/spec/views/events/event/_common.html.haml_spec.rb b/spec/views/events/event/_common.html.haml_spec.rb index 0de84e2fdb8..ad8e5c2ef77 100644 --- a/spec/views/events/event/_common.html.haml_spec.rb +++ b/spec/views/events/event/_common.html.haml_spec.rb @@ -7,33 +7,41 @@ RSpec.describe 'events/event/_common.html.haml' do let_it_be(:issue) { create(:issue, project: project) } let_it_be(:user) { create(:user) } + before do + render partial: 'events/event/common', locals: { event: event.present } + end + context 'when it is a work item event' do - let(:work_item) { create(:work_item, project: project) } + let_it_be(:work_item) { create(:work_item, :task, project: project) } - let(:event) do + let_it_be(:event) do create(:event, :created, project: project, target: work_item, target_type: 'WorkItem', author: user) end it 'renders the correct url' do - render partial: 'events/event/common', locals: { event: event.present } - expect(rendered).to have_link( work_item.reference_link_text, href: "/#{project.full_path}/-/work_items/#{work_item.id}" ) end + + it 'uses issue_type for the target_name' do + expect(rendered).to have_content("#{s_('Event|opened')} task #{work_item.to_reference}") + end end - context 'when it is an isssue event' do - let(:issue) { create(:issue, project: project) } + context 'when it is an issue event' do + let_it_be(:issue) { create(:issue, project: project) } - let(:event) do + let_it_be(:event) do create(:event, :created, project: project, target: issue, author: user) end it 'renders the correct url' do - render partial: 'events/event/common', locals: { event: event.present } - expect(rendered).to have_link(issue.reference_link_text, href: "/#{project.full_path}/-/issues/#{issue.iid}") end + + it 'uses issue_type for the target_name' do + expect(rendered).to have_content("#{s_('Event|opened')} issue #{issue.to_reference}") + end end end diff --git a/spec/views/groups/new.html.haml_spec.rb b/spec/views/groups/new.html.haml_spec.rb index 5c7378e8dc7..0bbc4c1d717 100644 --- a/spec/views/groups/new.html.haml_spec.rb +++ b/spec/views/groups/new.html.haml_spec.rb @@ -36,4 +36,11 @@ RSpec.describe 'groups/new.html.haml' do expect(rendered).to have_field('Public') end end + + describe 'role field' do + it 'does have a default selection' do + expect(rendered).to have_content('Role') + expect(rendered).to have_select('Role', selected: 'Software Developer') + end + end end diff --git a/spec/views/layouts/_flash.html.haml_spec.rb b/spec/views/layouts/_flash.html.haml_spec.rb index a4bed09368f..d88977b194a 100644 --- a/spec/views/layouts/_flash.html.haml_spec.rb +++ b/spec/views/layouts/_flash.html.haml_spec.rb @@ -3,9 +3,20 @@ require 'spec_helper' RSpec.describe 'layouts/_flash' do + let_it_be(:template) { 'layouts/_flash' } + let_it_be(:flash_container_no_margin_class) { 'flash-container-no-margin' } + + let(:locals) { {} } + before do allow(view).to receive(:flash).and_return(flash) - render + render(template: template, locals: locals) + end + + describe 'default' do + it 'does not render flash container no margin class' do + expect(rendered).not_to have_selector(".#{flash_container_no_margin_class}") + end end describe 'closable flash messages' do @@ -17,7 +28,7 @@ RSpec.describe 'layouts/_flash' do let(:flash) { { flash_type => 'This is a closable flash message' } } it 'shows a close button' do - expect(rendered).to include('js-close-icon') + expect(rendered).to include('js-close') end end end @@ -31,8 +42,16 @@ RSpec.describe 'layouts/_flash' do let(:flash) { { flash_type => 'This is a non closable flash message' } } it 'does not show a close button' do - expect(rendered).not_to include('js-close-icon') + expect(rendered).not_to include('js-close') end end end + + describe 'with flash_class in locals' do + let(:locals) { { flash_container_no_margin: true } } + + it 'adds class to flash-container' do + expect(rendered).to have_selector(".flash-container.#{flash_container_no_margin_class}") + end + end end diff --git a/spec/views/layouts/fullscreen.html.haml_spec.rb b/spec/views/layouts/fullscreen.html.haml_spec.rb index 14b382bc238..7b345fea2ad 100644 --- a/spec/views/layouts/fullscreen.html.haml_spec.rb +++ b/spec/views/layouts/fullscreen.html.haml_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' RSpec.describe 'layouts/fullscreen' do + let_it_be(:template) { 'layouts/fullscreen' } + let_it_be(:top_nav_partial) { 'layouts/header/_default' } + let_it_be(:top_nav_responsive_partial) { 'layouts/nav/_top_nav_responsive' } + let_it_be(:user) { create(:user) } before do @@ -16,6 +20,20 @@ RSpec.describe 'layouts/fullscreen' do expect(rendered).to have_selector(".gl--flex-full.gl-w-full") end + it 'renders flash container' do + render + + expect(view).to render_template("layouts/_flash") + expect(rendered).to have_selector(".flash-container.flash-container-no-margin") + end + + it 'renders top nav' do + render + + expect(view).to render_template(top_nav_partial) + expect(view).to render_template(top_nav_responsive_partial) + end + it_behaves_like 'a layout which reflects the application theme setting' describe 'sidebar' do @@ -51,4 +69,15 @@ RSpec.describe 'layouts/fullscreen' do end end end + + context 'when minimal is set' do + subject { render(template: template, formats: :html, locals: { minimal: true }) } + + it 'does not render top nav' do + subject + + expect(view).not_to render_template(top_nav_partial) + expect(view).not_to render_template(top_nav_responsive_partial) + end + end end diff --git a/spec/views/layouts/header/_gitlab_version.html.haml_spec.rb b/spec/views/layouts/header/_gitlab_version.html.haml_spec.rb index 0e24810f835..2f423c72ca6 100644 --- a/spec/views/layouts/header/_gitlab_version.html.haml_spec.rb +++ b/spec/views/layouts/header/_gitlab_version.html.haml_spec.rb @@ -12,5 +12,11 @@ RSpec.describe 'layouts/header/_gitlab_version' do it 'renders the version check badge' do expect(rendered).to have_selector('.js-gitlab-version-check') end + + it 'renders the container as a link' do + expect(rendered).to have_selector( + 'a[data-testid="gitlab-version-container"][href="/help/update/index"]' + ) + end end end diff --git a/spec/views/layouts/nav/sidebar/_profile.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_profile.html.haml_spec.rb index 3d28be68b25..f5a0a7a935c 100644 --- a/spec/views/layouts/nav/sidebar/_profile.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_profile.html.haml_spec.rb @@ -11,4 +11,20 @@ RSpec.describe 'layouts/nav/sidebar/_profile' do it_behaves_like 'has nav sidebar' it_behaves_like 'sidebar includes snowplow attributes', 'render', 'user_side_navigation', 'user_side_navigation' + + it 'has a link to access tokens' do + render + + expect(rendered).to have_link(_('Access Tokens'), href: profile_personal_access_tokens_path) + end + + context 'when personal access tokens are disabled' do + it 'does not have a link to access tokens' do + allow(::Gitlab::CurrentSettings).to receive_messages(personal_access_tokens_disabled?: true) + + render + + expect(rendered).not_to have_link(_('Access Tokens'), href: profile_personal_access_tokens_path) + end + end end diff --git a/spec/views/projects/hooks/edit.html.haml_spec.rb b/spec/views/projects/hooks/edit.html.haml_spec.rb index c4ec2149794..2a95656645e 100644 --- a/spec/views/projects/hooks/edit.html.haml_spec.rb +++ b/spec/views/projects/hooks/edit.html.haml_spec.rb @@ -27,7 +27,7 @@ RSpec.describe 'projects/hooks/edit' do it 'renders alert' do render - expect(rendered).to have_text(s_('Webhooks|Webhook was automatically disabled')) + expect(rendered).to have_text(s_('Webhooks|Webhook rate limit has been reached')) end end diff --git a/spec/views/projects/merge_requests/_close_reopen_draft_report_toggle.html.haml_spec.rb b/spec/views/projects/merge_requests/_close_reopen_draft_report_toggle.html.haml_spec.rb new file mode 100644 index 00000000000..416f4253e1b --- /dev/null +++ b/spec/views/projects/merge_requests/_close_reopen_draft_report_toggle.html.haml_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'projects/merge_requests/_close_reopen_draft_report_toggle.html.haml' do + let_it_be(:merge_request) { create(:merge_request, state: :merged) } + + before do + assign(:merge_request, merge_request) + assign(:project, merge_request.target_project) + + allow(view).to receive(:moved_mr_sidebar_enabled?).and_return(true) + end + + describe 'notifcations toggle' do + context 'when mr merged and logged in' do + it 'is present' do + allow(view).to receive(:current_user).and_return(merge_request.author) + + render + + expect(rendered).to have_css('li', class: 'js-sidebar-subscriptions-entry-point') + end + end + + context 'when mr merged and not logged in' do + it 'is not present' do + render + + expect(rendered).not_to have_css('li', class: 'js-sidebar-subscriptions-entry-point') + 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 d9c5d348e15..99d87ac449b 100644 --- a/spec/views/registrations/welcome/show.html.haml_spec.rb +++ b/spec/views/registrations/welcome/show.html.haml_spec.rb @@ -11,6 +11,7 @@ RSpec.describe 'registrations/welcome/show' do allow(view).to receive(:in_trial_flow?).and_return(false) allow(view).to receive(:user_has_memberships?).and_return(false) allow(view).to receive(:in_oauth_flow?).and_return(false) + allow(view).to receive(:glm_tracking_params).and_return({}) render end diff --git a/spec/views/search/_results.html.haml_spec.rb b/spec/views/search/_results.html.haml_spec.rb index 72e2d7131c0..2149c394320 100644 --- a/spec/views/search/_results.html.haml_spec.rb +++ b/spec/views/search/_results.html.haml_spec.rb @@ -12,6 +12,13 @@ RSpec.describe 'search/_results' do controller.params[:action] = 'show' controller.params[:search] = term + allow(self).to receive(:current_user).and_return(user) + allow(@search_results).to receive(:formatted_count).with(scope).and_return(10) + allow(self).to receive(:search_count_path).with(any_args).and_return("test count link") + allow(self).to receive(:search_path).with(any_args).and_return("link test") + + stub_feature_flags(search_page_vertical_nav: false) + create_list(:issue, 3) @search_objects = search_objects @@ -147,7 +154,7 @@ RSpec.describe 'search/_results' do it 'does not render the sidebar' do render - expect(rendered).not_to have_selector('#js-search-sidebar') + expect(rendered).not_to have_selector('form.search-sidebar') end end end diff --git a/spec/views/search/show.html.haml_spec.rb b/spec/views/search/show.html.haml_spec.rb index a336ec91ff2..565dadd64fe 100644 --- a/spec/views/search/show.html.haml_spec.rb +++ b/spec/views/search/show.html.haml_spec.rb @@ -4,93 +4,118 @@ require 'spec_helper' RSpec.describe 'search/show' do let(:search_term) { nil } + let(:user) { build(:user) } before do stub_template "search/_category.html.haml" => 'Category Partial' stub_template "search/_results.html.haml" => 'Results Partial' - - @search_term = search_term - - render end - context 'when the search page is opened' do - it 'displays the title' do - expect(rendered).to have_selector('h1.page-title', text: 'Search') - expect(rendered).not_to have_selector('h1.page-title code') + context 'feature flag enabled' do + before do + allow(self).to receive(:current_user).and_return(user) + @search_term = search_term + + render end - it 'does not render partials' do - expect(rendered).not_to render_template('search/_category') - expect(rendered).not_to render_template('search/_results') + context 'when search term is supplied' do + let(:search_term) { 'Search Foo' } + + it 'will not render category partial' do + expect(rendered).not_to render_template('search/_category') + expect(rendered).to render_template('search/_results') + end end end - context 'when search term is supplied' do - let(:search_term) { 'Search Foo' } + context 'feature flag disabled' do + before do + stub_feature_flags(search_page_vertical_nav: false) - it 'renders partials' do - expect(rendered).to render_template('search/_category') - expect(rendered).to render_template('search/_results') + @search_term = search_term + + render end - context 'unfurling support' do - let(:group) { build(:group) } - let(:search_results) do - instance_double(Gitlab::GroupSearchResults).tap do |double| - allow(double).to receive(:formatted_count).and_return(0) - end + context 'when the search page is opened' do + it 'displays the title' do + expect(rendered).to have_selector('h1.page-title', text: 'Search') + expect(rendered).not_to have_selector('h1.page-title code') end - before do - assign(:search_results, search_results) - assign(:scope, 'issues') - assign(:group, group) + it 'does not render partials' do + expect(rendered).not_to render_template('search/_category') + expect(rendered).not_to render_template('search/_results') end + end + + context 'when search term is supplied' do + let(:search_term) { 'Search Foo' } + + it 'renders partials' do + expect(rendered).to render_template('search/_category') + expect(rendered).to render_template('search/_results') + end + + context 'unfurling support' do + let(:group) { build(:group) } + let(:search_results) do + instance_double(Gitlab::GroupSearchResults).tap do |double| + allow(double).to receive(:formatted_count).and_return(0) + end + end - context 'search with full count' do before do - assign(:without_count, false) + assign(:search_results, search_results) + assign(:scope, 'issues') + assign(:group, group) end - it 'renders meta tags for a group' do - render + context 'search with full count' do + before do + assign(:without_count, false) + end - expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path) - end + it 'renders meta tags for a group' do + render - it 'renders meta tags for both group and project' do - project = build(:project, group: group) - assign(:project, project) + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path) + end - render + it 'renders meta tags for both group and project' do + project = build(:project, group: group) + assign(:project, project) - expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) - end - end + render - context 'search without full count' do - before do - assign(:without_count, true) + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) + end end - it 'renders meta tags for a group' do - render + context 'search without full count' do + before do + assign(:without_count, true) + end - expect(view.page_description).to match(/issues results for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path) - end + it 'renders meta tags for a group' do + render + + expect(view.page_description).to match(/issues results for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path) + end - it 'renders meta tags for both group and project' do - project = build(:project, group: group) - assign(:project, project) + it 'renders meta tags for both group and project' do + project = build(:project, group: group) + assign(:project, project) - render + render - expect(view.page_description).to match(/issues results for term '#{search_term}'/) - expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) + expect(view.page_description).to match(/issues results for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) + end end end end diff --git a/spec/views/shared/projects/_project.html.haml_spec.rb b/spec/views/shared/projects/_project.html.haml_spec.rb index 62f23338c48..7575c3b8b92 100644 --- a/spec/views/shared/projects/_project.html.haml_spec.rb +++ b/spec/views/shared/projects/_project.html.haml_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'shared/projects/_project.html.haml' do it 'renders creator avatar if project has a creator' do render 'shared/projects/project', use_creator_avatar: true, project: project - expect(rendered).to have_selector('img.avatar') + expect(rendered).to have_selector('img.gl-avatar') end it 'renders a generic avatar if project does not have a creator' do @@ -21,6 +21,6 @@ RSpec.describe 'shared/projects/_project.html.haml' do render 'shared/projects/project', use_creator_avatar: true, project: project - expect(rendered).to have_selector('.project-avatar') + expect(rendered).to have_selector('.gl-avatar-identicon') end end |