diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 12:09:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 12:09:39 +0300 |
commit | ada214dc52b53bd9eb3a79c279506f91c547f721 (patch) | |
tree | f4266ef83f9be3a62a0f8942911058758655929a /spec | |
parent | 27b43bd4d613cc7b8773ca0863b8d8f9b90f6d87 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/help_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/controllers/projects/environments_controller_spec.rb | 36 | ||||
-rw-r--r-- | spec/features/dashboard/help_spec.rb | 21 | ||||
-rw-r--r-- | spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js | 13 | ||||
-rw-r--r-- | spec/frontend/vue_shared/components/markdown/field_spec.js | 32 | ||||
-rw-r--r-- | spec/helpers/boards_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/jira_import/labels_importer_spec.rb | 22 | ||||
-rw-r--r-- | spec/policies/project_policy_spec.rb | 187 | ||||
-rw-r--r-- | spec/views/help/index.html.haml_spec.rb | 12 | ||||
-rw-r--r-- | spec/views/help/show.html.haml_spec.rb | 18 |
10 files changed, 297 insertions, 55 deletions
diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index f03fee8d3ae..fafbe6bffe1 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -99,6 +99,7 @@ describe HelpController do context 'for Markdown formats' do context 'when requested file exists' do before do + expect(File).to receive(:read).and_return(fixture_file('blockquote_fence_after.md')) get :show, params: { path: 'ssh/README' }, format: :md end @@ -108,7 +109,7 @@ describe HelpController do it 'renders HTML' do expect(response).to render_template('show.html.haml') - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end end @@ -129,7 +130,7 @@ describe HelpController do }, format: :png expect(response).to be_successful - expect(response.content_type).to eq 'image/png' + expect(response.media_type).to eq 'image/png' expect(response.headers['Content-Disposition']).to match(/^inline;/) end end @@ -168,6 +169,6 @@ describe HelpController do end def stub_readme(content) - allow(File).to receive(:read).and_return(content) + expect(File).to receive(:read).and_return(content) end end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 3b035eea7d5..56fff2771ec 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -410,6 +410,18 @@ describe Projects::EnvironmentsController do expect(json_response['last_update']).to eq(42) end end + + context 'permissions' do + before do + allow(controller).to receive(:can?).and_return true + end + + it 'checks :metrics_dashboard ability' do + expect(controller).to receive(:can?).with(anything, :metrics_dashboard, anything) + + get :metrics, params: environment_params + end + end end describe 'GET #additional_metrics' do @@ -473,6 +485,18 @@ describe Projects::EnvironmentsController do .to raise_error(ActionController::ParameterMissing) end end + + context 'permissions' do + before do + allow(controller).to receive(:can?).and_return true + end + + it 'checks :metrics_dashboard ability' do + expect(controller).to receive(:can?).with(anything, :metrics_dashboard, anything) + + get :metrics, params: environment_params + end + end end describe 'GET #metrics_dashboard' do @@ -648,6 +672,18 @@ describe Projects::EnvironmentsController do it_behaves_like 'the default dashboard' it_behaves_like 'dashboard can be specified' it_behaves_like 'dashboard can be embedded' + + context 'permissions' do + before do + allow(controller).to receive(:can?).and_return true + end + + it 'checks :metrics_dashboard ability' do + expect(controller).to receive(:can?).with(anything, :metrics_dashboard, anything) + + get :metrics, params: environment_params + end + end end describe 'GET #search' do diff --git a/spec/features/dashboard/help_spec.rb b/spec/features/dashboard/help_spec.rb deleted file mode 100644 index 73377453ba3..00000000000 --- a/spec/features/dashboard/help_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Dashboard Help' do - before do - sign_in(create(:user)) - end - - context 'documentation' do - it 'renders correctly markdown' do - visit help_page_path("administration/raketasks/maintenance") - - expect(page).to have_content('Gather GitLab and system information') - - node = find('.documentation h2 a#user-content-check-gitlab-configuration') - expect(node[:href]).to eq '#check-gitlab-configuration' - expect(find(:xpath, "#{node.path}/..").text).to eq 'Check GitLab configuration' - end - end -end diff --git a/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js b/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js index 9c292fa0f2b..369b1a93957 100644 --- a/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js +++ b/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js @@ -489,15 +489,22 @@ describe('Settings Panel', () => { .find('[name="project[project_feature_attributes][metrics_dashboard_access_level]"]') .setValue(visibilityOptions.PUBLIC); - expect(wrapper.vm.metricsAccessLevel).toBe(visibilityOptions.PUBLIC); + expect(wrapper.vm.metricsDashboardAccessLevel).toBe(visibilityOptions.PUBLIC); }); it('should contain help text', () => { - wrapper = overrideCurrentSettings({ visibilityLevel: visibilityOptions.PRIVATE }); - expect(wrapper.find({ ref: 'metrics-visibility-settings' }).props().helpText).toEqual( 'With Metrics Dashboard you can visualize this project performance metrics', ); }); + + it('should disable the metrics visibility dropdown when the project visibility level changes to private', () => { + wrapper = overrideCurrentSettings({ visibilityLevel: visibilityOptions.PRIVATE }); + + const metricsSettingsRow = wrapper.find({ ref: 'metrics-visibility-settings' }); + + expect(wrapper.vm.metricsOptionsDropdownEnabled).toBe(true); + expect(metricsSettingsRow.find('select').attributes('disabled')).toEqual('disabled'); + }); }); }); diff --git a/spec/frontend/vue_shared/components/markdown/field_spec.js b/spec/frontend/vue_shared/components/markdown/field_spec.js index 46e269e5071..4ef82b2dd4e 100644 --- a/spec/frontend/vue_shared/components/markdown/field_spec.js +++ b/spec/frontend/vue_shared/components/markdown/field_spec.js @@ -9,9 +9,9 @@ const markdownPreviewPath = `${TEST_HOST}/preview`; const markdownDocsPath = `${TEST_HOST}/docs`; function assertMarkdownTabs(isWrite, writeLink, previewLink, wrapper) { - expect(writeLink.element.parentNode.classList.contains('active')).toEqual(isWrite); - expect(previewLink.element.parentNode.classList.contains('active')).toEqual(!isWrite); - expect(wrapper.find('.md-preview-holder').element.style.display).toEqual(isWrite ? 'none' : ''); + expect(writeLink.element.parentNode.classList.contains('active')).toBe(isWrite); + expect(previewLink.element.parentNode.classList.contains('active')).toBe(!isWrite); + expect(wrapper.find('.md-preview-holder').element.style.display).toBe(isWrite ? 'none' : ''); } function createComponent() { @@ -67,6 +67,10 @@ describe('Markdown field component', () => { let previewLink; let writeLink; + afterEach(() => { + wrapper.destroy(); + }); + it('renders textarea inside backdrop', () => { wrapper = createComponent(); expect(wrapper.find('.zen-backdrop textarea').element).not.toBeNull(); @@ -92,32 +96,24 @@ describe('Markdown field component', () => { previewLink = getPreviewLink(wrapper); previewLink.trigger('click'); - wrapper.vm.$nextTick(() => { + return wrapper.vm.$nextTick(() => { expect(wrapper.find('.md-preview-holder').element.textContent.trim()).toContain( 'Loading…', ); }); }); - it('renders markdown preview', () => { + it('renders markdown preview and GFM', () => { wrapper = createComponent(); - previewLink = getPreviewLink(wrapper); - previewLink.trigger('click'); + const renderGFMSpy = jest.spyOn($.fn, 'renderGFM'); - setTimeout(() => { - expect(wrapper.find('.md-preview-holder').element.innerHTML).toContain(previewHTML); - }); - }); - - it('renders GFM with jQuery', () => { - wrapper = createComponent(); previewLink = getPreviewLink(wrapper); - jest.spyOn($.fn, 'renderGFM'); previewLink.trigger('click'); return axios.waitFor(markdownPreviewPath).then(() => { expect(wrapper.find('.md-preview-holder').element.innerHTML).toContain(previewHTML); + expect(renderGFMSpy).toHaveBeenCalled(); }); }); @@ -176,7 +172,7 @@ describe('Markdown field component', () => { const markdownButton = getMarkdownButton(wrapper); markdownButton.trigger('click'); - wrapper.vm.$nextTick(() => { + return wrapper.vm.$nextTick(() => { expect(textarea.value).toContain('**testing**'); }); }); @@ -188,7 +184,7 @@ describe('Markdown field component', () => { const markdownButton = getAllMarkdownButtons(wrapper).wrappers[5]; markdownButton.trigger('click'); - wrapper.vm.$nextTick(() => { + return wrapper.vm.$nextTick(() => { expect(textarea.value).toContain('* testing'); }); }); @@ -200,7 +196,7 @@ describe('Markdown field component', () => { const markdownButton = getAllMarkdownButtons(wrapper).wrappers[5]; markdownButton.trigger('click'); - wrapper.vm.$nextTick(() => { + return wrapper.vm.$nextTick(() => { expect(textarea.value).toContain('* testing\n* 123'); }); }); diff --git a/spec/helpers/boards_helper_spec.rb b/spec/helpers/boards_helper_spec.rb index f5e5285554c..cb9be9d5fb4 100644 --- a/spec/helpers/boards_helper_spec.rb +++ b/spec/helpers/boards_helper_spec.rb @@ -48,6 +48,10 @@ describe BoardsHelper do it 'returns a board_lists_path as lists_endpoint' do expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board)) end + + it 'returns board type as parent' do + expect(helper.board_data[:parent]).to eq('project') + end end describe '#current_board_json' do diff --git a/spec/lib/gitlab/jira_import/labels_importer_spec.rb b/spec/lib/gitlab/jira_import/labels_importer_spec.rb index 4d33ede136e..67eb541d376 100644 --- a/spec/lib/gitlab/jira_import/labels_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/labels_importer_spec.rb @@ -10,7 +10,9 @@ describe Gitlab::JiraImport::LabelsImporter do let_it_be(:project) { create(:project, group: group) } let_it_be(:jira_service) { create(:jira_service, project: project) } - subject { described_class.new(project).execute } + let(:importer) { described_class.new(project) } + + subject { importer.execute } before do stub_feature_flags(jira_issue_import: true) @@ -38,14 +40,13 @@ describe Gitlab::JiraImport::LabelsImporter do let(:jira_labels_1) { { "maxResults" => 2, "startAt" => 0, "total" => 3, "isLast" => false, "values" => %w(backend bug) } } let(:jira_labels_2) { { "maxResults" => 2, "startAt" => 2, "total" => 3, "isLast" => true, "values" => %w(feature) } } - before do - WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=0') - .to_return(body: jira_labels_1.to_json ) - WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=2') - .to_return(body: jira_labels_2.to_json ) - end - context 'when labels are returned from jira' do + before do + client = double + expect(importer).to receive(:client).twice.and_return(client) + allow(client).to receive(:get).twice.and_return(jira_labels_1, jira_labels_2) + end + it 'caches import label' do expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.import_label_cache_key(project.id))).to be nil @@ -74,8 +75,9 @@ describe Gitlab::JiraImport::LabelsImporter do let(:jira_labels) { { "maxResults" => 2, "startAt" => 0, "total" => 3, "values" => [] } } before do - WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=0') - .to_return(body: jira_labels.to_json ) + client = double + expect(importer).to receive(:client).and_return(client) + allow(client).to receive(:get).and_return(jira_labels) end context 'when the labels field is empty' do diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index db643e3a31f..f214b1ccf17 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -29,6 +29,7 @@ describe ProjectPolicy do admin_issue admin_label admin_list read_commit_status read_build read_container_image read_pipeline read_environment read_deployment read_merge_request download_wiki_code read_sentry_issue read_metrics_dashboard_annotation + metrics_dashboard ] end @@ -485,4 +486,190 @@ describe ProjectPolicy do it { is_expected.to be_disallowed(:read_prometheus_alerts) } end end + + describe 'metrics_dashboard feature' do + subject { described_class.new(current_user, project) } + + context 'public project' do + let(:project) { create(:project, :public) } + + context 'feature private' do + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + end + + context 'feature enabled' do + before do + project.project_feature.update(metrics_dashboard_access_level: ProjectFeature::ENABLED) + end + + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + end + end + + context 'internal project' do + let(:project) { create(:project, :internal) } + + context 'feature private' do + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard)} + end + end + + context 'feature enabled' do + before do + project.project_feature.update(metrics_dashboard_access_level: ProjectFeature::ENABLED) + end + + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + end + end + + context 'private project' do + let(:project) { create(:project, :private) } + + context 'feature private' do + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + end + + context 'feature enabled' do + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_allowed(:metrics_dashboard) } + it { is_expected.to be_allowed(:read_prometheus) } + it { is_expected.to be_allowed(:read_deployment) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + end + end + + context 'feature disabled' do + before do + project.project_feature.update(metrics_dashboard_access_level: ProjectFeature::DISABLED) + end + + context 'with reporter' do + let(:current_user) { reporter } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with guest' do + let(:current_user) { guest } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + + context 'with anonymous' do + let(:current_user) { nil } + + it { is_expected.to be_disallowed(:metrics_dashboard) } + end + end + end end diff --git a/spec/views/help/index.html.haml_spec.rb b/spec/views/help/index.html.haml_spec.rb index 98040da9d2c..3831ddacb72 100644 --- a/spec/views/help/index.html.haml_spec.rb +++ b/spec/views/help/index.html.haml_spec.rb @@ -53,6 +53,18 @@ describe 'help/index' do end end + describe 'Markdown rendering' do + before do + assign(:help_index, 'Welcome to [GitLab](https://about.gitlab.com/) Documentation.') + end + + it 'renders Markdown' do + render + + expect(rendered).to have_link('GitLab', href: 'https://about.gitlab.com/') + end + end + def stub_user(user = double) allow(view).to receive(:user_signed_in?).and_return(user) end diff --git a/spec/views/help/show.html.haml_spec.rb b/spec/views/help/show.html.haml_spec.rb new file mode 100644 index 00000000000..539c647c1d3 --- /dev/null +++ b/spec/views/help/show.html.haml_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'help/show' do + describe 'Markdown rendering' do + before do + assign(:path, 'ssh/README') + assign(:markdown, 'Welcome to [GitLab](https://about.gitlab.com/) Documentation.') + end + + it 'renders Markdown' do + render + + expect(rendered).to have_link('GitLab', href: 'https://about.gitlab.com/') + end + end +end |