diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-29 03:09:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-29 03:09:05 +0300 |
commit | 72278d5e10d7470b59b81c1e51379baa3a6cdab8 (patch) | |
tree | f8d5198f16b06e280446a72c197969761ddef80a /spec | |
parent | 680fd17700f55b3718e4d1de56631b4a8f9e6d6c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/diffs/components/tree_list_spec.js | 36 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 49 |
2 files changed, 70 insertions, 15 deletions
diff --git a/spec/frontend/diffs/components/tree_list_spec.js b/spec/frontend/diffs/components/tree_list_spec.js index 1ec8547d325..f56dd28ce9c 100644 --- a/spec/frontend/diffs/components/tree_list_spec.js +++ b/spec/frontend/diffs/components/tree_list_spec.js @@ -1,4 +1,3 @@ -import { shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; import TreeList from '~/diffs/components/tree_list.vue'; @@ -6,18 +5,21 @@ import createStore from '~/diffs/store/modules'; import batchComments from '~/batch_comments/stores/modules/batch_comments'; import DiffFileRow from '~/diffs/components//diff_file_row.vue'; import { stubComponent } from 'helpers/stub_component'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; describe('Diffs tree list component', () => { let wrapper; let store; const getScroller = () => wrapper.findComponent({ name: 'RecycleScroller' }); const getFileRow = () => wrapper.findComponent(DiffFileRow); + const findDiffTreeSearch = () => wrapper.findByTestId('diff-tree-search'); + Vue.use(Vuex); - const createComponent = () => { - wrapper = shallowMount(TreeList, { + const createComponent = ({ hideFileStats = false } = {}) => { + wrapper = shallowMountExtended(TreeList, { store, - propsData: { hideFileStats: false }, + propsData: { hideFileStats }, stubs: { // eslint will fail if we import the real component RecycleScroller: stubComponent( @@ -116,7 +118,10 @@ describe('Diffs tree list component', () => { describe('search by file extension', () => { it('hides scroller for no matches', async () => { - wrapper.find('[data-testid="diff-tree-search"]').setValue('*.md'); + const input = findDiffTreeSearch(); + + input.element.value = '*.md'; + input.trigger('input'); await nextTick(); @@ -131,7 +136,10 @@ describe('Diffs tree list component', () => { ${'app/*.js'} | ${2} ${'*.js, *.rb'} | ${3} `('returns $itemSize item for $extension', async ({ extension, itemSize }) => { - wrapper.find('[data-testid="diff-tree-search"]').setValue(extension); + const input = findDiffTreeSearch(); + + input.element.value = extension; + input.trigger('input'); await nextTick(); @@ -143,23 +151,21 @@ describe('Diffs tree list component', () => { expect(getScroller().props('items')).toHaveLength(2); }); - it('hides file stats', async () => { - wrapper.setProps({ hideFileStats: true }); - - await nextTick(); - expect(wrapper.find('.file-row-stats').exists()).toBe(false); + it('hides file stats', () => { + createComponent({ hideFileStats: true }); + expect(getFileRow().props('hideFileStats')).toBe(true); }); it('calls toggleTreeOpen when clicking folder', () => { - jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(undefined); + jest.spyOn(store, 'dispatch').mockReturnValue(undefined); getFileRow().vm.$emit('toggleTreeOpen', 'app'); - expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/toggleTreeOpen', 'app'); + expect(store.dispatch).toHaveBeenCalledWith('diffs/toggleTreeOpen', 'app'); }); it('renders when renderTreeList is false', async () => { - wrapper.vm.$store.state.diffs.renderTreeList = false; + store.state.diffs.renderTreeList = false; await nextTick(); expect(getScroller().props('items')).toHaveLength(3); @@ -178,7 +184,7 @@ describe('Diffs tree list component', () => { createComponent(); await nextTick(); - expect(wrapper.findComponent(DiffFileRow).props('viewedFiles')).toBe(viewedDiffFileIds); + expect(getFileRow().props('viewedFiles')).toBe(viewedDiffFileIds); }); }); }); diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 07479d4e1e0..20f389681b2 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1565,4 +1565,53 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do it { is_expected.to be_falsey } end end + + describe '#can_admin_associated_clusters?(project)' do + using RSpec::Parameterized::TableSyntax + + where(:project_clusters_exist, :user_can_admin_project_clusters, :group_clusters_exist, :user_can_admin_group_clusters, :expected) do + false | false | false | false | false + true | false | false | false | false + false | true | false | false | false + false | false | true | false | false + false | false | false | true | false + true | true | false | false | true + false | false | true | true | true + true | true | true | true | true + end + + with_them do + subject { helper.can_admin_associated_clusters?(project) } + + let(:clusters) { [double('Cluster')] } + let(:group) { double('Group') } + + before do + allow(project) + .to receive(:clusters) + .and_return(project_clusters_exist ? clusters : []) + allow(helper) + .to receive(:can?).with(user, :admin_cluster, project) + .and_return(user_can_admin_project_clusters) + + allow(project) + .to receive(:group) + .and_return(group) + allow(group) + .to receive(:clusters) + .and_return(group_clusters_exist ? clusters : []) + allow(helper) + .to receive(:can?).with(user, :admin_cluster, project.group) + .and_return(user_can_admin_group_clusters) + end + + it { is_expected.to eq(expected) } + end + end + + describe '#branch_rules_path' do + subject { helper.branch_rules_path } + + it { is_expected.to eq(project_settings_repository_path(project, anchor: 'js-branch-rules')) } + end end |