GeoBrowserModal.stories.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import { useEffect, useState, type ReactNode } from 'react';
  2. import type { Decorator, Meta, StoryObj } from '@storybook/react-vite';
  3. import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
  4. import { expect, within } from 'storybook/test';
  5. import { Button, Space, Typography } from 'antd';
  6. import type { GeoCategory, GeoEntry, GeoFile } from '@/generated/types';
  7. import GeoBrowserModal, { type GeoBrowserModalProps } from './GeoBrowserModal';
  8. type GeoResponder = (query: URLSearchParams) => unknown;
  9. type GeoRoutes = Record<string, GeoResponder>;
  10. const realFetch = window.fetch.bind(window);
  11. let activeRoutes: GeoRoutes = {};
  12. function requestUrl(input: RequestInfo | URL): URL {
  13. if (typeof input === 'string') return new URL(input, window.location.origin);
  14. if (input instanceof URL) return input;
  15. return new URL(input.url, window.location.origin);
  16. }
  17. function geoFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
  18. const url = requestUrl(input);
  19. const responder = activeRoutes[url.pathname];
  20. if (!responder) return realFetch(input, init);
  21. const body = JSON.stringify({ success: true, msg: '', obj: responder(url.searchParams) });
  22. return Promise.resolve(
  23. new Response(body, { status: 200, headers: { 'content-type': 'application/json' } }),
  24. );
  25. }
  26. function activate(routes: GeoRoutes): void {
  27. activeRoutes = routes;
  28. window.fetch = geoFetch;
  29. }
  30. function deactivate(routes: GeoRoutes): void {
  31. if (activeRoutes === routes) activeRoutes = {};
  32. }
  33. function GeoApi({ routes, children }: { routes: GeoRoutes; children: ReactNode }) {
  34. const [client] = useState(() => {
  35. activate(routes);
  36. return new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } });
  37. });
  38. useEffect(() => {
  39. activate(routes);
  40. return () => deactivate(routes);
  41. }, [routes]);
  42. return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
  43. }
  44. const domain = (value: string): GeoEntry => ({ kind: 'domain', value });
  45. const full = (value: string): GeoEntry => ({ kind: 'full', value });
  46. const keyword = (value: string): GeoEntry => ({ kind: 'keyword', value });
  47. const regexp = (value: string): GeoEntry => ({ kind: 'regexp', value });
  48. const cidr = (value: string): GeoEntry => ({ kind: 'cidr', value });
  49. const cross = (names: string[], suffixes: string[]): GeoEntry[] =>
  50. names.flatMap((name) => suffixes.map((suffix) => domain(`${name}.${suffix}`)));
  51. const CC_TLDS = [
  52. 'ae', 'al', 'am', 'at', 'az', 'ba', 'be', 'bg', 'bi', 'bj', 'ca', 'cat', 'cd', 'cf', 'cg', 'ch',
  53. 'ci', 'cl', 'cm', 'co.id', 'co.il', 'co.in', 'co.jp', 'co.ke', 'co.kr', 'co.ma', 'co.nz', 'co.th',
  54. 'co.uk', 'co.uz', 'co.ve', 'co.za', 'com.ar', 'com.au', 'com.bd', 'com.br', 'com.co', 'com.cu',
  55. 'com.eg', 'com.gt', 'com.hk', 'com.mx', 'com.my', 'com.ng', 'com.pe', 'com.ph', 'com.pk',
  56. 'com.sa', 'com.sg', 'com.tr', 'com.tw', 'com.ua', 'com.uy', 'com.vn', 'cz', 'de', 'dj', 'dk',
  57. 'dz', 'ee', 'es', 'fi', 'fr', 'ga', 'ge', 'gl', 'gm', 'gr', 'hn', 'hr', 'ht', 'hu', 'ie', 'iq',
  58. 'is', 'it', 'je', 'jo', 'kg', 'kz', 'la', 'li', 'lk', 'lt', 'lu', 'lv', 'ly', 'md', 'me', 'mg',
  59. 'mk', 'ml', 'mn', 'mu', 'mv', 'mw', 'ne', 'nl', 'no', 'nu', 'pl', 'pt', 'ro', 'rs', 'ru', 'rw',
  60. 'se', 'sh', 'si', 'sk', 'sm', 'sn', 'so', 'sr', 'st', 'td', 'tg', 'tk', 'tl', 'tm', 'tn', 'to',
  61. 'tt', 'vg', 'vu', 'ws',
  62. ];
  63. const AD_HOSTS = [
  64. 'adform', 'adnxs', 'adroll', 'adsrvr', 'amplitude', 'appsflyer', 'bluekai', 'branch',
  65. 'casalemedia', 'criteo', 'flurry', 'moatads', 'mopub', 'openx', 'outbrain', 'pubmatic',
  66. 'quantserve', 'rubiconproject', 'scorecardresearch', 'sharethrough', 'smartadserver', 'taboola',
  67. 'teads', 'yieldmo', 'zemanta',
  68. ];
  69. const CN_BRANDS = [
  70. '58', 'alibaba', 'alipay', 'aliyun', 'baidu', 'bilibili', 'cnblogs', 'csdn', 'ctrip', 'douban',
  71. 'gitee', 'huawei', 'iqiyi', 'jd', 'kuaishou', 'meituan', 'netease', 'pinduoduo', 'qq', 'sina',
  72. 'sohu', 'taobao', 'tencent', 'tmall', 'toutiao', 'weibo', 'xiaomi', 'youku', 'zhihu',
  73. ];
  74. const SITE_ENTRIES: Record<string, GeoEntry[]> = {
  75. amazon: [
  76. domain('amazon.com'), domain('amazonaws.com'), domain('media-amazon.com'),
  77. domain('ssl-images-amazon.com'), domain('primevideo.com'), domain('awsstatic.com'),
  78. domain('cloudfront.net'), full('www.amazon.co.jp'),
  79. ],
  80. apple: [
  81. domain('apple.com'), domain('icloud.com'), domain('cdn-apple.com'), domain('mzstatic.com'),
  82. domain('apple-cloudkit.com'), domain('itunes.com'), domain('me.com'), domain('appstore.com'),
  83. ],
  84. 'category-ads': [
  85. domain('adcolony.com'), domain('applovin.com'), domain('chartboost.com'),
  86. domain('inmobi.com'), domain('unityads.unity3d.com'), keyword('banner-ad'),
  87. ],
  88. 'category-ads-all': [
  89. domain('doubleclick.net'), domain('googleadservices.com'), domain('googlesyndication.com'),
  90. domain('adservice.google.com'), full('ads.yahoo.com'), keyword('adservice'),
  91. keyword('advertising'), regexp('^ad[0-9]{1,3}\\.'), ...cross(AD_HOSTS, ['com', 'net', 'io', 'ru']),
  92. ],
  93. cloudflare: [
  94. domain('cloudflare.com'), domain('cloudflare-dns.com'), domain('cloudflareinsights.com'),
  95. domain('workers.dev'), domain('pages.dev'), domain('cf-ipfs.com'),
  96. ],
  97. cn: [full('www.gov.cn'), keyword('chinanet'), ...cross(CN_BRANDS, ['com', 'cn', 'com.cn'])],
  98. discord: [
  99. domain('discord.com'), domain('discord.gg'), domain('discordapp.com'),
  100. domain('discordapp.net'), domain('discord.media'),
  101. ],
  102. facebook: [
  103. domain('facebook.com'), domain('fbcdn.net'), domain('fb.com'), domain('messenger.com'),
  104. domain('fbsbx.com'), domain('facebook.net'), full('m.facebook.com'),
  105. ],
  106. 'geolocation-!cn': [
  107. keyword('proxy'), regexp('.*\\.onion$'), domain('wikipedia.org'), domain('bbc.com'),
  108. domain('nytimes.com'), domain('reuters.com'), domain('medium.com'), domain('reddit.com'),
  109. ],
  110. 'geolocation-cn': [
  111. domain('gov.cn'), domain('edu.cn'), domain('org.cn'), domain('net.cn'),
  112. ...cross(CN_BRANDS.slice(0, 18), ['cn']),
  113. ],
  114. github: [
  115. domain('github.com'), domain('githubusercontent.com'), domain('githubassets.com'),
  116. domain('github.io'), domain('ghcr.io'), domain('git.io'),
  117. ],
  118. google: [
  119. domain('google.com'), domain('googleapis.com'), domain('gstatic.com'),
  120. domain('googleusercontent.com'), domain('google-analytics.com'), domain('googletagmanager.com'),
  121. domain('ggpht.com'), domain('withgoogle.com'), domain('android.com'), domain('chromium.org'),
  122. domain('abc.xyz'), full('dl.google.com'), ...CC_TLDS.map((tld) => domain(`google.${tld}`)),
  123. ],
  124. instagram: [domain('instagram.com'), domain('cdninstagram.com'), domain('ig.me')],
  125. microsoft: [
  126. domain('microsoft.com'), domain('live.com'), domain('office.com'), domain('office365.com'),
  127. domain('windows.net'), domain('windowsupdate.com'), domain('msn.com'), domain('azure.com'),
  128. domain('sharepoint.com'), domain('skype.com'), domain('bing.com'),
  129. ],
  130. netflix: [
  131. domain('netflix.com'), domain('netflix.net'), domain('nflximg.com'), domain('nflximg.net'),
  132. domain('nflxvideo.net'), domain('nflxso.net'), domain('nflxext.com'), full('fast.com'),
  133. ],
  134. openai: [
  135. domain('openai.com'), domain('chatgpt.com'), domain('oaistatic.com'),
  136. domain('oaiusercontent.com'), domain('sora.com'),
  137. ],
  138. spotify: [
  139. domain('spotify.com'), domain('scdn.co'), domain('spotifycdn.com'), domain('spoti.fi'),
  140. domain('spotifycdn.net'),
  141. ],
  142. steam: [
  143. domain('steampowered.com'), domain('steamcommunity.com'), domain('steamstatic.com'),
  144. domain('steamcontent.com'), domain('valvesoftware.com'),
  145. ],
  146. telegram: [
  147. domain('telegram.org'), domain('telegram.me'), domain('t.me'), domain('telesco.pe'),
  148. domain('tdesktop.com'), domain('telegra.ph'), domain('cdn-telegram.org'),
  149. full('comments.app'), keyword('telegram'),
  150. ],
  151. tiktok: [
  152. domain('tiktok.com'), domain('tiktokcdn.com'), domain('tiktokv.com'),
  153. domain('byteoversea.com'), domain('ibytedtos.com'), domain('musical.ly'),
  154. ],
  155. twitch: [domain('twitch.tv'), domain('ttvnw.net'), domain('jtvnw.net'), domain('twitchcdn.net')],
  156. twitter: [
  157. domain('twitter.com'), domain('x.com'), domain('t.co'), domain('twimg.com'),
  158. domain('periscope.tv'),
  159. ],
  160. whatsapp: [domain('whatsapp.com'), domain('whatsapp.net'), domain('wa.me')],
  161. youtube: [
  162. domain('youtube.com'), domain('youtu.be'), domain('ytimg.com'), domain('googlevideo.com'),
  163. domain('youtube-nocookie.com'), domain('yt.be'),
  164. ],
  165. };
  166. const SITE_ATTRIBUTES: Record<string, string[]> = {
  167. amazon: ['ads'],
  168. apple: ['cn'],
  169. facebook: ['ads'],
  170. google: ['ads', 'cn'],
  171. instagram: ['ads'],
  172. microsoft: ['cn'],
  173. tiktok: ['ads', 'cn'],
  174. twitter: ['ads'],
  175. youtube: ['ads'],
  176. };
  177. const CN_BLOCKS = [
  178. '1.0.1.0/24', '1.0.2.0/23', '1.0.8.0/21', '14.0.12.0/22', '27.0.128.0/21', '36.0.0.0/22',
  179. '39.0.0.0/24', '42.0.0.0/22', '58.14.0.0/15', '59.32.0.0/11', '61.128.0.0/10', '101.16.0.0/12',
  180. '103.1.8.0/22', '106.0.0.0/10', '110.6.0.0/15', '111.0.0.0/10', '112.0.0.0/10', '113.0.0.0/9',
  181. '114.28.0.0/16', '116.0.0.0/9', '117.8.0.0/13', '118.24.0.0/15', '119.0.0.0/9', '120.0.0.0/10',
  182. '121.0.0.0/8', '124.0.0.0/8', '125.32.0.0/11', '139.196.0.0/14', '140.75.0.0/16', '175.0.0.0/12',
  183. '180.76.0.0/16', '182.16.0.0/12', '183.0.0.0/10', '202.0.0.0/12', '203.0.0.0/12', '210.0.0.0/12',
  184. '211.64.0.0/11', '218.0.0.0/9', '219.72.0.0/14', '220.112.0.0/12', '221.0.0.0/9', '222.16.0.0/12',
  185. '2001:250::/35', '2400:3200::/32', '2408:8000::/20',
  186. ];
  187. const CN_EXTRA_BLOCKS = Array.from({ length: 96 }, (_, index) =>
  188. `${39 + Math.floor(index / 16)}.${(index % 16) * 16}.0.0/12`,
  189. );
  190. const IP_ENTRIES: Record<string, GeoEntry[]> = {
  191. cloudflare: [
  192. '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22', '104.16.0.0/13', '104.24.0.0/14',
  193. '108.162.192.0/18', '131.0.72.0/22', '141.101.64.0/18', '162.158.0.0/15', '172.64.0.0/13',
  194. '173.245.48.0/20', '188.114.96.0/20', '190.93.240.0/20', '197.234.240.0/22', '198.41.128.0/17',
  195. '2400:cb00::/32', '2606:4700::/32',
  196. ].map(cidr),
  197. cn: [...CN_BLOCKS, ...CN_EXTRA_BLOCKS].map(cidr),
  198. facebook: [
  199. '31.13.24.0/21', '31.13.64.0/18', '66.220.144.0/20', '69.63.176.0/20', '69.171.224.0/19',
  200. '157.240.0.0/16', '179.60.192.0/22', '185.60.216.0/22', '2a03:2880::/32',
  201. ].map(cidr),
  202. google: [
  203. '8.8.4.0/24', '8.8.8.0/24', '34.64.0.0/10', '35.184.0.0/13', '64.233.160.0/19', '66.102.0.0/20',
  204. '72.14.192.0/18', '74.125.0.0/16', '108.177.8.0/21', '142.250.0.0/15', '172.217.0.0/16',
  205. '216.58.192.0/19', '2404:6800::/32', '2607:f8b0::/32',
  206. ].map(cidr),
  207. ir: [
  208. '2.144.0.0/14', '5.22.0.0/17', '31.2.128.0/17', '37.32.0.0/19', '46.32.0.0/19', '78.38.0.0/15',
  209. '80.191.0.0/16', '85.15.0.0/18', '91.98.0.0/15', '178.22.72.0/21', '185.8.172.0/22',
  210. '188.34.0.0/17', '217.218.0.0/15',
  211. ].map(cidr),
  212. netflix: [
  213. '23.246.0.0/18', '37.77.184.0/21', '45.57.0.0/17', '64.120.128.0/17', '66.197.128.0/17',
  214. '108.175.32.0/20', '185.2.220.0/22', '192.173.64.0/18', '198.38.96.0/19', '198.45.48.0/20',
  215. ].map(cidr),
  216. private: [
  217. '0.0.0.0/8', '10.0.0.0/8', '100.64.0.0/10', '127.0.0.0/8', '169.254.0.0/16', '172.16.0.0/12',
  218. '192.0.0.0/24', '192.0.2.0/24', '192.168.0.0/16', '198.18.0.0/15', '198.51.100.0/24',
  219. '203.0.113.0/24', '224.0.0.0/4', '240.0.0.0/4', '255.255.255.255/32', '::1/128', 'fc00::/7',
  220. 'fe80::/10',
  221. ].map(cidr),
  222. ru: [
  223. '2.60.0.0/14', '5.8.0.0/19', '31.6.0.0/17', '37.9.0.0/19', '46.16.0.0/21', '62.76.0.0/18',
  224. '77.37.128.0/17', '78.24.216.0/21', '79.104.0.0/15', '80.64.128.0/19', '81.16.96.0/19',
  225. '82.140.128.0/18', '85.113.0.0/16', '87.226.0.0/16', '91.77.0.0/16', '93.157.0.0/17',
  226. '94.19.0.0/16', '95.24.0.0/13', '178.176.0.0/13', '188.128.0.0/13', '213.87.0.0/16',
  227. '217.66.152.0/21', '2a00:1148::/32',
  228. ].map(cidr),
  229. telegram: [
  230. '91.108.4.0/22', '91.108.8.0/22', '91.108.12.0/22', '91.108.16.0/22', '91.108.20.0/22',
  231. '91.108.56.0/22', '149.154.160.0/20', '2001:67c:4e8::/48', '2001:b28:f23d::/48',
  232. '2001:b28:f23f::/48',
  233. ].map(cidr),
  234. us: [
  235. '3.0.0.0/9', '12.0.0.0/8', '23.192.0.0/11', '34.192.0.0/10', '50.16.0.0/14', '52.0.0.0/10',
  236. '63.64.0.0/11', '65.0.0.0/10', '68.32.0.0/11', '71.0.0.0/11', '96.0.0.0/9', '128.0.0.0/10',
  237. '199.0.0.0/12', '208.64.0.0/12', '2600:1f00::/24',
  238. ].map(cidr),
  239. };
  240. function categoriesOf(
  241. entries: Record<string, GeoEntry[]>,
  242. attributes: Record<string, string[]> = {},
  243. ): GeoCategory[] {
  244. return Object.keys(entries)
  245. .sort()
  246. .map((code) => ({ code, entries: entries[code].length, attributes: attributes[code] ?? [] }));
  247. }
  248. const SITE_CATEGORIES = categoriesOf(SITE_ENTRIES, SITE_ATTRIBUTES);
  249. const IP_CATEGORIES = categoriesOf(IP_ENTRIES);
  250. const UPDATED_AT = Date.UTC(2026, 6, 24, 3, 12);
  251. const GEOSITE_FILE: GeoFile = {
  252. name: 'geosite.dat',
  253. kind: 'site',
  254. size: 4_812_544,
  255. modifiedAt: UPDATED_AT,
  256. categories: SITE_CATEGORIES.length,
  257. };
  258. const GEOIP_FILE: GeoFile = {
  259. name: 'geoip.dat',
  260. kind: 'ip',
  261. size: 8_694_272,
  262. modifiedAt: UPDATED_AT,
  263. categories: IP_CATEGORIES.length,
  264. };
  265. const DAMAGED_FILE: GeoFile = {
  266. name: 'geosite-custom.dat',
  267. kind: 'site',
  268. size: 262_144,
  269. modifiedAt: Date.UTC(2026, 5, 2, 19, 45),
  270. categories: 0,
  271. error: 'proto: cannot parse invalid wire-format data',
  272. };
  273. const OVERSIZED_FILE: GeoFile = {
  274. name: 'geoip-full.dat',
  275. kind: 'ip',
  276. size: 96_468_992,
  277. modifiedAt: Date.UTC(2026, 6, 20, 8, 5),
  278. categories: 0,
  279. error: 'geodata file is too large to browse',
  280. };
  281. const DATASETS: Record<string, { categories: GeoCategory[]; entries: Record<string, GeoEntry[]> }> = {
  282. 'geosite.dat': { categories: SITE_CATEGORIES, entries: SITE_ENTRIES },
  283. 'geoip.dat': { categories: IP_CATEGORIES, entries: IP_ENTRIES },
  284. };
  285. function routesFor(files: GeoFile[]): GeoRoutes {
  286. return {
  287. '/panel/api/xray/geodata/files': () => files,
  288. '/panel/api/xray/geodata/categories': (query) => {
  289. const dataset = DATASETS[query.get('file') ?? ''];
  290. const needle = (query.get('q') ?? '').trim().toLowerCase();
  291. const items = (dataset?.categories ?? []).filter((category) => category.code.includes(needle));
  292. return { total: items.length, items };
  293. },
  294. '/panel/api/xray/geodata/entries': (query) => {
  295. const dataset = DATASETS[query.get('file') ?? ''];
  296. const needle = (query.get('q') ?? '').trim().toLowerCase();
  297. const matched = (dataset?.entries[query.get('code') ?? ''] ?? []).filter((entry) =>
  298. entry.value.toLowerCase().includes(needle),
  299. );
  300. const offset = Number(query.get('offset') ?? 0);
  301. const limit = Number(query.get('limit') ?? 100);
  302. return { total: matched.length, items: matched.slice(offset, offset + limit) };
  303. },
  304. };
  305. }
  306. function withFiles(files: GeoFile[]): Decorator {
  307. const routes = routesFor(files);
  308. return function GeodataBackend(Story) {
  309. return (
  310. <GeoApi routes={routes}>
  311. <Story />
  312. </GeoApi>
  313. );
  314. };
  315. }
  316. const withDatabases = withFiles([GEOSITE_FILE, GEOIP_FILE]);
  317. function BrowserDemo(props: GeoBrowserModalProps) {
  318. const [open, setOpen] = useState(props.open);
  319. const [value, setValue] = useState(props.value);
  320. useEffect(() => setOpen(props.open), [props.open]);
  321. useEffect(() => setValue(props.value), [props.value]);
  322. return (
  323. <Space direction="vertical" size={12}>
  324. <Space size={8}>
  325. <Button onClick={() => setOpen(true)}>Open geo browser</Button>
  326. <Typography.Text code>{value || 'no rule yet'}</Typography.Text>
  327. </Space>
  328. <GeoBrowserModal
  329. {...props}
  330. open={open}
  331. value={value}
  332. onApply={(next) => {
  333. setValue(next);
  334. setOpen(false);
  335. }}
  336. onClose={() => setOpen(false)}
  337. />
  338. </Space>
  339. );
  340. }
  341. const meta = {
  342. title: 'Geodata/GeoBrowserModal',
  343. component: GeoBrowserModal,
  344. tags: ['autodocs'],
  345. parameters: {
  346. layout: 'padded',
  347. a11y: {
  348. config: {
  349. rules: [{ id: 'color-contrast', enabled: false }],
  350. },
  351. },
  352. docs: {
  353. description: {
  354. component:
  355. 'Browser for the geosite/geoip `.dat` databases Xray resolves `geosite:` and `geoip:` routing tokens against: pick a database, search its categories, tick the ones a rule needs, and preview the domains or CIDRs inside the highlighted category. Applying merges the ticked categories back into the rule string, keeping hand-typed domains untouched. The stories serve `/panel/api/xray/geodata/*` from an in-memory fixture, so search, paging and selection all work without a panel backend.',
  356. },
  357. },
  358. },
  359. args: {
  360. open: true,
  361. kind: 'site',
  362. value: '',
  363. onApply: () => undefined,
  364. onClose: () => undefined,
  365. },
  366. argTypes: {
  367. open: { description: 'Whether the modal is visible.' },
  368. kind: {
  369. description: 'Which database layout the rule targets: `site` for domain rules, `ip` for CIDR rules. Decides the preselected database and the token prefix.',
  370. control: 'inline-radio',
  371. options: ['site', 'ip'],
  372. },
  373. value: {
  374. description: 'Current rule string, comma separated. Tokens that match a category in the opened database come back preselected.',
  375. },
  376. onApply: { description: 'Called with the merged rule string when Apply is pressed.' },
  377. onClose: { description: 'Called when the modal is dismissed.' },
  378. },
  379. render: (args) => <BrowserDemo {...args} />,
  380. } satisfies Meta<typeof GeoBrowserModal>;
  381. export default meta;
  382. type Story = StoryObj<typeof meta>;
  383. export const SiteDatabase: Story = {
  384. decorators: [withDatabases],
  385. args: { kind: 'site', value: 'geosite:google, geosite:telegram, ads.example.com' },
  386. };
  387. export const CategoryPreview: Story = {
  388. decorators: [withDatabases],
  389. args: { kind: 'site', value: 'geosite:google' },
  390. parameters: {
  391. a11y: {
  392. config: {
  393. rules: [
  394. { id: 'color-contrast', enabled: false },
  395. { id: 'scrollable-region-focusable', enabled: false },
  396. ],
  397. },
  398. },
  399. },
  400. play: async ({ canvasElement, userEvent }) => {
  401. const body = within(canvasElement.ownerDocument.body);
  402. await userEvent.type(await body.findByPlaceholderText('Search category'), 'telegram');
  403. await userEvent.click(await body.findByText('telegram'));
  404. await expect(await body.findByText('t.me')).toBeVisible();
  405. },
  406. };
  407. export const IpDatabase: Story = {
  408. decorators: [withDatabases],
  409. args: { kind: 'ip', value: 'geoip:private, 10.0.0.0/8' },
  410. };
  411. export const NoDatabases: Story = {
  412. decorators: [withFiles([])],
  413. args: { kind: 'site', value: 'geosite:google' },
  414. };
  415. export const DamagedDatabase: Story = {
  416. decorators: [withFiles([GEOSITE_FILE, DAMAGED_FILE, OVERSIZED_FILE])],
  417. args: { kind: 'site', value: '' },
  418. };