Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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.js134
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');