|
| 1 | +/** @vitest-environment jsdom */ |
| 2 | +import { renderToStaticMarkup } from 'react-dom/server' |
| 3 | +import { describe, expect, it } from 'vitest' |
| 4 | +import { SourceIcon } from '@/app/workspace/[workspaceId]/home/components/message-content/components/source-chip/source-icon' |
| 5 | + |
| 6 | +describe('source hostname branding', () => { |
| 7 | + it.each([ |
| 8 | + 'https://example.slack.com/archives/channel/message', |
| 9 | + 'https://app.slack.com/client/team/channel', |
| 10 | + 'https://SLACK.COM/help', |
| 11 | + 'https://www.github.com/example/project', |
| 12 | + 'https://www.gitlab.com/example/project', |
| 13 | + 'https://www.notion.so/example', |
| 14 | + ])('renders a local brand instead of requesting a favicon for a recognized host: %s', (url) => { |
| 15 | + const container = document.createElement('div') |
| 16 | + container.innerHTML = renderToStaticMarkup(<SourceIcon source={{ url }} />) |
| 17 | + expect(container.querySelector('img')).toBeNull() |
| 18 | + expect(container.querySelector('svg')).not.toBeNull() |
| 19 | + }) |
| 20 | + |
| 21 | + it.each([ |
| 22 | + 'https://notslack.com/channel', |
| 23 | + 'https://slack.com.example.org/channel', |
| 24 | + 'https://slack.com@example.org/channel', |
| 25 | + 'https://example.org/slack.com', |
| 26 | + 'https://example.org/?url=https://example.slack.com', |
| 27 | + ])('retains the actual destination favicon for a lookalike URL: %s', (url) => { |
| 28 | + const container = document.createElement('div') |
| 29 | + container.innerHTML = renderToStaticMarkup(<SourceIcon source={{ url }} />) |
| 30 | + const image = container.querySelector('img') |
| 31 | + expect(image).not.toBeNull() |
| 32 | + expect(new URL(image!.src).searchParams.get('domain')).toBe(new URL(url).hostname) |
| 33 | + }) |
| 34 | +}) |
0 commit comments