diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js')
-rw-r--r-- | spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js | 134 |
1 files changed, 1 insertions, 133 deletions
diff --git a/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js b/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js index f54d56c3af4..4cac642bb50 100644 --- a/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js +++ b/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js @@ -1,139 +1,7 @@ -import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import { formatUtcOffset, formatTimezone } from '~/lib/utils/datetime_utility'; -import TimezoneDropdown, { - findTimezoneByIdentifier, -} from '~/pages/projects/pipeline_schedules/shared/components/timezone_dropdown'; +import { findTimezoneByIdentifier } from '~/pages/projects/pipeline_schedules/shared/components/timezone_dropdown'; describe('Timezone Dropdown', () => { - let $inputEl = null; - let $dropdownEl = null; - let $wrapper = null; - const tzListSel = '.dropdown-content ul li a.is-active'; - - const initTimezoneDropdown = (options = {}) => { - // eslint-disable-next-line no-new - new TimezoneDropdown({ - $inputEl, - $dropdownEl, - ...options, - }); - }; - - const findDropdownToggleText = () => $wrapper.find('.dropdown-toggle-text'); - - describe('Initialize', () => { - describe('with dropdown already loaded', () => { - beforeEach(() => { - loadHTMLFixture('pipeline_schedules/edit.html'); - $wrapper = $('.dropdown'); - $inputEl = $('#schedule_cron_timezone'); - $inputEl.val(''); - $dropdownEl = $('.js-timezone-dropdown'); - }); - - afterEach(() => { - resetHTMLFixture(); - }); - - it('can take an $inputEl in the constructor', () => { - initTimezoneDropdown(); - - const tzStr = '[UTC + 5.5] Sri Jayawardenepura'; - const tzValue = 'Asia/Colombo'; - - expect($inputEl.val()).toBe('Etc/UTC'); - - $(`${tzListSel}:contains('${tzStr}')`, $wrapper).trigger('click'); - - const val = $inputEl.val(); - - expect(val).toBe(tzValue); - expect(val).not.toBe('Etc/UTC'); - }); - - it('will format data array of timezones into a list of offsets', () => { - initTimezoneDropdown(); - - const data = $dropdownEl.data('data'); - const formatted = $wrapper.find(tzListSel).text(); - - data.forEach((item) => { - expect(formatted).toContain(formatTimezone(item)); - }); - }); - - describe('when `allowEmpty` property is `false`', () => { - beforeEach(() => { - initTimezoneDropdown(); - }); - - it('will default the timezone to UTC', () => { - const tz = $inputEl.val(); - - expect(tz).toBe('Etc/UTC'); - }); - }); - - describe('when `allowEmpty` property is `true`', () => { - beforeEach(() => { - initTimezoneDropdown({ - allowEmpty: true, - }); - }); - - it('will default the value of the input to an empty string', () => { - expect($inputEl.val()).toBe(''); - }); - }); - }); - - describe('without dropdown loaded', () => { - beforeEach(() => { - loadHTMLFixture('pipeline_schedules/edit.html'); - $wrapper = $('.dropdown'); - $inputEl = $('#schedule_cron_timezone'); - $dropdownEl = $('.js-timezone-dropdown'); - }); - - it('will populate the list of UTC offsets after the dropdown is loaded', () => { - expect($wrapper.find(tzListSel).length).toEqual(0); - - initTimezoneDropdown(); - - expect($wrapper.find(tzListSel).length).toEqual($($dropdownEl).data('data').length); - }); - - it('will call a provided handler when a new timezone is selected', () => { - const onSelectTimezone = jest.fn(); - - initTimezoneDropdown({ onSelectTimezone }); - - $wrapper.find(tzListSel).first().trigger('click'); - - expect(onSelectTimezone).toHaveBeenCalled(); - }); - - it('will correctly set the dropdown label if a timezone identifier is set on the inputEl', () => { - $inputEl.val('America/St_Johns'); - - initTimezoneDropdown({ displayFormat: (selectedItem) => formatTimezone(selectedItem) }); - - expect(findDropdownToggleText().html()).toEqual('[UTC - 2.5] Newfoundland'); - }); - - it('will call a provided `displayFormat` handler to format the dropdown value', () => { - const displayFormat = jest.fn(); - - initTimezoneDropdown({ displayFormat }); - - $wrapper.find(tzListSel).first().trigger('click'); - - expect(displayFormat).toHaveBeenCalled(); - }); - }); - }); - describe('formatUtcOffset', () => { it('will convert negative utc offsets in seconds to hours and minutes', () => { expect(formatUtcOffset(-21600)).toEqual('- 6'); |