@@ -69,3 +69,96 @@ test.describe('Sidebar Tests', () => {
69
69
expect ( page . url ( ) ) . toMatch ( / \/ t e s t % 3 E f o o $ / ) ;
70
70
} ) ;
71
71
} ) ;
72
+
73
+ test . describe ( 'Configuration: autoHeader' , ( ) => {
74
+ test ( 'autoHeader=false' , async ( { page } ) => {
75
+ const docsifyInitConfig = {
76
+ config : {
77
+ loadSidebar : '_sidebar.md' ,
78
+ autoHeader : false ,
79
+ } ,
80
+ markdown : {
81
+ sidebar : `
82
+ - [QuickStartAutoHeader](quickstart.md)
83
+ ` ,
84
+ } ,
85
+ routes : {
86
+ '/quickstart.md' : `
87
+ the content of quickstart space
88
+ ## In the main content there is no h1
89
+ ` ,
90
+ } ,
91
+ } ;
92
+
93
+ await docsifyInit ( docsifyInitConfig ) ;
94
+
95
+ await page . click ( 'a[href="#/quickstart"]' ) ;
96
+ expect ( page . url ( ) ) . toMatch ( / \/ q u i c k s t a r t $ / ) ;
97
+ // const element = page.locator('#main');
98
+ // expect(await element.innerText()).toContain(
99
+ // 'In the main content there is no h1',
100
+ // );
101
+ // expect(await element.innerText()).toContain(
102
+ // 'the content of quickstart space',
103
+ // );
104
+ // not heading
105
+ await expect ( page . locator ( '#quickstart' ) ) . toBeHidden ( ) ;
106
+ } ) ;
107
+
108
+ test ( 'autoHeader=true' , async ( { page } ) => {
109
+ const docsifyInitConfig = {
110
+ config : {
111
+ loadSidebar : '_sidebar.md' ,
112
+ autoHeader : true ,
113
+ } ,
114
+ markdown : {
115
+ sidebar : `
116
+ - [QuickStartAutoHeader](quickstart.md )
117
+ ` ,
118
+ } ,
119
+ routes : {
120
+ '/quickstart.md' : `
121
+ the content of quickstart space
122
+ ## In the main content there is no h1
123
+ ` ,
124
+ } ,
125
+ } ;
126
+
127
+ await docsifyInit ( docsifyInitConfig ) ;
128
+
129
+ await page . click ( 'a[href="#/quickstart"]' ) ;
130
+ expect ( page . url ( ) ) . toMatch ( / \/ q u i c k s t a r t $ / ) ;
131
+
132
+ // auto generate default heading id
133
+ const autoHeader = page . locator ( '#quickstartautoheader' ) ;
134
+ expect ( await autoHeader . innerText ( ) ) . toContain ( 'QuickStartAutoHeader' ) ;
135
+ } ) ;
136
+
137
+ test ( 'autoHeader=true and custom headingId' , async ( { page } ) => {
138
+ const docsifyInitConfig = {
139
+ config : {
140
+ loadSidebar : '_sidebar.md' ,
141
+ autoHeader : true ,
142
+ } ,
143
+ markdown : {
144
+ sidebar : `
145
+ - [QuickStartAutoHeader](quickstart.md ":id=quickstartId")
146
+ ` ,
147
+ } ,
148
+ routes : {
149
+ '/quickstart.md' : `
150
+ the content of quickstart space
151
+ ## In the main content there is no h1
152
+ ` ,
153
+ } ,
154
+ } ;
155
+
156
+ await docsifyInit ( docsifyInitConfig ) ;
157
+
158
+ await page . click ( 'a[href="#/quickstart"]' ) ;
159
+ expect ( page . url ( ) ) . toMatch ( / \/ q u i c k s t a r t $ / ) ;
160
+ // auto generate custom heading id
161
+ const autoHeader = page . locator ( '#quickstartId' ) ;
162
+ expect ( await autoHeader . innerText ( ) ) . toContain ( 'QuickStartAutoHeader' ) ;
163
+ } ) ;
164
+ } ) ;
0 commit comments