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

fix(countdown): emit paused #3062

Merged
merged 3 commits into from
May 8, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: update
eiinu committed May 7, 2024
commit e1115cd631740f7d4153aded3ecfc4a8da692639
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mount } from '@vue/test-utils'
import { nextTick, toRefs, reactive } from 'vue'
import { nextTick, ref } from 'vue'
import { Button, Countdown } from '@nutui/nutui'
import { sleep } from '@/packages/utils/unit'

test('endTime props', async () => {
test('Countdown: endTime props', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50
@@ -14,7 +14,7 @@ test('endTime props', async () => {
expect(wrapper.emitted('end')).toBeTruthy()
})

test('format props', async () => {
test('Countdown: format props', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50,
@@ -55,28 +55,19 @@ test('format props', async () => {
expect(wrapper.find('.nut-countdown__content').text() == '000毫秒').toBe(true)
})

test('paused props', async () => {
const wrapper = mount({
components: {
'nut-countdown': Countdown,
'nut-button': Button
},
template: `
<nut-countdown :end-time="endTime" :paused="paused" />
<nut-button @click="toggle">{{ paused ? 'start' : 'stop' }}</nut-button>
`,
setup() {
const state = reactive({
endTime: Date.now() + 1 * 50,
paused: false
})

const toggle = () => {
state.paused = !state.paused
}

return { ...toRefs(state), toggle }
}
test('Countdown: paused props', async () => {
const paused = ref(false)
const endTime = ref(Date.now() + 1 * 50)
const toggle = () => {
paused.value = !paused.value
}
const wrapper = mount(() => {
return (
<>
<Countdown endTime={endTime.value} paused={paused.value} />
<Button onClick={toggle}>{paused.value ? 'start' : 'stop'}</Button>
</>
)
})

const button = wrapper.find('.nut-button')
@@ -88,7 +79,19 @@ test('paused props', async () => {
expect(prevSnapShot === laterShapShot).toBeTruthy()
})

test('should render slot correctly', async () => {
test('Countdown: should render slot correctly', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50
},
slots: {
default: () => 'slot content'
}
})
expect(wrapper.text()).toEqual('slot content')
})

test('Countdown: should render slot correctly', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50