Skip to content

Commit f457217

Browse files
authored
Merge pull request #2 from fitodac/feature/index-responsive
Feature/index responsive
2 parents 8903fc2 + ac023fc commit f457217

65 files changed

Lines changed: 446 additions & 206 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

e2e/check.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { chromium } from 'playwright';
2+
3+
(async () => {
4+
const browser = await chromium.launch();
5+
const page = await browser.newPage();
6+
7+
const viewports = [
8+
{ name: 'Mobile', width: 375, height: 667 },
9+
{ name: 'Tablet', width: 768, height: 1024 },
10+
{ name: 'Desktop', width: 1440, height: 900 },
11+
];
12+
13+
const pagesToCheck = [
14+
{ name: 'Index', url: 'http://localhost:4321/' },
15+
{ name: 'Cursos', url: 'http://localhost:4321/cursos' },
16+
{ name: 'Proyectos', url: 'http://localhost:4321/proyectos' },
17+
{ name: 'Publicaciones', url: 'http://localhost:4321/publicaciones' }
18+
];
19+
20+
let hasErrors = false;
21+
22+
for (const pageInfo of pagesToCheck) {
23+
console.log(`\nChecking page: ${pageInfo.name}`);
24+
for (const vp of viewports) {
25+
await page.setViewportSize({ width: vp.width, height: vp.height });
26+
await page.goto(pageInfo.url);
27+
await page.waitForLoadState('networkidle');
28+
29+
const isResponsive = await page.evaluate(() => {
30+
return document.documentElement.scrollWidth <= window.innerWidth;
31+
});
32+
33+
console.log(` - Viewport ${vp.name} (${vp.width}x${vp.height}): Responsive=${isResponsive}`);
34+
35+
if (!isResponsive) {
36+
console.error(` ERROR: Horizontal scroll detected on ${pageInfo.name} at ${vp.name}!`);
37+
38+
// Find what's overflowing
39+
const overflowingElements = await page.evaluate(() => {
40+
const docWidth = document.documentElement.clientWidth;
41+
const elements = Array.from(document.querySelectorAll('*'));
42+
const overflows = [];
43+
for (const el of elements) {
44+
const rect = el.getBoundingClientRect();
45+
if (rect.right > docWidth) {
46+
overflows.push({
47+
tag: el.tagName,
48+
className: el.className,
49+
right: rect.right,
50+
docWidth
51+
});
52+
}
53+
}
54+
return overflows.slice(0, 3); // top 3
55+
});
56+
console.log(` Overflowing elements:`, overflowingElements);
57+
hasErrors = true;
58+
}
59+
}
60+
}
61+
62+
await browser.close();
63+
64+
if (hasErrors) {
65+
process.exit(1);
66+
} else {
67+
console.log('\nSUCCESS: All pages and viewports are successfully responsive.');
68+
process.exit(0);
69+
}
70+
})();

e2e/index.responsive.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const viewports = [
4+
{ name: 'Mobile', width: 375, height: 667 },
5+
{ name: 'Tablet', width: 768, height: 1024 },
6+
{ name: 'Desktop', width: 1440, height: 900 },
7+
];
8+
9+
test.describe('Responsive Index Page', () => {
10+
for (const vp of viewports) {
11+
test(`Viewport: ${vp.name}`, async ({ page }) => {
12+
await page.setViewportSize({ width: vp.width, height: vp.height });
13+
await page.goto('http://localhost:4321/');
14+
15+
// Wait for network idle to ensure everything is loaded
16+
await page.waitForLoadState('networkidle');
17+
18+
// Check for horizontal scrollability by comparing scrollWidth and clientWidth
19+
const isResponsive = await page.evaluate(() => {
20+
return document.documentElement.scrollWidth <= window.innerWidth;
21+
});
22+
23+
// Take a screenshot for visual confirmation
24+
await page.screenshot({ path: `playwright-report/screenshots/index-${vp.name.toLowerCase()}.png`, fullPage: true });
25+
26+
// The layout should fit without horizontal scrolling
27+
expect(isResponsive, `Page should not have horizontal scrollbar on ${vp.name}`).toBe(true);
28+
});
29+
}
30+
});

package-lock.json

Lines changed: 61 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
},
2929
"devDependencies": {
3030
"@astrojs/check": "^0.9.6",
31+
"@playwright/test": "^1.58.2",
3132
"@types/node": "^20",
33+
"playwright": "^1.58.2",
3234
"prettier": "^3.8.1",
3335
"prettier-plugin-astro": "^0.14.1",
3436
"typescript": "^5.9.3"
188 KB
Binary file not shown.
91.2 KB
Binary file not shown.
169 KB
Binary file not shown.
237 KB
Binary file not shown.
187 KB
Binary file not shown.
192 KB
Binary file not shown.

0 commit comments

Comments
 (0)