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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-28 09:08:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-28 09:08:11 +0300
commitf8184e504b8aa6f77b42583a9fd08daebbdcc8ab (patch)
tree186be898556eda08cb22065731ac0b26ae6f5353 /spec/frontend/vue_shared/components/timezone_dropdown
parent67e7b5a9ba9f88d4495841cb0457a2dbe3afec55 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components/timezone_dropdown')
-rw-r--r--spec/frontend/vue_shared/components/timezone_dropdown/helpers.js6
-rw-r--r--spec/frontend/vue_shared/components/timezone_dropdown/timezone_dropdown_spec.js96
2 files changed, 102 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/timezone_dropdown/helpers.js b/spec/frontend/vue_shared/components/timezone_dropdown/helpers.js
new file mode 100644
index 00000000000..dee4c92add4
--- /dev/null
+++ b/spec/frontend/vue_shared/components/timezone_dropdown/helpers.js
@@ -0,0 +1,6 @@
+import timezoneDataFixture from 'test_fixtures/timezones/short.json';
+
+export { timezoneDataFixture };
+
+export const findTzByName = (identifier = '') =>
+ timezoneDataFixture.find(({ name }) => name.toLowerCase() === identifier.toLowerCase());
diff --git a/spec/frontend/vue_shared/components/timezone_dropdown/timezone_dropdown_spec.js b/spec/frontend/vue_shared/components/timezone_dropdown/timezone_dropdown_spec.js
new file mode 100644
index 00000000000..48f811c8135
--- /dev/null
+++ b/spec/frontend/vue_shared/components/timezone_dropdown/timezone_dropdown_spec.js
@@ -0,0 +1,96 @@
+import { GlDropdownItem, GlDropdown } from '@gitlab/ui';
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
+import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown/timezone_dropdown.vue';
+import { formatTimezone } from '~/lib/utils/datetime_utility';
+import { findTzByName, timezoneDataFixture } from './helpers';
+
+describe('Deploy freeze timezone dropdown', () => {
+ let wrapper;
+ let store;
+
+ const createComponent = (searchTerm, selectedTimezone) => {
+ wrapper = shallowMountExtended(TimezoneDropdown, {
+ store,
+ propsData: {
+ value: selectedTimezone,
+ timezoneData: timezoneDataFixture,
+ },
+ });
+
+ // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
+ // eslint-disable-next-line no-restricted-syntax
+ wrapper.setData({ searchTerm });
+ };
+
+ const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
+ const findDropdownItemByIndex = (index) => wrapper.findAllComponents(GlDropdownItem).at(index);
+ const findDropdown = () => wrapper.findComponent(GlDropdown);
+ const findEmptyResultsItem = () => wrapper.findByTestId('noMatchingResults');
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ describe('No time zones found', () => {
+ beforeEach(() => {
+ createComponent('UTC timezone');
+ });
+
+ it('renders empty results message', () => {
+ expect(findDropdownItemByIndex(0).text()).toBe('No matching results');
+ });
+ });
+
+ describe('Search term is empty', () => {
+ beforeEach(() => {
+ createComponent('');
+ });
+
+ it('renders all timezones when search term is empty', () => {
+ expect(findAllDropdownItems()).toHaveLength(timezoneDataFixture.length);
+ });
+ });
+
+ describe('Time zones found', () => {
+ beforeEach(() => {
+ createComponent('Alaska');
+ });
+
+ it('renders only the time zone searched for', () => {
+ const selectedTz = findTzByName('Alaska');
+ expect(findAllDropdownItems()).toHaveLength(1);
+ expect(findDropdownItemByIndex(0).text()).toBe(formatTimezone(selectedTz));
+ });
+
+ it('should not display empty results message', () => {
+ expect(findEmptyResultsItem().exists()).toBe(false);
+ });
+
+ describe('Custom events', () => {
+ const selectedTz = findTzByName('Alaska');
+
+ it('should emit input if a time zone is clicked', () => {
+ findDropdownItemByIndex(0).vm.$emit('click');
+ expect(wrapper.emitted('input')).toEqual([
+ [
+ {
+ formattedTimezone: formatTimezone(selectedTz),
+ identifier: selectedTz.identifier,
+ },
+ ],
+ ]);
+ });
+ });
+ });
+
+ describe('Selected time zone', () => {
+ beforeEach(() => {
+ createComponent('', 'Alaska');
+ });
+
+ it('renders selected time zone as dropdown label', () => {
+ expect(findDropdown().vm.text).toBe('Alaska');
+ });
+ });
+});