1+ const { test, expect } = require ( '@playwright/test' ) ;
2+
3+ test . describe ( 'Navigation Links Tests' , ( ) => {
4+ test . beforeEach ( async ( { page } ) => {
5+ await page . goto ( '/' ) ;
6+ } ) ;
7+
8+ test ( 'header navigation links work correctly' , async ( { page } ) => {
9+ // Test GitHub link in header
10+ const githubLink = page . locator ( 'nav[aria-label="Main"] a:has-text("GitHub")' ) ;
11+ await expect ( githubLink ) . toBeVisible ( ) ;
12+ await expect ( githubLink ) . toHaveAttribute ( 'href' , 'https://github.com/console-table-printer/console-table-printer' ) ;
13+ await expect ( githubLink ) . toHaveAttribute ( 'target' , '_blank' ) ;
14+ await expect ( githubLink ) . toHaveAttribute ( 'rel' , 'noopener noreferrer' ) ;
15+
16+ // Test NPM link in header
17+ const npmLink = page . locator ( 'nav[aria-label="Main"] a:has-text("npmjs")' ) ;
18+ await expect ( npmLink ) . toBeVisible ( ) ;
19+ await expect ( npmLink ) . toHaveAttribute ( 'href' , 'https://www.npmjs.com/package/console-table-printer' ) ;
20+ await expect ( npmLink ) . toHaveAttribute ( 'target' , '_blank' ) ;
21+ await expect ( npmLink ) . toHaveAttribute ( 'rel' , 'noopener noreferrer' ) ;
22+ } ) ;
23+
24+ test ( 'footer links work correctly' , async ( { page } ) => {
25+ // Test Learn section links
26+ const quickStartLink = page . locator ( 'footer a:has-text("Quick Start")' ) . first ( ) ;
27+ await expect ( quickStartLink ) . toBeVisible ( ) ;
28+ await expect ( quickStartLink ) . toHaveAttribute ( 'href' , '/docs' ) ;
29+
30+ const cliLink = page . locator ( 'footer a:has-text("Getting Started With CLI")' ) . first ( ) ;
31+ await expect ( cliLink ) . toBeVisible ( ) ;
32+ await expect ( cliLink ) . toHaveAttribute ( 'href' , '/docs/doc-cli-install-quick-start' ) ;
33+
34+ // Test Decorate section links
35+ const colorLink = page . locator ( 'footer a:has-text("Color")' ) . first ( ) ;
36+ await expect ( colorLink ) . toBeVisible ( ) ;
37+ await expect ( colorLink ) . toHaveAttribute ( 'href' , '/docs/doc-color' ) ;
38+
39+ const borderLink = page . locator ( 'footer a:has-text("Border")' ) . first ( ) ;
40+ await expect ( borderLink ) . toBeVisible ( ) ;
41+ await expect ( borderLink ) . toHaveAttribute ( 'href' , '/docs/doc-border-design' ) ;
42+
43+ const alignmentLink = page . locator ( 'footer a:has-text("Alignment")' ) . first ( ) ;
44+ await expect ( alignmentLink ) . toBeVisible ( ) ;
45+ await expect ( alignmentLink ) . toHaveAttribute ( 'href' , '/docs/doc-alignment' ) ;
46+ } ) ;
47+
48+ test ( 'external links in footer work correctly' , async ( { page } ) => {
49+ // Test GitHub link in footer
50+ const githubLink = page . locator ( 'footer a:has-text("GitHub")' ) . first ( ) ;
51+ await expect ( githubLink ) . toBeVisible ( ) ;
52+ await expect ( githubLink ) . toHaveAttribute ( 'href' , 'https://github.com/console-table-printer/console-table-printer' ) ;
53+ await expect ( githubLink ) . toHaveAttribute ( 'target' , '_blank' ) ;
54+ await expect ( githubLink ) . toHaveAttribute ( 'rel' , 'noopener noreferrer' ) ;
55+
56+ // Test NPM link in footer
57+ const npmLink = page . locator ( 'footer a:has-text("Npmjs")' ) . first ( ) ;
58+ await expect ( npmLink ) . toBeVisible ( ) ;
59+ await expect ( npmLink ) . toHaveAttribute ( 'href' , 'https://www.npmjs.com/package/console-table-printer' ) ;
60+ await expect ( npmLink ) . toHaveAttribute ( 'target' , '_blank' ) ;
61+ await expect ( npmLink ) . toHaveAttribute ( 'rel' , 'noopener noreferrer' ) ;
62+ } ) ;
63+
64+ test ( 'announcement bar link works correctly' , async ( { page } ) => {
65+ // Test GitHub star link in announcement bar
66+ const announcementLink = page . locator ( 'div[role="banner"] a[href="https://github.com/console-table-printer/console-table-printer"]' ) ;
67+ await expect ( announcementLink ) . toBeVisible ( ) ;
68+ await expect ( announcementLink ) . toHaveAttribute ( 'target' , '_blank' ) ;
69+ await expect ( announcementLink ) . toHaveAttribute ( 'rel' , 'noopener noreferrer' ) ;
70+ } ) ;
71+ } ) ;
72+
73+ test . describe ( 'Documentation Page Navigation' , ( ) => {
74+ test ( 'sidebar navigation links work correctly' , async ( { page } ) => {
75+ // Go to docs page
76+ await page . goto ( '/' ) ;
77+ await page . locator ( 'a:has-text("GET STARTED")' ) . click ( ) ;
78+
79+ // Define the sidebar links to test
80+ const sidebarLinks = [
81+ { text : "Install and Quick start" , url : "/docs/" } ,
82+ { text : "Create Table Instance" , url : "/docs/doc-table-instance-creation" } ,
83+ { text : "Adding Rows" , url : "/docs/doc-adding-rows" } ,
84+ { text : "Row Dividers" , url : "/docs/doc-row-divider" } ,
85+ { text : "Coloring" , url : "/docs/doc-color" } ,
86+ { text : "Sort and Filter" , url : "/docs/doc-sort-filter" } ,
87+ { text : "Alignment" , url : "/docs/doc-alignment" } ,
88+ { text : "Enable and Disable Columns" , url : "/docs/doc-enable-disable-col" } ,
89+ { text : "Calculated Columns" , url : "/docs/doc-computed-function" } ,
90+ { text : "Special Chars and emojis" , url : "/docs/doc-emojis-special-chars" } ,
91+ { text : "Typescript" , url : "/docs/doc-typescript" }
92+ ] ;
93+
94+ // Test each sidebar link
95+ for ( const link of sidebarLinks ) {
96+ // Find and click the link
97+ await page . locator ( `nav.menu a:has-text("${ link . text } ")` ) . first ( ) . click ( ) ;
98+
99+ // Check that the URL includes the expected path
100+ await expect ( page ) . toHaveURL ( new RegExp ( link . url ) ) ;
101+
102+ // Verify page content is loaded
103+ await expect ( page . locator ( 'main' ) ) . toBeVisible ( ) ;
104+
105+ // Additional checks for Special Chars and emojis page
106+ if ( link . text === "Special Chars and emojis" ) {
107+ // Verify both sections are present using heading elements
108+ await expect ( page . locator ( 'h2:has-text("Special chars")' ) ) . toBeVisible ( ) ;
109+ await expect ( page . locator ( 'h2:has-text("Newlines in cells")' ) ) . toBeVisible ( ) ;
110+
111+ // Verify code examples - use count greater than 1
112+ const codeBlocks = await page . locator ( 'pre code' ) . count ( ) ;
113+ expect ( codeBlocks ) . toBeGreaterThan ( 1 ) ;
114+
115+ // Verify screenshots - use count greater than 0
116+ const screenshots = await page . locator ( 'img[alt="Screenshot"]' ) . count ( ) ;
117+ expect ( screenshots ) . toBeGreaterThan ( 0 ) ;
118+ }
119+ }
120+ } ) ;
121+ } ) ;
0 commit comments