diff options
Diffstat (limited to 'spec')
4 files changed, 113 insertions, 61 deletions
diff --git a/spec/frontend/vue_shared/components/sidebar/labels_select/dropdown_value_spec.js b/spec/frontend/vue_shared/components/sidebar/labels_select/dropdown_value_spec.js index ec143fec5d9..52c0298603d 100644 --- a/spec/frontend/vue_shared/components/sidebar/labels_select/dropdown_value_spec.js +++ b/spec/frontend/vue_shared/components/sidebar/labels_select/dropdown_value_spec.js @@ -1,24 +1,31 @@ -import Vue from 'vue'; -import $ from 'jquery'; +import { mount } from '@vue/test-utils'; +import { hexToRgb } from '~/lib/utils/color_utils'; +import DropdownValueComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_value.vue'; +import DropdownValueScopedLabel from '~/vue_shared/components/sidebar/labels_select/dropdown_value_scoped_label.vue'; -import dropdownValueComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_value.vue'; - -import mountComponent from 'helpers/vue_mount_component_helper'; import { mockConfig, mockLabels, } from '../../../../../javascripts/vue_shared/components/sidebar/labels_select/mock_data'; +const labelStyles = { + textColor: '#FFFFFF', + color: '#BADA55', +}; const createComponent = ( labels = mockLabels, labelFilterBasePath = mockConfig.labelFilterBasePath, ) => { - const Component = Vue.extend(dropdownValueComponent); - - return mountComponent(Component, { - labels, - labelFilterBasePath, - enableScopedLabels: true, + labels.forEach(label => Object.assign(label, labelStyles)); + + return mount(DropdownValueComponent, { + propsData: { + labels, + labelFilterBasePath, + enableScopedLabels: true, + }, + attachToDocument: true, + sync: false, }); }; @@ -30,7 +37,7 @@ describe('DropdownValueComponent', () => { }); afterEach(() => { - vm.$destroy(); + vm.destroy(); }); describe('computed', () => { @@ -38,12 +45,12 @@ describe('DropdownValueComponent', () => { it('returns true if `labels` prop is empty', () => { const vmEmptyLabels = createComponent([]); - expect(vmEmptyLabels.isEmpty).toBe(true); - vmEmptyLabels.$destroy(); + expect(vmEmptyLabels.classes()).not.toContain('has-labels'); + vmEmptyLabels.destroy(); }); it('returns false if `labels` prop is empty', () => { - expect(vm.isEmpty).toBe(false); + expect(vm.classes()).toContain('has-labels'); }); }); }); @@ -51,88 +58,71 @@ describe('DropdownValueComponent', () => { describe('methods', () => { describe('labelFilterUrl', () => { it('returns URL string starting with labelFilterBasePath and encoded label.title', () => { - expect( - vm.labelFilterUrl({ - title: 'Foo bar', - }), - ).toBe('/gitlab-org/my-project/issues?label_name[]=Foo%20bar'); + expect(vm.find(DropdownValueScopedLabel).props('labelFilterUrl')).toBe( + '/gitlab-org/my-project/issues?label_name[]=Foo%3A%3ABar', + ); }); }); describe('labelStyle', () => { it('returns object with `color` & `backgroundColor` properties from label.textColor & label.color', () => { - const label = { - textColor: '#FFFFFF', - color: '#BADA55', - }; - const styleObj = vm.labelStyle(label); - - expect(styleObj.color).toBe(label.textColor); - expect(styleObj.backgroundColor).toBe(label.color); - }); - }); - - describe('scopedLabelsDescription', () => { - it('returns html for tooltip', () => { - const html = vm.scopedLabelsDescription(mockLabels[1]); - const $el = $.parseHTML(html); - - expect($el[0]).toHaveClass('scoped-label-tooltip-title'); - expect($el[2].textContent).toEqual(mockLabels[1].description); + expect(vm.find(DropdownValueScopedLabel).props('labelStyle')).toEqual({ + color: labelStyles.textColor, + backgroundColor: labelStyles.color, + }); }); }); describe('showScopedLabels', () => { it('returns true if the label is scoped label', () => { - expect(vm.showScopedLabels(mockLabels[1])).toBe(true); - }); - - it('returns false when label is a regular label', () => { - expect(vm.showScopedLabels(mockLabels[0])).toBe(false); + expect(vm.findAll(DropdownValueScopedLabel).length).toEqual(1); }); }); }); describe('template', () => { it('renders component container element with classes `hide-collapsed value issuable-show-labels`', () => { - expect(vm.$el.classList.contains('hide-collapsed', 'value', 'issuable-show-labels')).toBe( - true, - ); + expect(vm.classes()).toContain('hide-collapsed', 'value', 'issuable-show-labels'); }); it('render slot content inside component when `labels` prop is empty', () => { const vmEmptyLabels = createComponent([]); - expect(vmEmptyLabels.$el.querySelector('.text-secondary').innerText.trim()).toBe( - mockConfig.emptyValueText, - ); - vmEmptyLabels.$destroy(); + expect( + vmEmptyLabels + .find('.text-secondary') + .text() + .trim(), + ).toBe(mockConfig.emptyValueText); + vmEmptyLabels.destroy(); }); it('renders label element with filter URL', () => { - expect(vm.$el.querySelector('a').getAttribute('href')).toBe( + expect(vm.find('a').attributes('href')).toBe( '/gitlab-org/my-project/issues?label_name[]=Foo%20Label', ); }); it('renders label element and styles based on label details', () => { - const labelEl = vm.$el.querySelector('a span.badge.color-label'); + const labelEl = vm.find('a span.badge.color-label'); - expect(labelEl).not.toBeNull(); - expect(labelEl.getAttribute('style')).toBe('background-color: rgb(186, 218, 85);'); - expect(labelEl.innerText.trim()).toBe(mockLabels[0].title); + expect(labelEl.exists()).toBe(true); + expect(labelEl.attributes('style')).toContain( + `background-color: rgb(${hexToRgb(labelStyles.color).join(', ')});`, + ); + expect(labelEl.text().trim()).toBe(mockLabels[0].title); }); describe('label is of scoped-label type', () => { it('renders a scoped-label-wrapper span to incorporate 2 anchors', () => { - expect(vm.$el.querySelector('span.scoped-label-wrapper')).not.toBeNull(); + expect(vm.find('span.scoped-label-wrapper').exists()).toBe(true); }); it('renders anchor tag containing question icon', () => { - const anchor = vm.$el.querySelector('.scoped-label-wrapper a.scoped-label'); + const anchor = vm.find('.scoped-label-wrapper a.scoped-label'); - expect(anchor).not.toBeNull(); - expect(anchor.querySelector('i.fa-question-circle')).not.toBeNull(); + expect(anchor.exists()).toBe(true); + expect(anchor.find('i.fa-question-circle').exists()).toBe(true); }); }); }); diff --git a/spec/javascripts/boards/board_card_spec.js b/spec/javascripts/boards/board_card_spec.js index 51433a58212..72367377929 100644 --- a/spec/javascripts/boards/board_card_spec.js +++ b/spec/javascripts/boards/board_card_spec.js @@ -13,7 +13,7 @@ import '~/boards/models/list'; import store from '~/boards/stores'; import boardsStore from '~/boards/stores/boards_store'; import boardCard from '~/boards/components/board_card.vue'; -import { listObj, boardsMockInterceptor, mockBoardService } from './mock_data'; +import { listObj, boardsMockInterceptor, setMockEndpoints } from './mock_data'; describe('Board card', () => { let vm; @@ -22,8 +22,8 @@ describe('Board card', () => { beforeEach(done => { mock = new MockAdapter(axios); mock.onAny().reply(boardsMockInterceptor); + setMockEndpoints(); - gl.boardService = mockBoardService(); boardsStore.create(); boardsStore.detail.issue = {}; diff --git a/spec/javascripts/boards/mock_data.js b/spec/javascripts/boards/mock_data.js index 41b8f567e08..bd295ba61ac 100644 --- a/spec/javascripts/boards/mock_data.js +++ b/spec/javascripts/boards/mock_data.js @@ -1,6 +1,20 @@ import BoardService from '~/boards/services/board_service'; import boardsStore from '~/boards/stores/boards_store'; +export const setMockEndpoints = (opts = {}) => { + const boardsEndpoint = opts.boardsEndpoint || '/test/issue-boards/-/boards.json'; + const listsEndpoint = opts.listsEndpoint || '/test/-/boards/1/lists'; + const bulkUpdatePath = opts.bulkUpdatePath || ''; + const boardId = opts.boardId || '1'; + + boardsStore.setEndpoints({ + boardsEndpoint, + listsEndpoint, + bulkUpdatePath, + boardId, + }); +}; + export const boardObj = { id: 1, name: 'test', diff --git a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb new file mode 100644 index 00000000000..b0f1e52f397 --- /dev/null +++ b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require_relative '../../../rubocop/cop/put_project_routes_under_scope' + +describe RuboCop::Cop::PutProjectRoutesUnderScope do + include CopHelper + + subject(:cop) { described_class.new } + + before do + allow(cop).to receive(:in_project_routes?).and_return(true) + end + + it 'registers an offense when route is outside scope' do + expect_offense(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + end + + resource :notes + ^^^^^^^^^^^^^^^ Put new project routes under /-/ scope + PATTERN + end + + it 'does not register an offense when resource inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + resource :notes + end + PATTERN + end + + it 'does not register an offense when resource is deep inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + resource :projects do + resource :issues do + resource :notes + end + end + end + PATTERN + end +end |