返回 slidev
tweet.test.ts
根目录 / packages / client / logic / tweet.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { resolveTweetId } from './tweet'
3
4 describe('resolveTweetId', () => {
5 it('keeps the existing id input', () => {
6 expect(resolveTweetId(123, undefined)).toBe('123')
7 expect(resolveTweetId(' 456 ', undefined)).toBe('456')
8 })
9
10 it('prefers id when both inputs are present', () => {
11 expect(resolveTweetId('123', 'https://x.com/slidevjs/status/456')).toBe('123')
12 })
13
14 it.each([
15 'https://x.com/slidevjs/status/123',
16 'https://www.x.com/slidevjs/status/123?s=20',
17 'https://twitter.com/slidevjs/status/123',
18 'https://mobile.twitter.com/slidevjs/status/123/photo/1',
19 'https://x.com/i/web/status/123',
20 ])('extracts an id from %s', (url) => {
21 expect(resolveTweetId(undefined, url)).toBe('123')
22 })
23
24 it.each([
25 'https://example.com/slidevjs/status/123',
26 'https://x.com.example.com/slidevjs/status/123',
27 'https://x.com/slidevjs/status/not-a-number',
28 'javascript:alert(1)',
29 'not a URL',
30 ])('rejects an unsupported source URL: %s', (url) => {
31 expect(resolveTweetId(undefined, url)).toBeUndefined()
32 })
33 })
34
34 lines TYPESCRIPT