-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,86 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { vi, describe, expect, test } from 'vitest' | ||
import { useProgress } from '.' | ||
|
||
const wait = (time) => | ||
new Promise((resolve) => { | ||
setTimeout(resolve, time) | ||
}) | ||
|
||
describe('useEllipsis', () => { | ||
test('should be defined', () => { | ||
expect(useProgress).toBeDefined() | ||
}) | ||
|
||
test('should increment correctly', () => { | ||
const { progress, increment } = useProgress() | ||
increment() | ||
expect(progress.value).toBe(1) | ||
|
||
increment(101) | ||
expect(progress.value).toBe(100) | ||
}) | ||
|
||
test('should decrement correctly', () => { | ||
const { progress, decrement } = useProgress({ initialValue: 10 }) | ||
|
||
decrement() | ||
expect(progress.value).toBe(9) | ||
|
||
decrement(10) | ||
expect(progress.value).toBe(0) | ||
}) | ||
|
||
test('should progress correctly with maxValue', () => { | ||
const { progress, increment } = useProgress({ maxValue: 1000 }) | ||
|
||
increment() | ||
expect(progress.value).toBe(0.1) | ||
}) | ||
|
||
test('should onChange called after change progress', async () => { | ||
const onChange = vi.fn() | ||
|
||
const { increment } = useProgress({ onChange }) | ||
|
||
await increment() | ||
expect(onChange).toHaveBeenCalledTimes(1) | ||
|
||
await increment(100) | ||
expect(onChange).toHaveBeenCalledTimes(2) | ||
|
||
await increment(100) | ||
expect(onChange).toHaveBeenCalledTimes(2) | ||
}) | ||
|
||
test('should auto increment progress', async () => { | ||
const { progress, startAutoIncrement } = useProgress({ | ||
autoIncrementRules: [{ before: 100, delay: 1, increment: 1 }], | ||
}) | ||
|
||
expect(progress.value).toBe(0) | ||
|
||
startAutoIncrement() | ||
|
||
await wait(200) | ||
expect(progress.value).toBe(99) | ||
}) | ||
|
||
test('should reset progress', async () => { | ||
const { progress, increment, reset } = useProgress() | ||
|
||
increment() | ||
expect(progress.value).toBe(1) | ||
|
||
reset() | ||
expect(progress.value).toBe(0) | ||
}) | ||
|
||
test('should isComplete correctly', async () => { | ||
const { isComplete, increment } = useProgress() | ||
|
||
expect(isComplete.value).toBeFalsy() | ||
|
||
increment(100) | ||
expect(isComplete.value).toBeTruthy() | ||
}) | ||
}) |
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