From 001243986195143c395a9811d8254bbf1b9ebfa1 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 22 Jan 2020 09:08:39 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../monitoring/components/dashboard_spec.js | 83 +++++++++++++++++++--- spec/frontend/monitoring/mock_data.js | 17 ++--- spec/frontend/monitoring/store/getters_spec.js | 55 ++++++++++++++ spec/helpers/auth_helper_spec.rb | 9 ++- spec/lib/gitlab/auth/ldap/user_spec.rb | 12 ++++ spec/lib/gitlab/auth/o_auth/user_spec.rb | 14 ++++ spec/lib/gitlab/auth/saml/user_spec.rb | 12 ++++ spec/models/user_spec.rb | 14 ++++ 8 files changed, 198 insertions(+), 18 deletions(-) (limited to 'spec') diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js index 007429a3d02..195abae3783 100644 --- a/spec/frontend/monitoring/components/dashboard_spec.js +++ b/spec/frontend/monitoring/components/dashboard_spec.js @@ -28,6 +28,15 @@ describe('Dashboard', () => { let wrapper; let mock; + const findEnvironmentsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' }); + const findAllEnvironmentsDropdownItems = () => findEnvironmentsDropdown().findAll(GlDropdownItem); + const setSearchTerm = searchTerm => { + wrapper.vm.$store.commit( + `monitoringDashboard/${types.SET_ENVIRONMENTS_SEARCH_TERM}`, + searchTerm, + ); + }; + const createShallowWrapper = (props = {}, options = {}) => { wrapper = shallowMount(Dashboard, { localVue, @@ -52,9 +61,6 @@ describe('Dashboard', () => { }); }; - const findEnvironmentsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' }); - const findAllEnvironmentsDropdownItems = () => findEnvironmentsDropdown().findAll(GlDropdownItem); - beforeEach(() => { store = createStore(); mock = new MockAdapter(axios); @@ -155,12 +161,9 @@ describe('Dashboard', () => { wrapper.vm .$nextTick() .then(() => { - const environmentDropdownItems = findAllEnvironmentsDropdownItems(); + expect(findAllEnvironmentsDropdownItems().length).toEqual(environmentData.length); - expect(wrapper.vm.environments.length).toEqual(environmentData.length); - expect(environmentDropdownItems.length).toEqual(wrapper.vm.environments.length); - - environmentDropdownItems.wrappers.forEach((itemWrapper, index) => { + findAllEnvironmentsDropdownItems().wrappers.forEach((itemWrapper, index) => { const anchorEl = itemWrapper.find('a'); if (anchorEl.exists() && environmentData[index].metrics_path) { const href = anchorEl.attributes('href'); @@ -248,6 +251,70 @@ describe('Dashboard', () => { }); }); + describe('searchable environments dropdown', () => { + beforeEach(() => { + createMountedWrapper( + { hasMetrics: true }, + { + attachToDocument: true, + stubs: ['graph-group', 'panel-type'], + provide: { + glFeatures: { searchableEnvironmentsDropdown: true }, + }, + }, + ); + + setupComponentStore(wrapper); + + return wrapper.vm.$nextTick(); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders a search input', () => { + expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownSearch' }).exists()).toBe(true); + }); + + it('renders dropdown items', () => { + findAllEnvironmentsDropdownItems().wrappers.forEach((itemWrapper, index) => { + const anchorEl = itemWrapper.find('a'); + if (anchorEl.exists()) { + expect(anchorEl.text()).toBe(environmentData[index].name); + } + }); + }); + + it('filters rendered dropdown items', () => { + const searchTerm = 'production'; + const resultEnvs = environmentData.filter(({ name }) => name.indexOf(searchTerm) !== -1); + setSearchTerm(searchTerm); + + return wrapper.vm.$nextTick(() => { + expect(findAllEnvironmentsDropdownItems().length).toEqual(resultEnvs.length); + }); + }); + + it('does not filter dropdown items if search term is empty string', () => { + const searchTerm = ''; + setSearchTerm(searchTerm); + + return wrapper.vm.$nextTick(() => { + expect(findAllEnvironmentsDropdownItems().length).toEqual(environmentData.length); + }); + }); + + it("shows error message if search term doesn't match", () => { + const searchTerm = 'does-not-exist'; + setSearchTerm(searchTerm); + + return wrapper.vm.$nextTick(() => { + expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownMsg' }).isVisible()).toBe(true); + }); + }); + }); + describe('drag and drop function', () => { const findDraggables = () => wrapper.findAll(VueDraggable); const findEnabledDraggables = () => findDraggables().filter(f => !f.attributes('disabled')); diff --git a/spec/frontend/monitoring/mock_data.js b/spec/frontend/monitoring/mock_data.js index 094554f525c..ada3e44f0a4 100644 --- a/spec/frontend/monitoring/mock_data.js +++ b/spec/frontend/monitoring/mock_data.js @@ -331,6 +331,14 @@ export const mockedQueryResultPayloadCoresTotal = { ], }; +const extraEnvironmentData = new Array(15).fill(null).map((_, idx) => ({ + id: 136 + idx, + name: `no-deployment/noop-branch-${idx}`, + state: 'available', + created_at: '2018-07-04T18:39:41.702Z', + updated_at: '2018-07-04T18:44:54.010Z', +})); + export const environmentData = [ { id: 34, @@ -368,14 +376,7 @@ export const environmentData = [ id: 128, }, }, - { - id: 36, - name: 'no-deployment/noop-branch', - state: 'available', - created_at: '2018-07-04T18:39:41.702Z', - updated_at: '2018-07-04T18:44:54.010Z', - }, -]; +].concat(extraEnvironmentData); export const metricsDashboardResponse = { dashboard: { diff --git a/spec/frontend/monitoring/store/getters_spec.js b/spec/frontend/monitoring/store/getters_spec.js index 097a5ca7f7c..263050b462f 100644 --- a/spec/frontend/monitoring/store/getters_spec.js +++ b/spec/frontend/monitoring/store/getters_spec.js @@ -3,6 +3,7 @@ import mutations from '~/monitoring/stores/mutations'; import * as types from '~/monitoring/stores/mutation_types'; import { metricStates } from '~/monitoring/constants'; import { + environmentData, metricsDashboardPayload, mockedEmptyResult, mockedQueryResultPayload, @@ -214,4 +215,58 @@ describe('Monitoring store Getters', () => { }); }); }); + + describe('filteredEnvironments', () => { + let state; + const setupState = (initState = {}) => { + state = { + ...state, + ...initState, + }; + }; + + beforeAll(() => { + setupState({ + environments: environmentData, + }); + }); + + afterAll(() => { + state = null; + }); + + [ + { + input: '', + output: 17, + }, + { + input: ' ', + output: 17, + }, + { + input: null, + output: 17, + }, + { + input: 'does-not-exist', + output: 0, + }, + { + input: 'noop-branch-', + output: 15, + }, + { + input: 'noop-branch-9', + output: 1, + }, + ].forEach(({ input, output }) => { + it(`filteredEnvironments returns ${output} items for ${input}`, () => { + setupState({ + environmentsSearchTerm: input, + }); + expect(getters.filteredEnvironments(state).length).toBe(output); + }); + }); + }); }); diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb index cb7c670198d..9179019cd6a 100644 --- a/spec/helpers/auth_helper_spec.rb +++ b/spec/helpers/auth_helper_spec.rb @@ -73,12 +73,17 @@ describe AuthHelper do describe 'enabled_button_based_providers' do before do - allow(helper).to receive(:auth_providers) { [:twitter, :github] } + allow(helper).to receive(:auth_providers) { [:twitter, :github, :google_oauth2] } end context 'all providers are enabled to sign in' do it 'returns all the enabled providers from settings' do - expect(helper.enabled_button_based_providers).to include('twitter', 'github') + expect(helper.enabled_button_based_providers).to include('twitter', 'github', 'google_oauth2') + end + + it 'puts google and github in the beginning' do + expect(helper.enabled_button_based_providers.first).to eq('google_oauth2') + expect(helper.enabled_button_based_providers.second).to eq('github') end end diff --git a/spec/lib/gitlab/auth/ldap/user_spec.rb b/spec/lib/gitlab/auth/ldap/user_spec.rb index bc09de7b525..071d687b2bf 100644 --- a/spec/lib/gitlab/auth/ldap/user_spec.rb +++ b/spec/lib/gitlab/auth/ldap/user_spec.rb @@ -139,6 +139,18 @@ describe Gitlab::Auth::LDAP::User do expect(gl_user).to be_confirmed end end + + context 'when the current minimum password length is different from the default minimum password length' do + before do + stub_application_setting minimum_password_length: 21 + end + + it 'creates the user' do + ldap_user.save + + expect(gl_user).to be_persisted + end + end end describe 'updating email' do diff --git a/spec/lib/gitlab/auth/o_auth/user_spec.rb b/spec/lib/gitlab/auth/o_auth/user_spec.rb index c621c0aa935..022a544395e 100644 --- a/spec/lib/gitlab/auth/o_auth/user_spec.rb +++ b/spec/lib/gitlab/auth/o_auth/user_spec.rb @@ -86,6 +86,20 @@ describe Gitlab::Auth::OAuth::User do end end + context 'when the current minimum password length is different from the default minimum password length' do + before do + stub_application_setting minimum_password_length: 21 + end + + it 'creates the user' do + stub_omniauth_config(allow_single_sign_on: [provider]) + + oauth_user.save + + expect(gl_user).to be_persisted + end + end + it 'marks user as having password_automatically_set' do stub_omniauth_config(allow_single_sign_on: [provider], external_providers: [provider]) diff --git a/spec/lib/gitlab/auth/saml/user_spec.rb b/spec/lib/gitlab/auth/saml/user_spec.rb index 5546438b7ee..4c400636ddf 100644 --- a/spec/lib/gitlab/auth/saml/user_spec.rb +++ b/spec/lib/gitlab/auth/saml/user_spec.rb @@ -325,6 +325,18 @@ describe Gitlab::Auth::Saml::User do expect(gl_user).to be_confirmed end end + + context 'when the current minimum password length is different from the default minimum password length' do + before do + stub_application_setting minimum_password_length: 21 + end + + it 'creates the user' do + saml_user.save + + expect(gl_user).to be_persisted + end + end end describe 'blocking' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5620f211d9c..6f393d169a2 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -508,6 +508,20 @@ describe User, :do_not_mock_admin_mode do end end + describe '.random_password' do + let(:random_password) { described_class.random_password } + + before do + expect(User).to receive(:password_length).and_return(88..128) + end + + context 'length' do + it 'conforms to the current password length settings' do + expect(random_password.length).to eq(128) + end + end + end + describe '.password_length' do let(:password_length) { described_class.password_length } -- cgit v1.2.3