debian-mirror-gitlab/spec/frontend/deploy_freeze/components/timezone_dropdown_spec.js

102 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
2021-01-03 14:25:43 +05:30
import { GlDropdownItem, GlDropdown } from '@gitlab/ui';
2020-10-24 23:57:45 +05:30
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import createStore from '~/deploy_freeze/store';
2021-01-29 00:20:46 +05:30
import { findTzByName, formatTz, timezoneDataFixture } from '../helpers';
2020-10-24 23:57:45 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Deploy freeze timezone dropdown', () => {
let wrapper;
let store;
2020-11-24 15:15:51 +05:30
2020-10-24 23:57:45 +05:30
const createComponent = (searchTerm, selectedTimezone) => {
store = createStore({
projectId: '8',
timezoneData: timezoneDataFixture,
});
wrapper = shallowMount(TimezoneDropdown, {
store,
localVue,
propsData: {
value: selectedTimezone,
timezoneData: timezoneDataFixture,
},
});
wrapper.setData({ searchTerm });
};
2021-01-03 14:25:43 +05:30
const findAllDropdownItems = () => wrapper.findAll(GlDropdownItem);
const findDropdownItemByIndex = index => wrapper.findAll(GlDropdownItem).at(index);
2020-10-24 23:57:45 +05:30
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', () => {
2020-11-24 15:15:51 +05:30
const selectedTz = findTzByName('Alaska');
2020-10-24 23:57:45 +05:30
expect(findAllDropdownItems()).toHaveLength(1);
2020-11-24 15:15:51 +05:30
expect(findDropdownItemByIndex(0).text()).toBe(formatTz(selectedTz));
2020-10-24 23:57:45 +05:30
});
it('should not display empty results message', () => {
expect(wrapper.find('[data-testid="noMatchingResults"]').exists()).toBe(false);
});
describe('Custom events', () => {
2020-11-24 15:15:51 +05:30
const selectedTz = findTzByName('Alaska');
2020-10-24 23:57:45 +05:30
it('should emit input if a time zone is clicked', () => {
findDropdownItemByIndex(0).vm.$emit('click');
expect(wrapper.emitted('input')).toEqual([
[
{
2020-11-24 15:15:51 +05:30
formattedTimezone: formatTz(selectedTz),
identifier: selectedTz.identifier,
2020-10-24 23:57:45 +05:30
},
],
]);
});
});
});
describe('Selected time zone', () => {
beforeEach(() => {
createComponent('', 'Alaska');
});
it('renders selected time zone as dropdown label', () => {
2020-11-24 15:15:51 +05:30
expect(wrapper.find(GlDropdown).vm.text).toBe('Alaska');
2020-10-24 23:57:45 +05:30
});
});
});