diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-15 00:07:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-15 00:07:52 +0300 |
commit | 67cd2904c9ebd7ba346cc92a37ac953747a3f0e5 (patch) | |
tree | ed10a6a07c43aa4167a40c39409f8e1fef1a4cce /spec/frontend | |
parent | 30b17460a2569734cf04dae1b2841d3654b2c0ec (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/ide/components/new_dropdown/modal_spec.js | 19 | ||||
-rw-r--r-- | spec/frontend/pages/projects/pipeline_schedules/shared/components/interval_pattern_input_spec.js | 107 |
2 files changed, 98 insertions, 28 deletions
diff --git a/spec/frontend/ide/components/new_dropdown/modal_spec.js b/spec/frontend/ide/components/new_dropdown/modal_spec.js index 597574bdeed..b6d4e60ce34 100644 --- a/spec/frontend/ide/components/new_dropdown/modal_spec.js +++ b/spec/frontend/ide/components/new_dropdown/modal_spec.js @@ -121,8 +121,10 @@ describe('new file modal component', () => { }); describe('submitForm', () => { - it('throws an error when target entry exists', () => { - const store = createStore(); + let store; + beforeEach(() => { + store = createStore(); + store.state.entries = { 'test-path/test': { name: 'test', @@ -131,6 +133,9 @@ describe('new file modal component', () => { }; vm = createComponentWithStore(Component, store).$mount(); + }); + + it('throws an error when target entry exists', () => { vm.open('rename', 'test-path/test'); expect(createFlash).not.toHaveBeenCalled(); @@ -146,5 +151,15 @@ describe('new file modal component', () => { true, ); }); + + it('does not throw error when target entry does not exist', () => { + jest.spyOn(vm, 'renameEntry').mockImplementation(); + + vm.open('rename', 'test-path/test'); + vm.entryName = 'test-path/test2'; + vm.submitForm(); + + expect(createFlash).not.toHaveBeenCalled(); + }); }); }); diff --git a/spec/frontend/pages/projects/pipeline_schedules/shared/components/interval_pattern_input_spec.js b/spec/frontend/pages/projects/pipeline_schedules/shared/components/interval_pattern_input_spec.js index 7db6dba770e..9cc1d6eeb5a 100644 --- a/spec/frontend/pages/projects/pipeline_schedules/shared/components/interval_pattern_input_spec.js +++ b/spec/frontend/pages/projects/pipeline_schedules/shared/components/interval_pattern_input_spec.js @@ -1,16 +1,20 @@ import { shallowMount } from '@vue/test-utils'; import IntervalPatternInput from '~/pages/projects/pipeline_schedules/shared/components/interval_pattern_input.vue'; -const cronIntervalPresets = { - everyDay: '0 4 * * *', - everyWeek: '0 4 * * 0', - everyMonth: '0 4 1 * *', -}; - describe('Interval Pattern Input Component', () => { let oldWindowGl; let wrapper; + const mockHour = 4; + const mockWeekDayIndex = 1; + const mockDay = 1; + + const cronIntervalPresets = { + everyDay: `0 ${mockHour} * * *`, + everyWeek: `0 ${mockHour} * * ${mockWeekDayIndex}`, + everyMonth: `0 ${mockHour} ${mockDay} * *`, + }; + const findEveryDayRadio = () => wrapper.find('#every-day'); const findEveryWeekRadio = () => wrapper.find('#every-week'); const findEveryMonthRadio = () => wrapper.find('#every-month'); @@ -21,13 +25,20 @@ describe('Interval Pattern Input Component', () => { const selectEveryMonthRadio = () => findEveryMonthRadio().setChecked(); const selectCustomRadio = () => findCustomRadio().trigger('click'); - const createWrapper = (props = {}) => { + const createWrapper = (props = {}, data = {}) => { if (wrapper) { throw new Error('A wrapper already exists'); } wrapper = shallowMount(IntervalPatternInput, { propsData: { ...props }, + data() { + return { + randomHour: data?.hour || mockHour, + randomWeekDayIndex: mockWeekDayIndex, + randomDay: mockDay, + }; + }, }); }; @@ -47,39 +58,64 @@ describe('Interval Pattern Input Component', () => { window.gl = oldWindowGl; }); - describe('when prop initialCronInterval is passed', () => { - describe('and prop initialCronInterval is custom', () => { - beforeEach(() => { - createWrapper({ initialCronInterval: '1 2 3 4 5' }); - }); + describe('the input field defaults', () => { + beforeEach(() => { + createWrapper(); + }); - it('the input is enabled', () => { - expect(findCustomInput().attributes('disabled')).toBeUndefined(); - }); + it('to a non empty string when no initial value is not passed', () => { + expect(findCustomInput()).not.toBe(''); }); + }); - describe('and prop initialCronInterval is a preset', () => { - beforeEach(() => { - createWrapper({ initialCronInterval: cronIntervalPresets.everyDay }); - }); + describe('the input field', () => { + const initialCron = '0 * * * *'; - it('the input is disabled', () => { - expect(findCustomInput().attributes('disabled')).toBe('disabled'); - }); + beforeEach(() => { + createWrapper({ initialCronInterval: initialCron }); + }); + + it('is equal to the prop `initialCronInterval` when passed', () => { + expect(findCustomInput().element.value).toBe(initialCron); }); }); - describe('when prop initialCronInterval is not passed', () => { + describe('The input field is enabled', () => { beforeEach(() => { createWrapper(); }); - it('the input is enabled since custom is default value', () => { - expect(findCustomInput().attributes('disabled')).toBeUndefined(); + it('when a default option is selected', () => { + selectEveryDayRadio(); + + return wrapper.vm.$nextTick().then(() => { + expect(findCustomInput().attributes('disabled')).toBeUndefined(); + }); + }); + + it('when the custom option is selected', () => { + selectCustomRadio(); + + return wrapper.vm.$nextTick().then(() => { + expect(findCustomInput().attributes('disabled')).toBeUndefined(); + }); }); }); - describe('User Actions', () => { + describe('formattedTime computed property', () => { + it.each` + desc | hour | expectedValue + ${'returns a time in the afternoon if the value of `random time` is higher than 12'} | ${13} | ${'1:00pm'} + ${'returns a time in the morning if the value of `random time` is lower than 12'} | ${11} | ${'11:00am'} + ${'returns "12:00pm" if the value of `random time` is exactly 12'} | ${12} | ${'12:00pm'} + `('$desc', ({ hour, expectedValue }) => { + createWrapper({}, { hour }); + + expect(wrapper.vm.formattedTime).toBe(expectedValue); + }); + }); + + describe('User Actions with radio buttons', () => { it.each` desc | initialCronInterval | act | expectedValue ${'when everyday is selected, update value'} | ${'1 2 3 4 5'} | ${selectEveryDayRadio} | ${cronIntervalPresets.everyDay} @@ -96,4 +132,23 @@ describe('Interval Pattern Input Component', () => { }); }); }); + describe('User actions with input field for Cron syntax', () => { + beforeEach(() => { + createWrapper(); + }); + + it('when editing the cron input it selects the custom radio button', () => { + const newValue = '0 * * * *'; + + findCustomInput().setValue(newValue); + + expect(wrapper.vm.cronInterval).toBe(newValue); + }); + + it('when value of input is one of the defaults, it selects the corresponding radio button', () => { + findCustomInput().setValue(cronIntervalPresets.everyWeek); + + expect(wrapper.vm.cronInterval).toBe(cronIntervalPresets.everyWeek); + }); + }); }); |