1
+ import { render , screen } from "@testing-library/react" ;
2
+ import { AppProviders } from "App" ;
3
+ import { createTestQueryClient } from "testHelpers/renderHelpers" ;
4
+ import { Markdown } from "./Markdown" ;
5
+
6
+ const renderWithProviders = ( children : React . ReactNode ) => {
7
+ return render (
8
+ < AppProviders queryClient = { createTestQueryClient ( ) } >
9
+ { children }
10
+ </ AppProviders >
11
+ ) ;
12
+ } ;
13
+
14
+ describe ( "Markdown" , ( ) => {
15
+ it ( "renders GFM alerts without links correctly" , ( ) => {
16
+ const markdown = `> [!NOTE]
17
+ > Useful information that users should know, even when skimming content.` ;
18
+
19
+ renderWithProviders ( < Markdown > { markdown } </ Markdown > ) ;
20
+
21
+ // Should render as an alert, not a regular blockquote
22
+ const alert = screen . getByRole ( "complementary" ) ;
23
+ expect ( alert ) . toBeInTheDocument ( ) ;
24
+ expect ( alert ) . toHaveTextContent ( "Useful information that users should know, even when skimming content." ) ;
25
+ } ) ;
26
+
27
+ it ( "renders GFM alerts with links correctly" , ( ) => {
28
+ const markdown = `> [!NOTE]
29
+ > This template is centrally managed by CI/CD in the [coder/templates](https://github.com/coder/templates) repository.` ;
30
+
31
+ renderWithProviders ( < Markdown > { markdown } </ Markdown > ) ;
32
+
33
+ // Should render as an alert, not a regular blockquote
34
+ const alert = screen . getByRole ( "complementary" ) ;
35
+ expect ( alert ) . toBeInTheDocument ( ) ;
36
+ // The alert should contain the content (the alert type might be included)
37
+ expect ( alert ) . toHaveTextContent ( / T h i s t e m p l a t e i s c e n t r a l l y m a n a g e d b y C I \/ C D i n t h e .* r e p o s i t o r y / ) ;
38
+
39
+ // Should contain the link
40
+ const link = screen . getByRole ( "link" , { name : / c o d e r \/ t e m p l a t e s / } ) ;
41
+ expect ( link ) . toBeInTheDocument ( ) ;
42
+ expect ( link ) . toHaveAttribute ( "href" , "https://github.com/coder/templates" ) ;
43
+ } ) ;
44
+
45
+ it ( "renders multiple GFM alerts with links correctly" , ( ) => {
46
+ const markdown = `> [!TIP]
47
+ > Check out the [documentation](https://docs.coder.com) for more information.
48
+
49
+ > [!WARNING]
50
+ > This action may affect your [workspace settings](https://coder.com/settings).` ;
51
+
52
+ renderWithProviders ( < Markdown > { markdown } </ Markdown > ) ;
53
+
54
+ // Should render both alerts
55
+ const alerts = screen . getAllByRole ( "complementary" ) ;
56
+ expect ( alerts ) . toHaveLength ( 2 ) ;
57
+
58
+ // Check first alert (TIP)
59
+ expect ( alerts [ 0 ] ) . toHaveTextContent ( / C h e c k o u t t h e .* d o c u m e n t a t i o n .* f o r m o r e i n f o r m a t i o n / ) ;
60
+ const docLink = screen . getByRole ( "link" , { name : / d o c u m e n t a t i o n / } ) ;
61
+ expect ( docLink ) . toHaveAttribute ( "href" , "https://docs.coder.com" ) ;
62
+
63
+ // Check second alert (WARNING)
64
+ expect ( alerts [ 1 ] ) . toHaveTextContent ( / T h i s a c t i o n m a y a f f e c t y o u r .* w o r k s p a c e s e t t i n g s / ) ;
65
+ const settingsLink = screen . getByRole ( "link" , { name : / w o r k s p a c e s e t t i n g s / } ) ;
66
+ expect ( settingsLink ) . toHaveAttribute ( "href" , "https://coder.com/settings" ) ;
67
+ } ) ;
68
+
69
+ it ( "falls back to regular blockquote for invalid alert types" , ( ) => {
70
+ const markdown = `> [!INVALID]
71
+ > This should render as a regular blockquote.` ;
72
+
73
+ renderWithProviders ( < Markdown > { markdown } </ Markdown > ) ;
74
+
75
+ // Should render as a regular blockquote, not an alert
76
+ // Use a more specific selector since blockquote doesn't have an accessible role
77
+ const blockquote = screen . getByText ( / \[ ! I N V A L I D \] .* T h i s s h o u l d r e n d e r a s a r e g u l a r b l o c k q u o t e / ) ;
78
+ expect ( blockquote ) . toBeInTheDocument ( ) ;
79
+ } ) ;
80
+
81
+ it ( "renders regular blockquotes without alert syntax" , ( ) => {
82
+ const markdown = `> This is a regular blockquote without alert syntax.` ;
83
+
84
+ renderWithProviders ( < Markdown > { markdown } </ Markdown > ) ;
85
+
86
+ // Should render as a regular blockquote
87
+ const blockquote = screen . getByText ( "This is a regular blockquote without alert syntax." ) ;
88
+ expect ( blockquote ) . toBeInTheDocument ( ) ;
89
+ } ) ;
90
+ } ) ;
0 commit comments