MarkdownContent.stories.svelte 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <script module lang="ts">
  2. import { defineMeta } from '@storybook/addon-svelte-csf';
  3. import { MarkdownContent } from '$lib/components/app';
  4. import { AI_TUTORIAL_MD } from './fixtures/ai-tutorial.js';
  5. import { API_DOCS_MD } from './fixtures/api-docs.js';
  6. import { BLOG_POST_MD } from './fixtures/blog-post.js';
  7. import { DATA_ANALYSIS_MD } from './fixtures/data-analysis.js';
  8. import { README_MD } from './fixtures/readme.js';
  9. import { MATH_FORMULAS_MD } from './fixtures/math-formulas.js';
  10. import { EMPTY_MD } from './fixtures/empty.js';
  11. const { Story } = defineMeta({
  12. title: 'Components/MarkdownContent',
  13. component: MarkdownContent,
  14. parameters: {
  15. layout: 'centered'
  16. }
  17. });
  18. </script>
  19. <Story name="Empty" args={{ content: EMPTY_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }} />
  20. <Story
  21. name="AI Tutorial"
  22. args={{ content: AI_TUTORIAL_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  23. />
  24. <Story
  25. name="API Documentation"
  26. args={{ content: API_DOCS_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  27. />
  28. <Story
  29. name="Technical Blog"
  30. args={{ content: BLOG_POST_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  31. />
  32. <Story
  33. name="Data Analysis"
  34. args={{ content: DATA_ANALYSIS_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  35. />
  36. <Story
  37. name="README file"
  38. args={{ content: README_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  39. />
  40. <Story
  41. name="Math Formulas"
  42. args={{ content: MATH_FORMULAS_MD, class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
  43. />
  44. <Story
  45. name="URL Links"
  46. args={{
  47. content: `# URL Links Test
  48. Here are some example URLs that should open in new tabs:
  49. - [Hugging Face Homepage](https://huggingface.co)
  50. - [GitHub Repository](https://github.com/ggml-org/llama.cpp)
  51. - [OpenAI Website](https://openai.com)
  52. - [Google Search](https://www.google.com)
  53. You can also test inline links like https://example.com or https://docs.python.org.
  54. All links should have \`target="_blank"\` and \`rel="noopener noreferrer"\` attributes for security.`,
  55. class: 'max-w-[56rem] w-[calc(100vw-2rem)]'
  56. }}
  57. play={async ({ canvasElement }) => {
  58. const { expect } = await import('storybook/internal/test');
  59. // Wait for component to render
  60. await new Promise(resolve => setTimeout(resolve, 100));
  61. // Find all links in the rendered content
  62. const links = canvasElement.querySelectorAll('a[href]');
  63. // Test that we have the expected number of links
  64. expect(links.length).toBeGreaterThan(0);
  65. // Test each link for proper attributes
  66. links.forEach((link) => {
  67. const href = link.getAttribute('href');
  68. // Test that external links have proper security attributes
  69. if (href && (href.startsWith('http://') || href.startsWith('https://'))) {
  70. expect(link.getAttribute('target')).toBe('_blank');
  71. expect(link.getAttribute('rel')).toBe('noopener noreferrer');
  72. }
  73. });
  74. // Test specific links exist
  75. const hugginFaceLink = Array.from(links).find(link =>
  76. link.getAttribute('href') === 'https://huggingface.co'
  77. );
  78. expect(hugginFaceLink).toBeTruthy();
  79. expect(hugginFaceLink?.textContent).toBe('Hugging Face Homepage');
  80. const githubLink = Array.from(links).find(link =>
  81. link.getAttribute('href') === 'https://github.com/ggml-org/llama.cpp'
  82. );
  83. expect(githubLink).toBeTruthy();
  84. expect(githubLink?.textContent).toBe('GitHub Repository');
  85. const openaiLink = Array.from(links).find(link =>
  86. link.getAttribute('href') === 'https://openai.com'
  87. );
  88. expect(openaiLink).toBeTruthy();
  89. expect(openaiLink?.textContent).toBe('OpenAI Website');
  90. const googleLink = Array.from(links).find(link =>
  91. link.getAttribute('href') === 'https://www.google.com'
  92. );
  93. expect(googleLink).toBeTruthy();
  94. expect(googleLink?.textContent).toBe('Google Search');
  95. // Test inline links (auto-linked URLs)
  96. const exampleLink = Array.from(links).find(link =>
  97. link.getAttribute('href') === 'https://example.com'
  98. );
  99. expect(exampleLink).toBeTruthy();
  100. const pythonDocsLink = Array.from(links).find(link =>
  101. link.getAttribute('href') === 'https://docs.python.org'
  102. );
  103. expect(pythonDocsLink).toBeTruthy();
  104. console.log(`✅ URL Links test passed - Found ${links.length} links with proper attributes`);
  105. }}
  106. />