Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { normalizeNewsContent, normalizeNewsImageUrl } from '@/utils/newsImageUrl';
|
|
|
|
describe('news image URL normalization', () => {
|
|
const origin = 'http://47.111.103.66';
|
|
|
|
it('maps the backend internal host to the public API resource path', () => {
|
|
expect(
|
|
normalizeNewsImageUrl(
|
|
'http://127.0.0.1:9091/profile/upload/2026/07/20/news.png',
|
|
undefined,
|
|
origin,
|
|
),
|
|
).toBe('http://47.111.103.66/api/shihezi/profile/upload/2026/07/20/news.png');
|
|
});
|
|
|
|
it('supports the fileName returned by the upload endpoint', () => {
|
|
expect(normalizeNewsImageUrl(undefined, 'profile/upload/2026/07/20/news.png', origin)).toBe(
|
|
'http://47.111.103.66/api/shihezi/profile/upload/2026/07/20/news.png',
|
|
);
|
|
});
|
|
|
|
it('normalizes existing API-prefixed URLs to an absolute browser URL', () => {
|
|
expect(normalizeNewsImageUrl('/api/shihezi/profile/upload/news.png', undefined, origin)).toBe(
|
|
'http://47.111.103.66/api/shihezi/profile/upload/news.png',
|
|
);
|
|
});
|
|
|
|
it('uses the development proxy prefix in development builds', () => {
|
|
const originalNodeEnv = process.env.NODE_ENV;
|
|
process.env.NODE_ENV = 'development';
|
|
try {
|
|
expect(
|
|
normalizeNewsImageUrl('/profile/upload/news.png', undefined, 'http://localhost:8000'),
|
|
).toBe('http://localhost:8000/api/profile/upload/news.png');
|
|
} finally {
|
|
process.env.NODE_ENV = originalNodeEnv;
|
|
}
|
|
});
|
|
|
|
it('rewrites only image sources in existing rich text', () => {
|
|
expect(
|
|
normalizeNewsContent(
|
|
'<p>正文</p><img src="http://127.0.0.1:9091/profile/upload/news.png"><img src="https://cdn.example.com/news.png">',
|
|
origin,
|
|
),
|
|
).toBe(
|
|
'<p>正文</p><img src="http://47.111.103.66/api/shihezi/profile/upload/news.png"><img src="https://cdn.example.com/news.png">',
|
|
);
|
|
});
|
|
});
|