diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 12:09:12 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 12:09:12 +0000 |
commit | 3ab4feda4dce9c9f0672375ae27c2f7c2ba6f4ad (patch) | |
tree | be5a771e0427ed98cdb58acfd5c631b4b2eb4bf9 /spec | |
parent | c72e5ebe9938d315ec598197873e71a80168d40a (diff) | |
download | gitlab-ce-3ab4feda4dce9c9f0672375ae27c2f7c2ba6f4ad.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/issues_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/frontend/issuables_list/components/issuables_list_app_spec.js | 141 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 7 | ||||
-rw-r--r-- | spec/requests/api/error_tracking_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/spam/mark_as_spam_service_spec.rb | 2 |
5 files changed, 132 insertions, 36 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index fb4d1cf59fe..806a4e2f52c 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -740,16 +740,16 @@ describe Projects::IssuesController do .to log_spam(title: 'Spam title', noteable_type: 'Issue') end - it 'renders recaptcha_html json response' do - update_issue - - expect(json_response).to have_key('recaptcha_html') - end + context 'renders properly' do + render_views - it 'returns 200 status' do - update_issue + it 'renders recaptcha_html json response' do + update_issue - expect(response).to have_gitlab_http_status(:ok) + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to have_key('recaptcha_html') + expect(json_response['recaptcha_html']).not_to be_empty + end end end diff --git a/spec/frontend/issuables_list/components/issuables_list_app_spec.js b/spec/frontend/issuables_list/components/issuables_list_app_spec.js index eafc4d83d87..6b680af354e 100644 --- a/spec/frontend/issuables_list/components/issuables_list_app_spec.js +++ b/spec/frontend/issuables_list/components/issuables_list_app_spec.js @@ -12,12 +12,21 @@ import { PAGE_SIZE, PAGE_SIZE_MANUAL, RELATIVE_POSITION } from '~/issuables_list jest.mock('~/flash', () => jest.fn()); jest.mock('~/issuables_list/eventhub'); +jest.mock('~/lib/utils/common_utils', () => ({ + ...jest.requireActual('~/lib/utils/common_utils'), + scrollToElement: () => {}, +})); const TEST_LOCATION = `${TEST_HOST}/issues`; const TEST_ENDPOINT = '/issues'; const TEST_CREATE_ISSUES_PATH = '/createIssue'; const TEST_EMPTY_SVG_PATH = '/emptySvg'; +const setUrl = query => { + window.location.href = `${TEST_LOCATION}${query}`; + window.location.search = query; +}; + const MOCK_ISSUES = Array(PAGE_SIZE_MANUAL) .fill(0) .map((_, i) => ({ @@ -267,8 +276,6 @@ describe('Issuables list component', () => { }); describe('with query params in window.location', () => { - const query = - '?assignee_username=root&author_username=root&confidential=yes&label_name%5B%5D=Aquapod&label_name%5B%5D=Astro&milestone_title=v3.0&my_reaction_emoji=airplane&scope=all&sort=priority&state=opened&utf8=%E2%9C%93&weight=0'; const expectedFilters = { assignee_username: 'root', author_username: 'root', @@ -284,32 +291,73 @@ describe('Issuables list component', () => { sort: 'desc', }; - beforeEach(() => { - window.location.href = `${TEST_LOCATION}${query}`; - window.location.search = query; - setupApiMock(() => [200, MOCK_ISSUES.slice(0)]); - factory({ sortKey: 'milestone_due_desc' }); - return waitForPromises(); - }); + describe('when page is not present in params', () => { + const query = + '?assignee_username=root&author_username=root&confidential=yes&label_name%5B%5D=Aquapod&label_name%5B%5D=Astro&milestone_title=v3.0&my_reaction_emoji=airplane&scope=all&sort=priority&state=opened&utf8=%E2%9C%93&weight=0'; - it('applies filters and sorts', () => { - expect(wrapper.vm.hasFilters).toBe(true); - expect(wrapper.vm.filters).toEqual(expectedFilters); + beforeEach(() => { + setUrl(query); - expect(apiSpy).toHaveBeenCalledWith( - expect.objectContaining({ - params: { - ...expectedFilters, - with_labels_details: true, - page: 1, - per_page: PAGE_SIZE, - }, - }), - ); + setupApiMock(() => [200, MOCK_ISSUES.slice(0)]); + factory({ sortKey: 'milestone_due_desc' }); + + return waitForPromises(); + }); + + afterEach(() => { + apiSpy.mockClear(); + }); + + it('applies filters and sorts', () => { + expect(wrapper.vm.hasFilters).toBe(true); + expect(wrapper.vm.filters).toEqual(expectedFilters); + + expect(apiSpy).toHaveBeenCalledWith( + expect.objectContaining({ + params: { + ...expectedFilters, + with_labels_details: true, + page: 1, + per_page: PAGE_SIZE, + }, + }), + ); + }); + + it('passes the base url to issuable', () => { + expect(findFirstIssuable().props('baseUrl')).toBe(TEST_LOCATION); + }); }); - it('passes the base url to issuable', () => { - expect(findFirstIssuable().props('baseUrl')).toEqual(TEST_LOCATION); + describe('when page is present in the param', () => { + const query = + '?assignee_username=root&author_username=root&confidential=yes&label_name%5B%5D=Aquapod&label_name%5B%5D=Astro&milestone_title=v3.0&my_reaction_emoji=airplane&scope=all&sort=priority&state=opened&utf8=%E2%9C%93&weight=0&page=3'; + + beforeEach(() => { + setUrl(query); + + setupApiMock(() => [200, MOCK_ISSUES.slice(0)]); + factory({ sortKey: 'milestone_due_desc' }); + + return waitForPromises(); + }); + + afterEach(() => { + apiSpy.mockClear(); + }); + + it('applies filters and sorts', () => { + expect(apiSpy).toHaveBeenCalledWith( + expect.objectContaining({ + params: { + ...expectedFilters, + with_labels_details: true, + page: 3, + per_page: PAGE_SIZE, + }, + }), + ); + }); }); }); @@ -322,7 +370,7 @@ describe('Issuables list component', () => { }); it('passes the base url to issuable', () => { - expect(findFirstIssuable().props('baseUrl')).toEqual(TEST_LOCATION); + expect(findFirstIssuable().props('baseUrl')).toBe(TEST_LOCATION); }); }); @@ -402,4 +450,47 @@ describe('Issuables list component', () => { }); }); }); + + describe('when paginates', () => { + const newPage = 3; + + beforeEach(() => { + window.history.pushState = jest.fn(); + setupApiMock(() => [ + 200, + MOCK_ISSUES.slice(0, PAGE_SIZE), + { + 'x-total': 100, + 'x-page': 2, + }, + ]); + + factory(); + + return waitForPromises(); + }); + + afterEach(() => { + // reset to original value + window.history.pushState.mockRestore(); + }); + + it('calls window.history.pushState one time', () => { + // Trigger pagination + wrapper.find(GlPagination).vm.$emit('input', newPage); + + expect(window.history.pushState).toHaveBeenCalledTimes(1); + }); + + it('sets params in the url', () => { + // Trigger pagination + wrapper.find(GlPagination).vm.$emit('input', newPage); + + expect(window.history.pushState).toHaveBeenCalledWith( + {}, + '', + `${TEST_LOCATION}?state=opened&order_by=priority&sort=asc&page=${newPage}`, + ); + }); + }); }); diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index f58bcbebd67..eaf19bd4fea 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -10,8 +10,13 @@ describe Service do it { is_expected.to have_one :issue_tracker_data } end - describe 'Validations' do + describe 'validations' do it { is_expected.to validate_presence_of(:type) } + + it 'validates presence of project_id if not template', :aggregate_failures do + expect(build(:service, project_id: nil, template: true)).to be_valid + expect(build(:service, project_id: nil, template: false)).to be_invalid + end end describe 'Scopes' do diff --git a/spec/requests/api/error_tracking_spec.rb b/spec/requests/api/error_tracking_spec.rb index 120248bdbc6..deed9777025 100644 --- a/spec/requests/api/error_tracking_spec.rb +++ b/spec/requests/api/error_tracking_spec.rb @@ -22,7 +22,7 @@ describe API::ErrorTracking do end shared_examples 'returns 404' do - it 'returns correct project settings' do + it 'returns no project settings' do make_request expect(response).to have_gitlab_http_status(:not_found) diff --git a/spec/services/spam/mark_as_spam_service_spec.rb b/spec/services/spam/mark_as_spam_service_spec.rb index cba9d6a39cb..9978005279a 100644 --- a/spec/services/spam/mark_as_spam_service_spec.rb +++ b/spec/services/spam/mark_as_spam_service_spec.rb @@ -7,7 +7,7 @@ describe Spam::MarkAsSpamService do let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) } let(:fake_akismet_service) { double(:akismet_service, submit_spam: true) } - subject { described_class.new(spammable: spammable) } + subject { described_class.new(target: spammable) } describe '#execute' do before do |