2021-09-30 23:02:18 +05:30
|
|
|
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { nextTick } from 'vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import SubscriptionsDropdown from '~/sidebar/components/subscriptions/subscriptions_dropdown.vue';
|
|
|
|
import { subscriptionsDropdownOptions } from '~/sidebar/constants';
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe('SubscriptionsDropdown component', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findDropdown = () => wrapper.findComponent(GlDropdown);
|
|
|
|
const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
|
|
|
|
const findHiddenInput = () => wrapper.find('input');
|
|
|
|
|
|
|
|
function createComponent() {
|
2022-11-25 23:54:43 +05:30
|
|
|
wrapper = shallowMount(SubscriptionsDropdown);
|
2021-09-30 23:02:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with no value selected', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it('hidden input value is undefined', () => {
|
|
|
|
expect(findHiddenInput().attributes('value')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('renders default text', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(findDropdown().props('text')).toBe(SubscriptionsDropdown.i18n.defaultDropdownText);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders dropdown items with `is-checked` prop set to `false`', () => {
|
|
|
|
const dropdownItems = findAllDropdownItems();
|
|
|
|
|
|
|
|
expect(dropdownItems.at(0).props('isChecked')).toBe(false);
|
|
|
|
expect(dropdownItems.at(1).props('isChecked')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when selecting a value', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
beforeEach(() => {
|
2021-09-30 23:02:18 +05:30
|
|
|
createComponent();
|
2022-11-25 23:54:43 +05:30
|
|
|
findAllDropdownItems().at(0).vm.$emit('click');
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('updates value of the hidden input', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(findHiddenInput().attributes('value')).toBe(subscriptionsDropdownOptions[0].value);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the dropdown text prop', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(findDropdown().props('text')).toBe(subscriptionsDropdownOptions[0].text);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets dropdown item `is-checked` prop to `true`', () => {
|
|
|
|
const dropdownItems = findAllDropdownItems();
|
|
|
|
|
|
|
|
expect(dropdownItems.at(0).props('isChecked')).toBe(true);
|
|
|
|
expect(dropdownItems.at(1).props('isChecked')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when selecting the value that is already selected', () => {
|
|
|
|
it('clears dropdown selection', async () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
findAllDropdownItems().at(0).vm.$emit('click');
|
|
|
|
await nextTick();
|
2021-09-30 23:02:18 +05:30
|
|
|
const dropdownItems = findAllDropdownItems();
|
|
|
|
|
|
|
|
expect(dropdownItems.at(0).props('isChecked')).toBe(false);
|
|
|
|
expect(dropdownItems.at(1).props('isChecked')).toBe(false);
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(findDropdown().props('text')).toBe(SubscriptionsDropdown.i18n.defaultDropdownText);
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|