debian-mirror-gitlab/spec/frontend/sidebar/components/status/status_dropdown_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
2023-03-04 22:38:38 +05:30
import StatusDropdown from '~/sidebar/components/status/status_dropdown.vue';
import { statusDropdownOptions } 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(StatusDropdown);
2021-09-30 23:02:18 +05:30
}
describe('with no value selected', () => {
beforeEach(() => {
createComponent();
});
it('renders default text', () => {
expect(findDropdown().props('text')).toBe('Select status');
});
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', () => {
const selectItemAtIndex = 0;
beforeEach(async () => {
createComponent();
await findAllDropdownItems().at(selectItemAtIndex).vm.$emit('click');
});
it('updates value of the hidden input', () => {
expect(findHiddenInput().attributes('value')).toBe(
2022-11-25 23:54:43 +05:30
statusDropdownOptions[selectItemAtIndex].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(statusDropdownOptions[selectItemAtIndex].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 () => {
await findAllDropdownItems().at(selectItemAtIndex).vm.$emit('click');
const dropdownItems = findAllDropdownItems();
expect(dropdownItems.at(0).props('isChecked')).toBe(false);
expect(dropdownItems.at(1).props('isChecked')).toBe(false);
expect(findDropdown().props('text')).toBe('Select status');
});
});
});
});