Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(form-details): complete test cases #1740

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion packages/varlet-ui/src/form-details/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
import FormDetails from '..'
import { mount } from '@vue/test-utils'
import { createApp } from 'vue'
import { expect, test } from 'vitest'
import { describe, expect, test } from 'vitest'

test('test form details plugin', () => {
const app = createApp({}).use(FormDetails)
expect(app.component(FormDetails.name)).toBeTruthy()
})

describe('test form details component props', () => {
test('test form details errorMessage', async () => {
const wrapper = mount(FormDetails, {
props: {
errorMessage: 'Initial errorMessage',
},
})

const errorMessageWrapper = wrapper.find('.var-form-details__error-message')
const errorMessageDiv = errorMessageWrapper.find('div')

expect(errorMessageDiv.text()).toBe('Initial errorMessage')

await wrapper.setProps({
errorMessage: 'Updated errorMessage',
})

expect(errorMessageDiv.text()).toBe('Updated errorMessage')

wrapper.unmount()
})

test('test form details extraMessage', async () => {
const wrapper = mount(FormDetails, {
props: {
extraMessage: 'Initial extraMessage',
},
})

const extraMessageWrapper = wrapper.find('.var-form-details__extra-message')
const extraMessageDiv = extraMessageWrapper.find('div')

expect(extraMessageDiv.text()).toBe('Initial extraMessage')

await wrapper.setProps({
extraMessage: 'Updated extraMessage',
})

expect(extraMessageDiv.text()).toBe('Updated extraMessage')

wrapper.unmount()
})
})

describe('test form details component slots', () => {
test('test chip extraMessage slots', () => {
const wrapper = mount(FormDetails, {
slots: {
'extra-message': () => 'This is extra message slot',
},
})

const extraMessageWrapper = wrapper.find('.var-form-details__extra-message')
expect(extraMessageWrapper.text()).toBe('This is extra message slot')

wrapper.unmount()
})
})