|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { mount } from '@vue/test-utils' |
| 7 | +import { describe, expect, it } from 'vitest' |
| 8 | +import { defineComponent } from 'vue' |
| 9 | +import NcAppNavigationSearch from '../../../../src/components/NcAppNavigationSearch/NcAppNavigationSearch.vue' |
| 10 | + |
| 11 | +function findClearButton(wrapper) { |
| 12 | + return wrapper.find('button[aria-label="Clear search"]') |
| 13 | +} |
| 14 | +function mountWrapped(value = '') { |
| 15 | + return mount(defineComponent({ |
| 16 | + components: { |
| 17 | + NcAppNavigationSearch, |
| 18 | + }, |
| 19 | + data() { |
| 20 | + return { |
| 21 | + value, |
| 22 | + } |
| 23 | + }, |
| 24 | + template: '<NcAppNavigationSearch v-model="value" />', |
| 25 | + })) |
| 26 | +} |
| 27 | + |
| 28 | +describe('NcAppNavigationSearch', () => { |
| 29 | + it('does not show the clear button for an empty search', () => { |
| 30 | + const wrapper = mountWrapped() |
| 31 | + |
| 32 | + expect(findClearButton(wrapper).exists()).toBe(false) |
| 33 | + }) |
| 34 | + |
| 35 | + it('only shows the clear button once the search has content', async () => { |
| 36 | + const wrapper = mountWrapped() |
| 37 | + |
| 38 | + await wrapper.get('input').setValue('a') |
| 39 | + |
| 40 | + expect(findClearButton(wrapper).exists()).toBe(true) |
| 41 | + }) |
| 42 | + |
| 43 | + it('hides the clear button again after clearing the search', async () => { |
| 44 | + const wrapper = mountWrapped('test') |
| 45 | + |
| 46 | + await findClearButton(wrapper).trigger('click') |
| 47 | + |
| 48 | + expect(findClearButton(wrapper).exists()).toBe(false) |
| 49 | + }) |
| 50 | +}) |
0 commit comments