diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-10 21:09:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-10 21:09:54 +0300 |
commit | 350fd8b878fe930b83c52ccae82f861cc499776a (patch) | |
tree | aa01a35b06921103ba9967920165419accb9f72d /spec | |
parent | 70732753863e569f95ed954ca3c41421292f912b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
29 files changed, 284 insertions, 46 deletions
diff --git a/spec/controllers/concerns/send_file_upload_spec.rb b/spec/controllers/concerns/send_file_upload_spec.rb index 7cfaf1b248f..e24e4cbf5e7 100644 --- a/spec/controllers/concerns/send_file_upload_spec.rb +++ b/spec/controllers/concerns/send_file_upload_spec.rb @@ -21,6 +21,12 @@ RSpec.describe SendFileUpload do let(:controller_class) do Class.new do include SendFileUpload + + def params + {} + end + + def current_user; end end end @@ -42,6 +48,89 @@ RSpec.describe SendFileUpload do FileUtils.rm_f(temp_file) end + shared_examples 'handles image resize requests' do + let(:headers) { double } + + before do + allow(uploader).to receive(:image?).and_return(true) + allow(uploader).to receive(:mounted_as).and_return(:avatar) + + allow(controller).to receive(:headers).and_return(headers) + # both of these are valid cases, depending on whether we are dealing with + # local or remote files + allow(controller).to receive(:send_file) + allow(controller).to receive(:redirect_to) + end + + context 'when feature is enabled for current user' do + let(:user) { build(:user) } + + before do + stub_feature_flags(dynamic_image_resizing: user) + allow(controller).to receive(:current_user).and_return(user) + end + + context 'with valid width parameter' do + it 'renders OK with workhorse command header' do + expect(controller).not_to receive(:send_file) + expect(controller).to receive(:params).at_least(:once).and_return(width: '64') + expect(controller).to receive(:head).with(:ok) + expect(headers).to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + + context 'with missing width parameter' do + it 'does not write workhorse command header' do + expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + + context 'with invalid width parameter' do + it 'does not write workhorse command header' do + expect(controller).to receive(:params).at_least(:once).and_return(width: 'not a number') + expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + + context 'with width that is not allowed' do + it 'does not write workhorse command header' do + expect(controller).to receive(:params).at_least(:once).and_return(width: '63') + expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + + context 'when image file is not an avatar' do + it 'does not write workhorse command header' do + expect(uploader).to receive(:mounted_as).and_return(nil) # FileUploader is not mounted + expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + end + + context 'when feature is disabled' do + before do + stub_feature_flags(dynamic_image_resizing: false) + end + + it 'does not write workhorse command header' do + expect(controller).to receive(:params).at_least(:once).and_return(width: '64') + expect(headers).not_to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-scaled-img:/) + + subject + end + end + end + context 'when local file is used' do before do uploader.store!(temp_file) @@ -52,6 +141,8 @@ RSpec.describe SendFileUpload do subject end + + it_behaves_like 'handles image resize requests' end context 'with inline image' do @@ -155,6 +246,8 @@ RSpec.describe SendFileUpload do it_behaves_like 'proxied file' end end + + it_behaves_like 'handles image resize requests' end end end diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index 60c37d1e125..e66a40720da 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -112,7 +112,7 @@ RSpec.describe 'Commits' do describe 'Cancel build' do it 'cancels build', :js, :sidekiq_might_not_need_inline do visit pipeline_path(pipeline) - find('.js-btn-cancel-pipeline').click + find('[data-testid="cancelPipeline"]').click expect(page).to have_content 'canceled' end end diff --git a/spec/features/invites_spec.rb b/spec/features/invites_spec.rb index c0f453206a8..e7bcd7876ea 100644 --- a/spec/features/invites_spec.rb +++ b/spec/features/invites_spec.rb @@ -48,6 +48,14 @@ RSpec.describe 'Invites', :aggregate_failures do expect(page).to have_content('To accept this invitation, sign in') end + it 'pre-fills the "Username or email" field on the sign in box with the invite_email from the invite' do + expect(find_field('Username or email').value).to eq(group_invite.invite_email) + end + + it 'pre-fills the Email field on the sign up box with the invite_email from the invite' do + expect(find_field('Email').value).to eq(group_invite.invite_email) + end + it 'sign in, grants access and redirects to group page' do fill_in_sign_in_form(user) diff --git a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb index d5ff31de073..e61ae4ea795 100644 --- a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb +++ b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb @@ -154,7 +154,7 @@ RSpec.describe 'Merge request > User merges when pipeline succeeds', :js do context 'view merge request with MWPS enabled but automatically merge fails' do before do - merge_request.update( + merge_request.update!( merge_user: merge_request.author, merge_error: 'Something went wrong.' ) @@ -173,7 +173,7 @@ RSpec.describe 'Merge request > User merges when pipeline succeeds', :js do context 'view merge request with MWPS enabled but automatically merge fails' do before do - merge_request.update( + merge_request.update!( merge_user: merge_request.author, merge_error: 'Something went wrong.' ) diff --git a/spec/features/merge_request/user_posts_diff_notes_spec.rb b/spec/features/merge_request/user_posts_diff_notes_spec.rb index 6ecffb05009..9556142ecb8 100644 --- a/spec/features/merge_request/user_posts_diff_notes_spec.rb +++ b/spec/features/merge_request/user_posts_diff_notes_spec.rb @@ -193,7 +193,7 @@ RSpec.describe 'Merge request > User posts diff notes', :js do context 'when the MR only supports legacy diff notes' do before do - merge_request.merge_request_diff.update(start_commit_sha: nil) + merge_request.merge_request_diff.update!(start_commit_sha: nil) visit diffs_project_merge_request_path(project, merge_request, view: 'inline') end diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb index aa3840b4376..f2adfd21e49 100644 --- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb +++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'Merge request > User resolves diff notes and threads', :js do before do project.add_maintainer(user) sign_in(user) - note.destroy + note.destroy! visit_merge_request end diff --git a/spec/features/merge_request/user_sees_cherry_pick_modal_spec.rb b/spec/features/merge_request/user_sees_cherry_pick_modal_spec.rb index ec2fb856be5..7f4249336fe 100644 --- a/spec/features/merge_request/user_sees_cherry_pick_modal_spec.rb +++ b/spec/features/merge_request/user_sees_cherry_pick_modal_spec.rb @@ -26,7 +26,7 @@ RSpec.describe 'Merge request > User cherry-picks', :js do context 'without a merge commit' do before do merge_request.merge_commit_sha = nil - merge_request.save + merge_request.save! end it 'does not show a Cherry-pick button' do diff --git a/spec/features/merge_request/user_sees_discussions_spec.rb b/spec/features/merge_request/user_sees_discussions_spec.rb index ca8c4f84677..74d1b8b628c 100644 --- a/spec/features/merge_request/user_sees_discussions_spec.rb +++ b/spec/features/merge_request/user_sees_discussions_spec.rb @@ -13,8 +13,8 @@ RSpec.describe 'Merge request > User sees threads', :js do end describe "Diff discussions" do - let!(:old_merge_request_diff) { merge_request.merge_request_diffs.create(diff_refs: outdated_diff_refs) } - let!(:new_merge_request_diff) { merge_request.merge_request_diffs.create } + let!(:old_merge_request_diff) { merge_request.merge_request_diffs.create!(diff_refs: outdated_diff_refs) } + let!(:new_merge_request_diff) { merge_request.merge_request_diffs.create! } let!(:outdated_discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: outdated_position).to_discussion } let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } let(:outdated_position) do diff --git a/spec/features/merge_request/user_sees_merge_widget_spec.rb b/spec/features/merge_request/user_sees_merge_widget_spec.rb index ce49e9f4141..c7d26dfc814 100644 --- a/spec/features/merge_request/user_sees_merge_widget_spec.rb +++ b/spec/features/merge_request/user_sees_merge_widget_spec.rb @@ -302,7 +302,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do context 'view merge request with MWPS enabled but automatically merge fails' do before do - merge_request.update( + merge_request.update!( auto_merge_enabled: true, auto_merge_strategy: AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS, merge_user: merge_request.author, @@ -324,7 +324,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do context 'view merge request with MWPS enabled but automatically merge fails' do before do - merge_request.update( + merge_request.update!( merge_when_pipeline_succeeds: true, merge_user: merge_request.author, merge_error: 'Something went wrong' @@ -345,9 +345,9 @@ RSpec.describe 'Merge request > User sees merge widget', :js do context 'view merge request where fast-forward merge is not possible' do before do - project.update(merge_requests_ff_only_enabled: true) + project.update!(merge_requests_ff_only_enabled: true) - merge_request.update( + merge_request.update!( merge_user: merge_request.author, merge_status: :cannot_be_merged ) @@ -380,19 +380,19 @@ RSpec.describe 'Merge request > User sees merge widget', :js do end end - context 'user can merge into source project but cannot push to fork', :js do - let(:fork_project) { create(:project, :public, :repository) } + context 'user can merge into target project but cannot push to fork', :js do + let(:forked_project) { fork_project(project, nil, repository: true) } let(:user2) { create(:user) } before do project.add_maintainer(user2) sign_out(:user) sign_in(user2) - merge_request.update(target_project: fork_project) + merge_request.update!(source_project: forked_project) visit project_merge_request_path(project, merge_request) end - it 'user can merge into the source project' do + it 'user can merge into the target project', :sidekiq_inline do expect(page).to have_button('Merge', disabled: false) end @@ -409,7 +409,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do project.add_developer(user2) sign_out(:user) sign_in(user2) - merge_request.update( + merge_request.update!( source_project: forked_project, target_project: project, merge_params: { 'force_remove_source_branch' => '1' } @@ -879,7 +879,7 @@ RSpec.describe 'Merge request > User sees merge widget', :js do let!(:pipeline) { create(:ci_pipeline, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) } before do - project.update( + project.update!( visibility_level: Gitlab::VisibilityLevel::PUBLIC, public_builds: false ) diff --git a/spec/features/merge_request/user_sees_versions_spec.rb b/spec/features/merge_request/user_sees_versions_spec.rb index 75319c8a22d..a89ae5c7464 100644 --- a/spec/features/merge_request/user_sees_versions_spec.rb +++ b/spec/features/merge_request/user_sees_versions_spec.rb @@ -5,14 +5,14 @@ require 'spec_helper' RSpec.describe 'Merge request > User sees versions', :js do let(:merge_request) do create(:merge_request).tap do |mr| - mr.merge_request_diff.destroy + mr.merge_request_diff.destroy! end end let(:project) { merge_request.source_project } let(:user) { project.creator } - let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } - let!(:merge_request_diff2) { merge_request.merge_request_diffs.create(head_commit_sha: nil) } - let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + let!(:merge_request_diff1) { merge_request.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + let!(:merge_request_diff2) { merge_request.merge_request_diffs.create!(head_commit_sha: nil) } + let!(:merge_request_diff3) { merge_request.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } let!(:params) { {} } before do diff --git a/spec/features/merge_requests/user_mass_updates_spec.rb b/spec/features/merge_requests/user_mass_updates_spec.rb index 589825f12af..179bf84a729 100644 --- a/spec/features/merge_requests/user_mass_updates_spec.rb +++ b/spec/features/merge_requests/user_mass_updates_spec.rb @@ -95,7 +95,7 @@ RSpec.describe 'Merge requests > User mass updates', :js do describe 'unset milestone' do before do merge_request.milestone = milestone - merge_request.save + merge_request.save! visit project_merge_requests_path(project) end diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index b3f671d57a9..a05910cd892 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -37,7 +37,7 @@ RSpec.describe 'Environments page', :js do expect(page).to have_css('.environments-container') expect(page.all('.environment-name').length).to eq(1) - expect(page.all('.ic-stop').length).to eq(1) + expect(page.all('[data-testid="stop-icon"]').length).to eq(1) end end diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index f0b4d2e88b2..70cc64e9308 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -399,7 +399,7 @@ RSpec.describe 'Pipeline', :js do context 'when retrying' do before do - find('.js-retry-button').click + find('[data-testid="retryButton"]').click end it 'does not show a "Retry" button', :sidekiq_might_not_need_inline do @@ -901,7 +901,7 @@ RSpec.describe 'Pipeline', :js do context 'when retrying' do before do - find('.js-retry-button').click + find('[data-testid="retryButton"]').click end it 'does not show a "Retry" button', :sidekiq_might_not_need_inline do diff --git a/spec/frontend/batch_comments/components/drafts_count_spec.js b/spec/frontend/batch_comments/components/drafts_count_spec.js index 9d9fffce7e7..41583a94fcf 100644 --- a/spec/frontend/batch_comments/components/drafts_count_spec.js +++ b/spec/frontend/batch_comments/components/drafts_count_spec.js @@ -24,7 +24,7 @@ describe('Batch comments drafts count component', () => { }); it('renders count', () => { - expect(vm.$el.querySelector('.drafts-count-number').textContent).toBe('1'); + expect(vm.$el.textContent).toContain('1'); }); it('renders screen reader text', done => { diff --git a/spec/frontend/environments/environment_external_url_spec.js b/spec/frontend/environments/environment_external_url_spec.js index 9997ea94941..4c133665979 100644 --- a/spec/frontend/environments/environment_external_url_spec.js +++ b/spec/frontend/environments/environment_external_url_spec.js @@ -1,4 +1,4 @@ -import { shallowMount } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; import ExternalUrlComp from '~/environments/components/environment_external_url.vue'; describe('External URL Component', () => { @@ -6,7 +6,7 @@ describe('External URL Component', () => { const externalUrl = 'https://gitlab.com'; beforeEach(() => { - wrapper = shallowMount(ExternalUrlComp, { propsData: { externalUrl } }); + wrapper = mount(ExternalUrlComp, { propsData: { externalUrl } }); }); it('should link to the provided externalUrl prop', () => { diff --git a/spec/frontend/environments/environment_stop_spec.js b/spec/frontend/environments/environment_stop_spec.js index f971cf56b65..37d65c9da5a 100644 --- a/spec/frontend/environments/environment_stop_spec.js +++ b/spec/frontend/environments/environment_stop_spec.js @@ -1,7 +1,7 @@ import $ from 'jquery'; import { shallowMount } from '@vue/test-utils'; import StopComponent from '~/environments/components/environment_stop.vue'; -import LoadingButton from '~/vue_shared/components/loading_button.vue'; +import { GlButton } from '@gitlab/ui'; import eventHub from '~/environments/event_hub'; $.fn.tooltip = () => {}; @@ -17,7 +17,7 @@ describe('Stop Component', () => { }); }; - const findButton = () => wrapper.find(LoadingButton); + const findButton = () => wrapper.find(GlButton); beforeEach(() => { jest.spyOn(window, 'confirm'); diff --git a/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js b/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js index c0851096d8e..158f70f7d47 100644 --- a/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js +++ b/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js @@ -57,7 +57,11 @@ describe('Recent Searches Dropdown Content', () => { beforeEach(() => { createComponent({ - items: ['foo', 'author:@root label:~foo bar'], + items: [ + 'foo', + 'author:@root label:~foo bar', + [{ type: 'author_username', value: { data: 'toby', operator: '=' } }], + ], isLocalStorageAvailable: true, }); }); @@ -76,7 +80,7 @@ describe('Recent Searches Dropdown Content', () => { }); it('renders a correct amount of dropdown items', () => { - expect(findDropdownItems()).toHaveLength(2); + expect(findDropdownItems()).toHaveLength(2); // Ignore non-string recent item }); it('expect second dropdown to have 2 tokens', () => { diff --git a/spec/frontend/maintenance_mode_settings/components/app_spec.js b/spec/frontend/maintenance_mode_settings/components/app_spec.js index 0453354b008..a67bc63cfe1 100644 --- a/spec/frontend/maintenance_mode_settings/components/app_spec.js +++ b/spec/frontend/maintenance_mode_settings/components/app_spec.js @@ -1,6 +1,6 @@ import { shallowMount } from '@vue/test-utils'; import MaintenanceModeSettingsApp from '~/maintenance_mode_settings/components/app.vue'; -import { GlToggle, GlFormTextarea, GlDeprecatedButton } from '@gitlab/ui'; +import { GlToggle, GlFormTextarea, GlButton } from '@gitlab/ui'; describe('MaintenanceModeSettingsApp', () => { let wrapper; @@ -16,7 +16,7 @@ describe('MaintenanceModeSettingsApp', () => { const findMaintenanceModeSettingsContainer = () => wrapper.find('article'); const findGlToggle = () => wrapper.find(GlToggle); const findGlFormTextarea = () => wrapper.find(GlFormTextarea); - const findGlButton = () => wrapper.find(GlDeprecatedButton); + const findGlButton = () => wrapper.find(GlButton); describe('template', () => { beforeEach(() => { @@ -35,7 +35,7 @@ describe('MaintenanceModeSettingsApp', () => { expect(findGlFormTextarea().exists()).toBe(true); }); - it('renders the GlDeprecatedButton', () => { + it('renders the GlButton', () => { expect(findGlButton().exists()).toBe(true); }); }); diff --git a/spec/frontend/pipelines/header_component_spec.js b/spec/frontend/pipelines/header_component_spec.js index 1c3a6c545a0..7f7b1f00dab 100644 --- a/spec/frontend/pipelines/header_component_spec.js +++ b/spec/frontend/pipelines/header_component_spec.js @@ -85,13 +85,13 @@ describe('Pipeline details header', () => { }); it('should call postAction when retry button action is clicked', () => { - wrapper.find('.js-retry-button').vm.$emit('click'); + wrapper.find('[data-testid="retryButton"]').vm.$emit('click'); expect(eventHub.$emit).toHaveBeenCalledWith('headerPostAction', 'retry'); }); it('should call postAction when cancel button action is clicked', () => { - wrapper.find('.js-btn-cancel-pipeline').vm.$emit('click'); + wrapper.find('[data-testid="cancelPipeline"]').vm.$emit('click'); expect(eventHub.$emit).toHaveBeenCalledWith('headerPostAction', 'cancel'); }); diff --git a/spec/frontend/releases/util_spec.js b/spec/frontend/releases/util_spec.js index 921da34d62a..90aa9c4c7d8 100644 --- a/spec/frontend/releases/util_spec.js +++ b/spec/frontend/releases/util_spec.js @@ -41,6 +41,24 @@ describe('releases/util.js', () => { }); }); + describe('release.name', () => { + it.each` + input | output + ${null} | ${null} + ${''} | ${null} + ${' \t\n\r\n'} | ${null} + ${' Release name '} | ${'Release name'} + `('converts a name like `$input` to `$output`', ({ input, output }) => { + const release = { name: input }; + + const expectedJson = { + name: output, + }; + + expect(releaseToApiJson(release)).toMatchObject(expectedJson); + }); + }); + describe('when release.milestones is falsy', () => { it('includes a "milestone" property in the returned result as an empty array', () => { const release = {}; diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js index 2e4fb987306..5f474193495 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_bar_root_spec.js @@ -20,7 +20,7 @@ const createComponent = ({ namespace = 'gitlab-org/gitlab-test', recentSearchesStorageKey = 'requirements', tokens = mockAvailableTokens, - sortOptions = mockSortOptions, + sortOptions, searchInputPlaceholder = 'Filter requirements', } = {}) => { const mountMethod = shallow ? shallowMount : mount; @@ -40,7 +40,7 @@ describe('FilteredSearchBarRoot', () => { let wrapper; beforeEach(() => { - wrapper = createComponent(); + wrapper = createComponent({ sortOptions: mockSortOptions }); }); afterEach(() => { @@ -48,10 +48,25 @@ describe('FilteredSearchBarRoot', () => { }); describe('data', () => { - it('initializes `filterValue`, `selectedSortOption` and `selectedSortDirection` data props', () => { + it('initializes `filterValue`, `selectedSortOption` and `selectedSortDirection` data props and displays the sort dropdown', () => { expect(wrapper.vm.filterValue).toEqual([]); expect(wrapper.vm.selectedSortOption).toBe(mockSortOptions[0].sortDirection.descending); expect(wrapper.vm.selectedSortDirection).toBe(SortDirection.descending); + expect(wrapper.contains(GlButtonGroup)).toBe(true); + expect(wrapper.contains(GlButton)).toBe(true); + expect(wrapper.contains(GlDropdown)).toBe(true); + expect(wrapper.contains(GlDropdownItem)).toBe(true); + }); + + it('does not initialize `selectedSortOption` and `selectedSortDirection` when `sortOptions` is not applied and hides the sort dropdown', () => { + const wrapperNoSort = createComponent(); + + expect(wrapperNoSort.vm.filterValue).toEqual([]); + expect(wrapperNoSort.vm.selectedSortOption).toBe(undefined); + expect(wrapperNoSort.contains(GlButtonGroup)).toBe(false); + expect(wrapperNoSort.contains(GlButton)).toBe(false); + expect(wrapperNoSort.contains(GlDropdown)).toBe(false); + expect(wrapperNoSort.contains(GlDropdownItem)).toBe(false); }); }); @@ -103,6 +118,19 @@ describe('FilteredSearchBarRoot', () => { expect(wrapper.vm.sortDirectionTooltip).toBe('Sort direction: Descending'); }); }); + + describe('filteredRecentSearches', () => { + it('returns array of recent searches filtering out any string type (unsupported) items', async () => { + wrapper.setData({ + recentSearches: [{ foo: 'bar' }, 'foo'], + }); + + await wrapper.vm.$nextTick(); + + expect(wrapper.vm.filteredRecentSearches).toHaveLength(1); + expect(wrapper.vm.filteredRecentSearches[0]).toEqual({ foo: 'bar' }); + }); + }); }); describe('watchers', () => { @@ -273,7 +301,7 @@ describe('FilteredSearchBarRoot', () => { }); it('renders search history items dropdown with formatting done using token symbols', async () => { - const wrapperFullMount = createComponent({ shallow: false }); + const wrapperFullMount = createComponent({ sortOptions: mockSortOptions, shallow: false }); wrapperFullMount.vm.recentSearchesStore.addRecentSearch(mockHistoryItems[0]); await wrapperFullMount.vm.$nextTick(); diff --git a/spec/frontend/vue_shared/components/header_ci_component_spec.js b/spec/frontend/vue_shared/components/header_ci_component_spec.js index 216563165d6..5233a64ce5e 100644 --- a/spec/frontend/vue_shared/components/header_ci_component_spec.js +++ b/spec/frontend/vue_shared/components/header_ci_component_spec.js @@ -35,7 +35,7 @@ describe('Header CI Component', () => { vm.$destroy(); }); - const findActionButtons = () => vm.$el.querySelector('.header-action-buttons'); + const findActionButtons = () => vm.$el.querySelector('[data-testid="headerButtons"]'); describe('render', () => { beforeEach(() => { diff --git a/spec/graphql/resolvers/group_milestone_resolver_spec.rb b/spec/graphql/resolvers/group_milestones_resolver_spec.rb index 7504324f8bc..05d0ec38192 100644 --- a/spec/graphql/resolvers/group_milestone_resolver_spec.rb +++ b/spec/graphql/resolvers/group_milestones_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Resolvers::GroupMilestoneResolver do +RSpec.describe Resolvers::GroupMilestonesResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/project_milestone_resolver_spec.rb b/spec/graphql/resolvers/project_milestones_resolver_spec.rb index 36ced72934f..e0b250cfe7c 100644 --- a/spec/graphql/resolvers/project_milestone_resolver_spec.rb +++ b/spec/graphql/resolvers/project_milestones_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Resolvers::ProjectMilestoneResolver do +RSpec.describe Resolvers::ProjectMilestonesResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 081f99a8307..ab13162b406 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -17,6 +17,7 @@ RSpec.describe GitlabSchema.types['Query'] do current_user snippets design_management + milestone user users ] diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index 040368b5ebd..6c7172e6232 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -62,7 +62,7 @@ RSpec.describe WikiHelper do path = "/#{wiki.project.full_path}/-/wikis/pages?direction=#{direction}&sort=#{sort}" helper.link_to(path, type: 'button', class: classes, title: 'Sort direction') do - helper.sprite_icon("sort-#{icon_class}", size: 16) + helper.sprite_icon("sort-#{icon_class}") end end diff --git a/spec/lib/gitlab/redis/hll_spec.rb b/spec/lib/gitlab/redis/hll_spec.rb new file mode 100644 index 00000000000..51768dd81c1 --- /dev/null +++ b/spec/lib/gitlab/redis/hll_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Redis::HLL, :clean_gitlab_redis_shared_state do + describe '.add' do + it 'raise an error when using an invalid key format' do + expect { described_class.add(key: 'test', value: 1, expiry: 1.day) }.to raise_error(Gitlab::Redis::HLL::KeyFormatError) + expect { described_class.add(key: 'test-{metric', value: 1, expiry: 1.day) }.to raise_error(Gitlab::Redis::HLL::KeyFormatError) + expect { described_class.add(key: 'test-{metric}}', value: 1, expiry: 1.day) }.to raise_error(Gitlab::Redis::HLL::KeyFormatError) + end + + it "doesn't raise error when having correct format" do + expect { described_class.add(key: 'test-{metric}', value: 1, expiry: 1.day) }.not_to raise_error + expect { described_class.add(key: 'test-{metric}-1', value: 1, expiry: 1.day) }.not_to raise_error + expect { described_class.add(key: 'test:{metric}-1', value: 1, expiry: 1.day) }.not_to raise_error + expect { described_class.add(key: '2020-216-{project_action}', value: 1, expiry: 1.day) }.not_to raise_error + expect { described_class.add(key: 'i_{analytics}_dev_ops_score-2020-32', value: 1, expiry: 1.day) }.not_to raise_error + end + end +end diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index 5cb08ac1e76..da327ce7706 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -421,6 +421,24 @@ RSpec.describe Gitlab::Workhorse do end end + describe '.send_scaled_image' do + let(:location) { 'http://example.com/avatar.png' } + let(:width) { '150' } + + subject { described_class.send_scaled_image(location, width) } + + it 'sets the header correctly' do + key, command, params = decode_workhorse_header(subject) + + expect(key).to eq("Gitlab-Workhorse-Send-Data") + expect(command).to eq("send-scaled-img") + expect(params).to eq({ + 'Location' => location, + 'Width' => width + }.deep_stringify_keys) + end + end + describe '.send_git_snapshot' do let(:url) { 'http://example.com' } diff --git a/spec/requests/api/graphql/milestone_spec.rb b/spec/requests/api/graphql/milestone_spec.rb new file mode 100644 index 00000000000..59de116fa2b --- /dev/null +++ b/spec/requests/api/graphql/milestone_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Querying a Milestone' do + include GraphqlHelpers + + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:milestone) { create(:milestone, project: project) } + + let(:query) do + graphql_query_for('milestone', { id: milestone.to_global_id.to_s }, 'title') + end + + subject { graphql_data['milestone'] } + + before do + post_graphql(query, current_user: current_user) + end + + context 'when the user has access to the milestone' do + before_all do + project.add_guest(current_user) + end + + it_behaves_like 'a working graphql query' + + it { is_expected.to include('title' => milestone.name) } + end + + context 'when the user does not have access to the milestone' do + it_behaves_like 'a working graphql query' + + it { is_expected.to be_nil } + end + + context 'when ID argument is missing' do + let(:query) do + graphql_query_for('milestone', {}, 'title') + end + + it 'raises an exception' do + expect(graphql_errors).to include(a_hash_including('message' => "Field 'milestone' is missing required arguments: id")) + end + end +end |