|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Portfolio page', () => { |
| 4 | + test('has expected main heading', async ({ page }) => { |
| 5 | + await page.goto('/portfolio'); |
| 6 | + await expect(page.getByRole('heading', { level: 1, name: 'Portfolio!' })).toBeVisible(); |
| 7 | + }); |
| 8 | + |
| 9 | + test('header/footer links hover: color becomes shellYellow', async ({ page }) => { |
| 10 | + await page.goto('/portfolio'); |
| 11 | + |
| 12 | + const shellYellow = await page.evaluate(() => { |
| 13 | + const probe = document.createElement('div'); |
| 14 | + probe.style.color = 'var(--shellYellow)'; |
| 15 | + document.body.appendChild(probe); |
| 16 | + const color = getComputedStyle(probe).color; |
| 17 | + probe.remove(); |
| 18 | + return color; |
| 19 | + }); |
| 20 | + |
| 21 | + const areas = [ |
| 22 | + 'header[aria-label="header navigation"]', |
| 23 | + 'footer nav[aria-label="footer navigation"]', |
| 24 | + ]; |
| 25 | + |
| 26 | + for (const area of areas) { |
| 27 | + const nav = page.locator(area); |
| 28 | + await expect(nav).toBeVisible(); |
| 29 | + |
| 30 | + const link = nav.getByRole('link', { name: 'Portfolio', exact: true }); |
| 31 | + await expect(link).toBeVisible(); |
| 32 | + |
| 33 | + const before = await link.evaluate((el) => getComputedStyle(el as Element).color); |
| 34 | + await link.hover(); |
| 35 | + const after = await link.evaluate((el) => getComputedStyle(el as Element).color); |
| 36 | + |
| 37 | + expect(after).toBe(shellYellow); |
| 38 | + expect(after).not.toBe(before); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + test('current page (Portfolio) link is active in header and footer', async ({ page }) => { |
| 43 | + await page.goto('/portfolio'); |
| 44 | + const areas = [ |
| 45 | + 'header[aria-label="header navigation"]', |
| 46 | + 'footer nav[aria-label="footer navigation"]', |
| 47 | + ]; |
| 48 | + for (const area of areas) { |
| 49 | + const nav = page.locator(area); |
| 50 | + const portfolioLink = nav.getByRole('link', { name: 'Portfolio', exact: true }); |
| 51 | + await expect(portfolioLink).toBeVisible(); |
| 52 | + const isActive = await portfolioLink.evaluate((el) => (el as Element).classList.contains('active')); |
| 53 | + expect(isActive).toBeTruthy(); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + test('tabs render and can switch between Personal and Professional', async ({ page }) => { |
| 58 | + await page.goto('/portfolio'); |
| 59 | + |
| 60 | + // Prefer role-based tab selection; fall back to data attribute if role is not present |
| 61 | + const personalTab = page.getByRole('tab', { name: 'Personal' }).or(page.locator('[data-tabs-trigger]', { hasText: 'Personal' })); |
| 62 | + const professionalTab = page.getByRole('tab', { name: 'Professional' }).or(page.locator('[data-tabs-trigger]', { hasText: 'Professional' })); |
| 63 | + |
| 64 | + await expect(personalTab).toBeVisible(); |
| 65 | + await expect(professionalTab).toBeVisible(); |
| 66 | + |
| 67 | + // Personal content visible by default (card heading exists) |
| 68 | + const personalCardHeading = page.locator('.portfolio-picture h2', { hasText: 'Personal Website' }).first(); |
| 69 | + await expect(personalCardHeading).toBeVisible(); |
| 70 | + |
| 71 | + // Switch to Professional |
| 72 | + await professionalTab.click(); |
| 73 | + |
| 74 | + // Professional content appears, personal may hide |
| 75 | + const professionalCardHeading = page.locator('.portfolio-picture h2', { hasText: 'Mark Shellnut Architect' }).first(); |
| 76 | + await expect(professionalCardHeading).toBeVisible(); |
| 77 | + }); |
| 78 | + |
| 79 | + test('personal tab: key cards, images, and external links are accessible', async ({ page }) => { |
| 80 | + await page.goto('/portfolio'); |
| 81 | + |
| 82 | + // Ensure on Personal tab |
| 83 | + const personalTab = page.getByRole('tab', { name: 'Personal' }).or(page.locator('[data-tabs-trigger]', { hasText: 'Personal' })); |
| 84 | + await personalTab.click(); |
| 85 | + |
| 86 | + // Headings (scoped to portfolio cards to avoid strict-mode conflicts) |
| 87 | + await expect(page.locator('.portfolio-picture h2', { hasText: 'Personal Website' }).first()).toBeVisible(); |
| 88 | + await expect(page.locator('.portfolio-picture h2', { hasText: 'Wedding Website' }).first()).toBeVisible(); |
| 89 | + await expect(page.locator('.portfolio-picture h2', { hasText: 'Old Personal Website' }).first()).toBeVisible(); |
| 90 | + |
| 91 | + // Images by alt text |
| 92 | + await expect(page.getByAltText("Picture of Bradley Shellnut's Personal Website")).toBeVisible(); |
| 93 | + await expect(page.getByAltText('Picture of NextJS Wedding Website')).toBeVisible(); |
| 94 | + await expect(page.getByAltText('Home Page of the old bradleyshellnut.com website')).toBeVisible(); |
| 95 | + |
| 96 | + // External links (use visible link names) |
| 97 | + await expect(page.getByRole('link', { name: /GitHub repository/i }).first()).toBeVisible(); |
| 98 | + }); |
| 99 | + |
| 100 | + test('professional tab: card renders with external link', async ({ page }) => { |
| 101 | + await page.goto('/portfolio'); |
| 102 | + |
| 103 | + const professionalTab = page.getByRole('tab', { name: 'Professional' }).or(page.locator('[data-tabs-trigger]', { hasText: 'Professional' })); |
| 104 | + await professionalTab.click(); |
| 105 | + |
| 106 | + const professionalCard = page |
| 107 | + .locator('.portfolio') |
| 108 | + .filter({ has: page.locator('.portfolio-picture h2', { hasText: 'Mark Shellnut Architect' }) }) |
| 109 | + .first(); |
| 110 | + |
| 111 | + await expect(professionalCard).toBeVisible(); |
| 112 | + // Accessible name derived from aria-label in ExternalLink.svelte |
| 113 | + await expect( |
| 114 | + professionalCard.getByRole('link', { name: /Open\s+View Mark Shellnut Architect\s+externally/i }) |
| 115 | + ).toBeVisible(); |
| 116 | + }); |
| 117 | + |
| 118 | + // Mirror header link presence from other pages |
| 119 | + test('header navigation shows expected links', async ({ page }) => { |
| 120 | + await page.goto('/portfolio'); |
| 121 | + const headerNav = page.locator('header[aria-label="header navigation"]'); |
| 122 | + await expect(headerNav).toBeVisible(); |
| 123 | + await expect(headerNav.getByRole('link', { name: 'Home', exact: true })).toBeVisible(); |
| 124 | + await expect(headerNav.getByRole('link', { name: 'About', exact: true })).toBeVisible(); |
| 125 | + await expect(headerNav.getByRole('link', { name: 'Portfolio', exact: true })).toBeVisible(); |
| 126 | + await expect(headerNav.getByRole('link', { name: 'Uses', exact: true })).toBeVisible(); |
| 127 | + }); |
| 128 | + |
| 129 | + // Mirror navigation flow via header (starting on /portfolio) |
| 130 | + test('header navigation links go to correct routes (from /portfolio)', async ({ page }) => { |
| 131 | + await page.goto('/portfolio'); |
| 132 | + const headerNav = page.locator('header[aria-label="header navigation"]'); |
| 133 | + |
| 134 | + await headerNav.getByRole('link', { name: 'About', exact: true }).click(); |
| 135 | + await expect(page).toHaveURL(/\/about\/?$/); |
| 136 | + |
| 137 | + await headerNav.getByRole('link', { name: 'Uses', exact: true }).click(); |
| 138 | + await expect(page).toHaveURL(/\/uses\/?$/); |
| 139 | + |
| 140 | + await headerNav.getByRole('link', { name: 'Home', exact: true }).click(); |
| 141 | + await expect(page).toHaveURL(/\/?$/); |
| 142 | + |
| 143 | + await headerNav.getByRole('link', { name: 'Portfolio', exact: true }).click(); |
| 144 | + await expect(page).toHaveURL(/\/portfolio\/?$/); |
| 145 | + }); |
| 146 | + |
| 147 | + // Mirror footer link presence from other pages |
| 148 | + test('footer shows expected links', async ({ page }) => { |
| 149 | + await page.goto('/portfolio'); |
| 150 | + const footerNav = page.getByRole('navigation', { name: 'footer navigation' }); |
| 151 | + await expect(footerNav).toBeVisible(); |
| 152 | + await expect(footerNav.getByRole('link', { name: 'Home', exact: true })).toBeVisible(); |
| 153 | + await expect(footerNav.getByRole('link', { name: 'About', exact: true })).toBeVisible(); |
| 154 | + await expect(footerNav.getByRole('link', { name: 'Portfolio', exact: true })).toBeVisible(); |
| 155 | + await expect(footerNav.getByRole('link', { name: 'Uses', exact: true })).toBeVisible(); |
| 156 | + await expect(footerNav.getByRole('link', { name: 'Privacy', exact: true })).toBeVisible(); |
| 157 | + await expect(footerNav.getByRole('link', { name: 'Favorite Articles', exact: true })).toBeVisible(); |
| 158 | + }); |
| 159 | + |
| 160 | + // Mirror navigation via footer (starting on /portfolio) |
| 161 | + test('footer navigation links go to correct routes (from /portfolio)', async ({ page }) => { |
| 162 | + await page.goto('/portfolio'); |
| 163 | + const footerNav = page.getByRole('navigation', { name: 'footer navigation' }); |
| 164 | + |
| 165 | + await footerNav.getByRole('link', { name: 'Privacy', exact: true }).scrollIntoViewIfNeeded(); |
| 166 | + await footerNav.getByRole('link', { name: 'Privacy', exact: true }).click(); |
| 167 | + await expect(page).toHaveURL(/\/privacy\/?$/); |
| 168 | + |
| 169 | + // Favorite Articles may route to /articles or /articles/1 |
| 170 | + const fav = footerNav.getByRole('link', { name: 'Favorite Articles', exact: true }); |
| 171 | + await fav.scrollIntoViewIfNeeded(); |
| 172 | + const href = await fav.getAttribute('href'); |
| 173 | + expect(href).toBeTruthy(); |
| 174 | + if (href) { |
| 175 | + expect(href).toMatch(/\/articles(\/\d+)?\/?$/); |
| 176 | + await page.goto(href); |
| 177 | + await expect(page).toHaveURL(/\/articles(\/\d+)?\/?$/, { timeout: 15000 }); |
| 178 | + } |
| 179 | + |
| 180 | + await footerNav.getByRole('link', { name: 'About', exact: true }).scrollIntoViewIfNeeded(); |
| 181 | + await footerNav.getByRole('link', { name: 'About', exact: true }).click(); |
| 182 | + await expect(page).toHaveURL(/\/about\/?$/); |
| 183 | + |
| 184 | + await footerNav.getByRole('link', { name: 'Home', exact: true }).scrollIntoViewIfNeeded(); |
| 185 | + await footerNav.getByRole('link', { name: 'Home', exact: true }).click(); |
| 186 | + await expect(page).toHaveURL(/\/?$/); |
| 187 | + }); |
| 188 | +}); |
0 commit comments