feat: Add some more tests
This commit is contained in:
1 parent
08fce6f023
commit
fc240bbae6
3 files changed
+63
-4
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { tick } from 'svelte'
|
||||
import FormattedNumber from '../src/lib/components/util/FormattedNumber.svelte'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('FormattedNumber.svelte', () => {
|
||||
let host = document.createElement('div')
|
||||
host.setAttribute('id', 'host')
|
||||
document.body.appendChild(host)
|
||||
|
||||
it('mounts', () => {
|
||||
const instance = new FormattedNumber({
|
||||
target: host,
|
||||
props: {
|
||||
number: 1000,
|
||||
},
|
||||
})
|
||||
expect(instance).toBeTruthy()
|
||||
expect(host.innerHTML).toBeTruthy()
|
||||
})
|
||||
it('formats numbers correctly', async () => {
|
||||
const instance = new FormattedNumber({
|
||||
target: host,
|
||||
props: {
|
||||
number: 1100,
|
||||
},
|
||||
})
|
||||
expect(instance).toBeTruthy()
|
||||
|
||||
expect(host.innerHTML).toContain('1.1K')
|
||||
|
||||
instance.$set({ number: 5000 })
|
||||
await tick()
|
||||
expect(host.innerHTML).toContain('5K')
|
||||
|
||||
instance.$set({ number: 6_320_000 })
|
||||
await tick()
|
||||
expect(host.innerHTML).toContain('6.3M')
|
||||
|
||||
instance.$set({
|
||||
options: {
|
||||
notation: 'standard',
|
||||
},
|
||||
})
|
||||
await tick()
|
||||
expect(host.innerHTML).toContain('6,320,000')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
import { isImage } from '../src/lib/ui/image.js'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('lemmy utilities', () => {
|
||||
it('checks image URLs correctly', () => {
|
||||
expect(isImage(`https://example.com/img.jpg?thumb=28`)).toBeTruthy()
|
||||
expect(isImage(`https://test.dev/file/img.webp?great`)).toBeTruthy()
|
||||
expect(isImage(`https://test.dev/file/img.jpeg?test=false`)).toBeTruthy()
|
||||
expect(isImage(`https://test.dev/file/img.bmp#awesome`)).toBeTruthy()
|
||||
expect(isImage(`https://test.dev/file/img.png#awesome`)).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -6,6 +6,9 @@ describe('RelativeDate.svelte', () => {
|
||||
host.setAttribute('id', 'host')
|
||||
document.body.appendChild(host)
|
||||
|
||||
const testDate = new Date('2023-01-01 00:00:00')
|
||||
const testRelativeTo = new Date('2023-01-01 01:00:00')
|
||||
|
||||
it('mounts', () => {
|
||||
let host = document.createElement('div')
|
||||
const instance = new RelativeDate({
|
||||
@@ -18,12 +21,9 @@ describe('RelativeDate.svelte', () => {
|
||||
expect(instance).toBeTruthy()
|
||||
})
|
||||
it('shows the correct date', () => {
|
||||
const date = new Date('2023-01-01 00:00:00')
|
||||
const relativeTo = new Date('2023-01-01 01:00:00')
|
||||
|
||||
const instance = new RelativeDate({
|
||||
target: host,
|
||||
props: { date: date, relativeTo: relativeTo },
|
||||
props: { date: testDate, relativeTo: testRelativeTo },
|
||||
})
|
||||
|
||||
expect(instance).toBeTruthy()
|
||||
|
||||
Reference in new issue
Block a user