|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { TestHelpers } from '../helpers'; |
| 3 | + |
| 4 | +test.describe('Tag Alignment in Project Cards', () => { |
| 5 | + let helpers: TestHelpers; |
| 6 | + |
| 7 | + test.beforeEach(async ({ page }) => { |
| 8 | + helpers = new TestHelpers(page); |
| 9 | + await page.goto('/projects'); |
| 10 | + await helpers.waitForPageReady(); |
| 11 | + }); |
| 12 | + |
| 13 | + test('tags should be aligned to the right when there are no github/demo links', async ({ page }) => { |
| 14 | + // Find the card for "Example Project Without Links" |
| 15 | + const projectCard = page.locator('.card', { has: page.locator('h1:has-text("Example Project Without Links")') }); |
| 16 | + |
| 17 | + // Verify the card exists |
| 18 | + await expect(projectCard).toBeVisible(); |
| 19 | + |
| 20 | + // Get the card footer |
| 21 | + const cardFooter = projectCard.locator('.card-footer'); |
| 22 | + await expect(cardFooter).toBeVisible(); |
| 23 | + |
| 24 | + // Verify there are no card links (github/demo buttons) |
| 25 | + const cardLinks = cardFooter.locator('.card-links'); |
| 26 | + await expect(cardLinks).not.toBeVisible(); |
| 27 | + |
| 28 | + // Verify there are tags |
| 29 | + const cardTags = cardFooter.locator('.card-tags'); |
| 30 | + await expect(cardTags).toBeVisible(); |
| 31 | + |
| 32 | + const tags = cardTags.locator('.card-tag'); |
| 33 | + const tagCount = await tags.count(); |
| 34 | + expect(tagCount).toBeGreaterThan(0); |
| 35 | + |
| 36 | + // Get the bounding boxes |
| 37 | + const footerBox = await cardFooter.boundingBox(); |
| 38 | + const tagsBox = await cardTags.boundingBox(); |
| 39 | + |
| 40 | + expect(footerBox).toBeTruthy(); |
| 41 | + expect(tagsBox).toBeTruthy(); |
| 42 | + |
| 43 | + if (footerBox && tagsBox) { |
| 44 | + // Tags should be aligned to the right (right edge should be close to footer's right edge) |
| 45 | + const footerRight = footerBox.x + footerBox.width; |
| 46 | + const tagsRight = tagsBox.x + tagsBox.width; |
| 47 | + |
| 48 | + // Allow a small margin for padding (20px is the card padding) |
| 49 | + const rightMargin = footerBox.width * 0.1; // 10% tolerance |
| 50 | + expect(tagsRight).toBeGreaterThan(footerRight - rightMargin); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + test('tags should still be aligned to the right when github/demo links are present', async ({ page }) => { |
| 55 | + // Find a card that has both links and tags (e.g., "Apollo" project) |
| 56 | + const projectCard = page.locator('.card', { has: page.locator('h1:has-text("Apollo")') }); |
| 57 | + |
| 58 | + // Verify the card exists |
| 59 | + await expect(projectCard).toBeVisible(); |
| 60 | + |
| 61 | + // Get the card footer |
| 62 | + const cardFooter = projectCard.locator('.card-footer'); |
| 63 | + await expect(cardFooter).toBeVisible(); |
| 64 | + |
| 65 | + // Verify there are card links |
| 66 | + const cardLinks = cardFooter.locator('.card-links'); |
| 67 | + await expect(cardLinks).toBeVisible(); |
| 68 | + |
| 69 | + // Verify there are tags |
| 70 | + const cardTags = cardFooter.locator('.card-tags'); |
| 71 | + await expect(cardTags).toBeVisible(); |
| 72 | + |
| 73 | + // Get the bounding boxes |
| 74 | + const footerBox = await cardFooter.boundingBox(); |
| 75 | + const tagsBox = await cardTags.boundingBox(); |
| 76 | + |
| 77 | + expect(footerBox).toBeTruthy(); |
| 78 | + expect(tagsBox).toBeTruthy(); |
| 79 | + |
| 80 | + if (footerBox && tagsBox) { |
| 81 | + // Tags should be aligned to the right (right edge should be close to footer's right edge) |
| 82 | + const footerRight = footerBox.x + footerBox.width; |
| 83 | + const tagsRight = tagsBox.x + tagsBox.width; |
| 84 | + |
| 85 | + // Allow a small margin for padding |
| 86 | + const rightMargin = footerBox.width * 0.1; // 10% tolerance |
| 87 | + expect(tagsRight).toBeGreaterThan(footerRight - rightMargin); |
| 88 | + } |
| 89 | + }); |
| 90 | +}); |
0 commit comments