-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(select): rendering card slots (#181)
Co-authored-by: JD Solanki <jdsolanki0001@gmail.com>
- Loading branch information
1 parent
7368593
commit 4ba3821
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { objectKeys } from '@antfu/utils' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const filterUsedSlots = computed(() => <const T extends Record<string, any>>(slotsToUse: T): (keyof T)[] => { | ||
const slots = useSlots() | ||
|
||
return objectKeys(slotsToUse).filter(key => slots[key as keyof typeof slots]) as (keyof T)[] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { describe, expect, it } from 'vitest' | ||
import { afterEach, describe, expect, it } from 'vitest' | ||
import { nextTick, ref } from 'vue' | ||
import { ASelect } from '../src' | ||
|
||
describe('Testing ASelect', async () => { | ||
let wrapper: ReturnType<typeof mount<ASelect>> | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = '' | ||
}) | ||
|
||
it('should render', () => { | ||
const options = ref(['banana', 'apple', 'watermelon']) | ||
const wrapper = mount(() => | ||
wrapper = mount(() => | ||
<ASelect options={options.value}></ASelect>, | ||
{ attachTo: 'body' }, | ||
) | ||
expect(wrapper).toBeDefined() | ||
}) | ||
|
||
it('should select default value', async () => { | ||
const options = ref(['banana', 'apple', 'watermelon']) | ||
const modelValue = ref('apple') | ||
const wrapper = mount(() => | ||
wrapper = mount(() => | ||
<ASelect | ||
v-model={modelValue.value} | ||
options={options.value} | ||
></ASelect>, | ||
{ attachTo: 'body' }, | ||
) | ||
await nextTick() | ||
const inputElement = wrapper.find('.a-select-input').element as HTMLInputElement | ||
expect(inputElement.value).toContain('apple') | ||
}) | ||
|
||
it('should render card slots', async () => { | ||
const options = ref(['banana', 'apple', 'watermelon']) | ||
wrapper = mount(ASelect, { | ||
props: { | ||
options: options.value, | ||
}, | ||
slots: { | ||
title: '<div class="title-slot">title</div>', | ||
subtitle: '<div class="subtitle-slot">subtitle</div>', | ||
}, | ||
attachTo: 'body', | ||
}) | ||
await wrapper.find('.a-select-input').trigger('click') | ||
await nextTick() | ||
const titleText = document.querySelector('.title-slot')?.textContent | ||
const subTitleText = document.querySelector('.subtitle-slot')?.textContent | ||
expect(titleText).toBe('title') | ||
expect(subTitleText).toBe('subtitle') | ||
}) | ||
}) |