diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js')
-rw-r--r-- | spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js b/spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js new file mode 100644 index 00000000000..3fb8214606c --- /dev/null +++ b/spec/frontend/sidebar/components/subscriptions/subscriptions_dropdown_spec.js @@ -0,0 +1,76 @@ +import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import SubscriptionsDropdown from '~/sidebar/components/subscriptions/subscriptions_dropdown.vue'; +import { subscriptionsDropdownOptions } from '~/sidebar/constants'; + +describe('SubscriptionsDropdown component', () => { + let wrapper; + + const findDropdown = () => wrapper.findComponent(GlDropdown); + const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem); + const findHiddenInput = () => wrapper.find('input'); + + function createComponent() { + wrapper = shallowMount(SubscriptionsDropdown); + } + + afterEach(() => { + wrapper.destroy(); + }); + + describe('with no value selected', () => { + beforeEach(() => { + createComponent(); + }); + + it('hidden input value is undefined', () => { + expect(findHiddenInput().attributes('value')).toBeUndefined(); + }); + + it('renders default text', () => { + expect(findDropdown().props('text')).toBe(SubscriptionsDropdown.i18n.defaultDropdownText); + }); + + 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', () => { + beforeEach(() => { + createComponent(); + findAllDropdownItems().at(0).vm.$emit('click'); + }); + + it('updates value of the hidden input', () => { + expect(findHiddenInput().attributes('value')).toBe(subscriptionsDropdownOptions[0].value); + }); + + it('updates the dropdown text prop', () => { + expect(findDropdown().props('text')).toBe(subscriptionsDropdownOptions[0].text); + }); + + 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 () => { + findAllDropdownItems().at(0).vm.$emit('click'); + await nextTick(); + const dropdownItems = findAllDropdownItems(); + + expect(dropdownItems.at(0).props('isChecked')).toBe(false); + expect(dropdownItems.at(1).props('isChecked')).toBe(false); + expect(findDropdown().props('text')).toBe(SubscriptionsDropdown.i18n.defaultDropdownText); + }); + }); + }); +}); |