diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 15:09:00 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 15:09:00 +0000 |
commit | c282dba898a4cb0645f88579339502a4e3778727 (patch) | |
tree | 94a6457ce4438e085c9ae43bc51a2b5a29787bf2 /spec | |
parent | 2c2dd5e36c4ed5f09f488be288882d98f9124d12 (diff) | |
download | gitlab-ce-c282dba898a4cb0645f88579339502a4e3778727.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/profiles/password_spec.rb | 4 | ||||
-rw-r--r-- | spec/features/projects/badges/coverage_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/projects/settings/registry_settings_spec.rb | 48 | ||||
-rw-r--r-- | spec/features/projects/tags/user_views_tags_spec.rb | 2 | ||||
-rw-r--r-- | spec/frontend/graphql_shared/utils_spec.js | 42 | ||||
-rw-r--r-- | spec/frontend/monitoring/mock_data.js | 6 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/actions_spec.js | 54 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/utils_spec.js | 77 | ||||
-rw-r--r-- | spec/frontend/registry/settings/components/registry_settings_app_spec.js | 29 | ||||
-rw-r--r-- | spec/frontend/registry/settings/store/actions_spec.js | 32 | ||||
-rw-r--r-- | spec/frontend/registry/settings/store/mutations_spec.js | 10 | ||||
-rw-r--r-- | spec/javascripts/groups/components/group_item_spec.js | 29 | ||||
-rw-r--r-- | spec/lib/gitlab/quick_actions/extractor_spec.rb | 18 |
13 files changed, 308 insertions, 45 deletions
diff --git a/spec/features/profiles/password_spec.rb b/spec/features/profiles/password_spec.rb index 8c0c426f689..9dc96080732 100644 --- a/spec/features/profiles/password_spec.rb +++ b/spec/features/profiles/password_spec.rb @@ -63,7 +63,7 @@ describe 'Profile > Password' do visit edit_profile_password_path - expect(page).to have_gitlab_http_status(404) + expect(page).to have_gitlab_http_status(:not_found) end end @@ -73,7 +73,7 @@ describe 'Profile > Password' do it 'renders 404' do visit edit_profile_password_path - expect(page).to have_gitlab_http_status(404) + expect(page).to have_gitlab_http_status(:not_found) end end end diff --git a/spec/features/projects/badges/coverage_spec.rb b/spec/features/projects/badges/coverage_spec.rb index dd51eac9be1..d17588bb7b4 100644 --- a/spec/features/projects/badges/coverage_spec.rb +++ b/spec/features/projects/badges/coverage_spec.rb @@ -54,7 +54,7 @@ describe 'test coverage badge' do it 'user requests test coverage badge image' do show_test_coverage_badge - expect(page).to have_gitlab_http_status(404) + expect(page).to have_gitlab_http_status(:not_found) end end diff --git a/spec/features/projects/settings/registry_settings_spec.rb b/spec/features/projects/settings/registry_settings_spec.rb index 89da9d1b996..1a1940f6efb 100644 --- a/spec/features/projects/settings/registry_settings_spec.rb +++ b/spec/features/projects/settings/registry_settings_spec.rb @@ -4,20 +4,26 @@ require 'spec_helper' describe 'Project > Settings > CI/CD > Container registry tag expiration policy', :js do let(:user) { create(:user) } - let(:project) { create(:project, namespace: user.namespace) } + let(:project) { create(:project, namespace: user.namespace, container_registry_enabled: container_registry_enabled) } + let(:container_registry_enabled) { true } + + before do + sign_in(user) + stub_container_registry_config(enabled: true) + stub_feature_flags(registry_retention_policies_settings: true) + end context 'as owner' do before do - sign_in(user) visit project_settings_ci_cd_path(project) end - it 'section is available' do + it 'shows available section' do settings_block = find('#js-registry-policies') expect(settings_block).to have_text 'Container Registry tag expiration policy' end - it 'Save expiration policy submit the form' do + it 'saves expiration policy submit the form' do within '#js-registry-policies' do within '.card-body' do find('#expiration-policy-toggle button:not(.is-disabled)').click @@ -34,4 +40,38 @@ describe 'Project > Settings > CI/CD > Container registry tag expiration policy' expect(toast).to have_content('Expiration policy successfully saved.') end end + + context 'when registry is disabled' do + before do + stub_container_registry_config(enabled: false) + visit project_settings_ci_cd_path(project) + end + + it 'does not exists' do + expect(page).not_to have_selector('#js-registry-policies') + end + end + + context 'when container registry is disabled on project' do + let(:container_registry_enabled) { false } + + before do + visit project_settings_ci_cd_path(project) + end + + it 'does not exists' do + expect(page).not_to have_selector('#js-registry-policies') + end + end + + context 'when feature flag is disabled' do + before do + stub_feature_flags(registry_retention_policies_settings: false) + visit project_settings_ci_cd_path(project) + end + + it 'does not exists' do + expect(page).not_to have_selector('#js-registry-policies') + end + end end diff --git a/spec/features/projects/tags/user_views_tags_spec.rb b/spec/features/projects/tags/user_views_tags_spec.rb index bc570f502bf..7b49b0d0f65 100644 --- a/spec/features/projects/tags/user_views_tags_spec.rb +++ b/spec/features/projects/tags/user_views_tags_spec.rb @@ -7,7 +7,7 @@ describe 'User views tags', :feature do it do visit project_tags_path(project, format: :atom) - expect(page).to have_gitlab_http_status(200) + expect(page).to have_gitlab_http_status(:ok) end end diff --git a/spec/frontend/graphql_shared/utils_spec.js b/spec/frontend/graphql_shared/utils_spec.js new file mode 100644 index 00000000000..52386bf6ede --- /dev/null +++ b/spec/frontend/graphql_shared/utils_spec.js @@ -0,0 +1,42 @@ +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; + +describe('getIdFromGraphQLId', () => { + [ + { + input: '', + output: null, + }, + { + input: null, + output: null, + }, + { + input: 'gid://', + output: null, + }, + { + input: 'gid://gitlab/', + output: null, + }, + { + input: 'gid://gitlab/Environments', + output: null, + }, + { + input: 'gid://gitlab/Environments/', + output: null, + }, + { + input: 'gid://gitlab/Environments/123', + output: 123, + }, + { + input: 'gid://gitlab/DesignManagement::Version/2', + output: 2, + }, + ].forEach(({ input, output }) => { + it(`getIdFromGraphQLId returns ${output} when passed ${input}`, () => { + expect(getIdFromGraphQLId(input)).toBe(output); + }); + }); +}); diff --git a/spec/frontend/monitoring/mock_data.js b/spec/frontend/monitoring/mock_data.js index ada3e44f0a4..e3357394551 100644 --- a/spec/frontend/monitoring/mock_data.js +++ b/spec/frontend/monitoring/mock_data.js @@ -332,7 +332,7 @@ export const mockedQueryResultPayloadCoresTotal = { }; const extraEnvironmentData = new Array(15).fill(null).map((_, idx) => ({ - id: 136 + idx, + id: `gid://gitlab/Environments/${150 + idx}`, name: `no-deployment/noop-branch-${idx}`, state: 'available', created_at: '2018-07-04T18:39:41.702Z', @@ -341,7 +341,7 @@ const extraEnvironmentData = new Array(15).fill(null).map((_, idx) => ({ export const environmentData = [ { - id: 34, + id: 'gid://gitlab/Environments/34', name: 'production', state: 'available', external_url: 'http://root-autodevops-deploy.my-fake-domain.com', @@ -359,7 +359,7 @@ export const environmentData = [ }, }, { - id: 35, + id: 'gid://gitlab/Environments/35', name: 'review/noop-branch', state: 'available', external_url: 'http://root-autodevops-deploy-review-noop-branc-die93w.my-fake-domain.com', diff --git a/spec/frontend/monitoring/store/actions_spec.js b/spec/frontend/monitoring/store/actions_spec.js index d479b2eb083..352900f7087 100644 --- a/spec/frontend/monitoring/store/actions_spec.js +++ b/spec/frontend/monitoring/store/actions_spec.js @@ -20,6 +20,7 @@ import { setGettingStartedEmptyState, duplicateSystemDashboard, } from '~/monitoring/stores/actions'; +import { gqClient, parseEnvironmentsResponse } from '~/monitoring/stores/utils'; import storeState from '~/monitoring/stores/state'; import { deploymentData, @@ -105,37 +106,46 @@ describe('Monitoring store actions', () => { }); }); describe('fetchEnvironmentsData', () => { - it('commits RECEIVE_ENVIRONMENTS_DATA_SUCCESS on error', done => { + it('commits RECEIVE_ENVIRONMENTS_DATA_SUCCESS on error', () => { const dispatch = jest.fn(); const { state } = store; - state.environmentsEndpoint = '/success'; - mock.onGet(state.environmentsEndpoint).reply(200, { - environments: environmentData, - }); - fetchEnvironmentsData({ + state.projectPath = '/gitlab-org/gitlab-test'; + + jest.spyOn(gqClient, 'mutate').mockReturnValue( + Promise.resolve({ + data: { + project: { + data: { + environments: environmentData, + }, + }, + }, + }), + ); + + return fetchEnvironmentsData({ state, dispatch, - }) - .then(() => { - expect(dispatch).toHaveBeenCalledWith('receiveEnvironmentsDataSuccess', environmentData); - done(); - }) - .catch(done.fail); + }).then(() => { + expect(dispatch).toHaveBeenCalledWith( + 'receiveEnvironmentsDataSuccess', + parseEnvironmentsResponse(environmentData, state.projectPath), + ); + }); }); - it('commits RECEIVE_ENVIRONMENTS_DATA_FAILURE on error', done => { + + it('commits RECEIVE_ENVIRONMENTS_DATA_FAILURE on error', () => { const dispatch = jest.fn(); const { state } = store; - state.environmentsEndpoint = '/error'; - mock.onGet(state.environmentsEndpoint).reply(500); - fetchEnvironmentsData({ + state.projectPath = '/gitlab-org/gitlab-test'; + jest.spyOn(gqClient, 'mutate').mockReturnValue(Promise.reject()); + + return fetchEnvironmentsData({ state, dispatch, - }) - .then(() => { - expect(dispatch).toHaveBeenCalledWith('receiveEnvironmentsDataFailure'); - done(); - }) - .catch(done.fail); + }).then(() => { + expect(dispatch).toHaveBeenCalledWith('receiveEnvironmentsDataFailure'); + }); }); }); describe('Set endpoints', () => { diff --git a/spec/frontend/monitoring/store/utils_spec.js b/spec/frontend/monitoring/store/utils_spec.js index d562aaaefe9..d322d45457e 100644 --- a/spec/frontend/monitoring/store/utils_spec.js +++ b/spec/frontend/monitoring/store/utils_spec.js @@ -1,4 +1,11 @@ -import { normalizeMetric, uniqMetricsId } from '~/monitoring/stores/utils'; +import { + normalizeMetric, + uniqMetricsId, + parseEnvironmentsResponse, + removeLeadingSlash, +} from '~/monitoring/stores/utils'; + +const projectPath = 'gitlab-org/gitlab-test'; describe('normalizeMetric', () => { [ @@ -32,3 +39,71 @@ describe('uniqMetricsId', () => { }); }); }); + +describe('parseEnvironmentsResponse', () => { + [ + { + input: null, + output: [], + }, + { + input: undefined, + output: [], + }, + { + input: [], + output: [], + }, + { + input: [ + { + id: '1', + name: 'env-1', + }, + ], + output: [ + { + id: 1, + name: 'env-1', + metrics_path: `${projectPath}/environments/1/metrics`, + }, + ], + }, + { + input: [ + { + id: 'gid://gitlab/Environment/12', + name: 'env-12', + }, + ], + output: [ + { + id: 12, + name: 'env-12', + metrics_path: `${projectPath}/environments/12/metrics`, + }, + ], + }, + ].forEach(({ input, output }) => { + it(`parseEnvironmentsResponse returns ${JSON.stringify(output)} with input ${JSON.stringify( + input, + )}`, () => { + expect(parseEnvironmentsResponse(input, projectPath)).toEqual(output); + }); + }); +}); + +describe('removeLeadingSlash', () => { + [ + { input: null, output: '' }, + { input: '', output: '' }, + { input: 'gitlab-org', output: 'gitlab-org' }, + { input: 'gitlab-org/gitlab', output: 'gitlab-org/gitlab' }, + { input: '/gitlab-org/gitlab', output: 'gitlab-org/gitlab' }, + { input: '////gitlab-org/gitlab', output: 'gitlab-org/gitlab' }, + ].forEach(({ input, output }) => { + it(`removeLeadingSlash returns ${output} with input ${input}`, () => { + expect(removeLeadingSlash(input)).toEqual(output); + }); + }); +}); diff --git a/spec/frontend/registry/settings/components/registry_settings_app_spec.js b/spec/frontend/registry/settings/components/registry_settings_app_spec.js index eceb5bf643c..8a5c5d84198 100644 --- a/spec/frontend/registry/settings/components/registry_settings_app_spec.js +++ b/spec/frontend/registry/settings/components/registry_settings_app_spec.js @@ -1,16 +1,21 @@ import { shallowMount } from '@vue/test-utils'; +import { GlAlert } from '@gitlab/ui'; import component from '~/registry/settings/components/registry_settings_app.vue'; +import SettingsForm from '~/registry/settings/components/settings_form.vue'; import { createStore } from '~/registry/settings/store/'; +import { SET_IS_DISABLED } from '~/registry/settings/store/mutation_types'; import { FETCH_SETTINGS_ERROR_MESSAGE } from '~/registry/settings/constants'; describe('Registry Settings App', () => { let wrapper; let store; - const findSettingsComponent = () => wrapper.find({ ref: 'settings-form' }); + const findSettingsComponent = () => wrapper.find(SettingsForm); + const findAlert = () => wrapper.find(GlAlert); - const mountComponent = ({ dispatchMock } = {}) => { + const mountComponent = ({ dispatchMock = 'mockResolvedValue', isDisabled = false } = {}) => { store = createStore(); + store.commit(SET_IS_DISABLED, isDisabled); const dispatchSpy = jest.spyOn(store, 'dispatch'); if (dispatchMock) { dispatchSpy[dispatchMock](); @@ -30,12 +35,12 @@ describe('Registry Settings App', () => { }); it('renders', () => { - mountComponent({ dispatchMock: 'mockResolvedValue' }); + mountComponent(); expect(wrapper.element).toMatchSnapshot(); }); it('call the store function to load the data on mount', () => { - mountComponent({ dispatchMock: 'mockResolvedValue' }); + mountComponent(); expect(store.dispatch).toHaveBeenCalledWith('fetchSettings'); }); @@ -49,7 +54,21 @@ describe('Registry Settings App', () => { }); it('renders the setting form', () => { - mountComponent({ dispatchMock: 'mockResolvedValue' }); + mountComponent(); expect(findSettingsComponent().exists()).toBe(true); }); + + describe('isDisabled', () => { + beforeEach(() => { + mountComponent({ isDisabled: true }); + }); + + it('the form is hidden', () => { + expect(findSettingsComponent().exists()).toBe(false); + }); + + it('shows an alert', () => { + expect(findAlert().exists()).toBe(true); + }); + }); }); diff --git a/spec/frontend/registry/settings/store/actions_spec.js b/spec/frontend/registry/settings/store/actions_spec.js index 65b1fc42bfe..f904d0b660a 100644 --- a/spec/frontend/registry/settings/store/actions_spec.js +++ b/spec/frontend/registry/settings/store/actions_spec.js @@ -5,18 +5,38 @@ import * as types from '~/registry/settings/store/mutation_types'; describe('Actions Registry Store', () => { describe.each` - actionName | mutationName | payload - ${'setInitialState'} | ${types.SET_INITIAL_STATE} | ${'foo'} - ${'updateSettings'} | ${types.UPDATE_SETTINGS} | ${'foo'} - ${'receiveSettingsSuccess'} | ${types.SET_SETTINGS} | ${'foo'} - ${'toggleLoading'} | ${types.TOGGLE_LOADING} | ${undefined} - ${'resetSettings'} | ${types.RESET_SETTINGS} | ${undefined} + actionName | mutationName | payload + ${'setInitialState'} | ${types.SET_INITIAL_STATE} | ${'foo'} + ${'updateSettings'} | ${types.UPDATE_SETTINGS} | ${'foo'} + ${'toggleLoading'} | ${types.TOGGLE_LOADING} | ${undefined} + ${'resetSettings'} | ${types.RESET_SETTINGS} | ${undefined} `('%s action invokes %s mutation with payload %s', ({ actionName, mutationName, payload }) => { it('should set the initial state', done => { testAction(actions[actionName], payload, {}, [{ type: mutationName, payload }], [], done); }); }); + describe('receiveSettingsSuccess', () => { + it('calls SET_SETTINGS when data is present', () => { + testAction( + actions.receiveSettingsSuccess, + 'foo', + {}, + [{ type: types.SET_SETTINGS, payload: 'foo' }], + [], + ); + }); + it('calls SET_IS_DISABLED when data is not present', () => { + testAction( + actions.receiveSettingsSuccess, + null, + {}, + [{ type: types.SET_IS_DISABLED, payload: true }], + [], + ); + }); + }); + describe('fetchSettings', () => { const state = { projectId: 'bar', diff --git a/spec/frontend/registry/settings/store/mutations_spec.js b/spec/frontend/registry/settings/store/mutations_spec.js index 1a0effbe125..deb59089d60 100644 --- a/spec/frontend/registry/settings/store/mutations_spec.js +++ b/spec/frontend/registry/settings/store/mutations_spec.js @@ -32,6 +32,7 @@ describe('Mutations Registry Store', () => { expect(mockState.settings).toEqual(expectedState.settings); }); }); + describe('SET_SETTINGS', () => { it('should set the settings and original', () => { const payload = { foo: 'baz' }; @@ -41,6 +42,7 @@ describe('Mutations Registry Store', () => { expect(mockState.original).toEqual(expectedState.settings); }); }); + describe('RESET_SETTINGS', () => { it('should copy original over settings', () => { mockState.settings = { foo: 'bar' }; @@ -49,10 +51,18 @@ describe('Mutations Registry Store', () => { expect(mockState.settings).toEqual(mockState.original); }); }); + describe('TOGGLE_LOADING', () => { it('should toggle the loading', () => { mutations[types.TOGGLE_LOADING](mockState); expect(mockState.isLoading).toEqual(true); }); }); + + describe('SET_IS_DISABLED', () => { + it('should set isDisabled', () => { + mutations[types.SET_IS_DISABLED](mockState, true); + expect(mockState.isDisabled).toEqual(true); + }); + }); }); diff --git a/spec/javascripts/groups/components/group_item_spec.js b/spec/javascripts/groups/components/group_item_spec.js index 39575ee9f97..2889d7ae4ff 100644 --- a/spec/javascripts/groups/components/group_item_spec.js +++ b/spec/javascripts/groups/components/group_item_spec.js @@ -155,6 +155,35 @@ describe('GroupItemComponent', () => { }); describe('template', () => { + let group = null; + + describe('for a group pending deletion', () => { + beforeEach(() => { + group = { ...mockParentGroupItem, pendingRemoval: true }; + vm = createComponent(group); + }); + + it('renders the group pending removal badge', () => { + const badgeEl = vm.$el.querySelector('.badge-warning'); + + expect(badgeEl).toBeDefined(); + expect(badgeEl).toContainText('pending removal'); + }); + }); + + describe('for a group not scheduled for deletion', () => { + beforeEach(() => { + group = { ...mockParentGroupItem, pendingRemoval: false }; + vm = createComponent(group); + }); + + it('does not render the group pending removal badge', () => { + const groupTextContainer = vm.$el.querySelector('.group-text-container'); + + expect(groupTextContainer).not.toContainText('pending removal'); + }); + }); + it('should render component template correctly', () => { const visibilityIconEl = vm.$el.querySelector('.item-visibility'); diff --git a/spec/lib/gitlab/quick_actions/extractor_spec.rb b/spec/lib/gitlab/quick_actions/extractor_spec.rb index f1acb5b7049..2536e4a372b 100644 --- a/spec/lib/gitlab/quick_actions/extractor_spec.rb +++ b/spec/lib/gitlab/quick_actions/extractor_spec.rb @@ -294,4 +294,22 @@ describe Gitlab::QuickActions::Extractor do expect(msg).to eq expected_msg end end + + describe '#redact_commands' do + using RSpec::Parameterized::TableSyntax + + where(:text, :expected) do + "hello\n/labels ~label1 ~label2\nworld" | "hello\n`/labels ~label1 ~label2`\nworld" + "hello\n/open\n/labels ~label1\nworld" | "hello\n`/open`\n`/labels ~label1`\nworld" + "hello\n/reopen\nworld" | "hello\n`/reopen`\nworld" + "/reopen\nworld" | "`/reopen`\nworld" + "hello\n/open" | "hello\n`/open`" + end + + with_them do + it 'encloses quick actions with code span markdown' do + expect(extractor.redact_commands(text)).to eq(expected) + end + end + end end |