Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/js/components/Lazy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export default {
}
}

window.$on('load-lazy', () => {
this.state.isIntersected = true
})

this.onIdle(() => {
this.state.isIntersected = true
})
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/playwright/general.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('newsletter', BasePage.tags, async ({ page }) => {
const email = `wayne+${Date.now()}@enterprises.com`

await page.goto('/')
await new BasePage(page).scrolldown()
await new BasePage(page).loadLazy()

await page.getByTestId('newsletter-email').fill(email)
await page.getByTestId('newsletter-submit').click()
Expand Down
32 changes: 14 additions & 18 deletions tests/playwright/pages/BasePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,35 @@ export class BasePage {
options['mask'] = masks

if (type.startsWith('fullpage')) {
await this.scrolldown()
await this.loadLazy()
options['fullPage'] = true
}

if (type.startsWith('fullpage-footer')) {
await expect(this.page.getByTestId('newsletter-email')).toBeVisible()
}

if (type == 'fullpage-footer-images') {
await this.waitForImages()
}

await this.waitForImages()
await expect(this.page).toHaveScreenshot(options)
}

async scrolldown() {
for (let i = 10; i >= 1; i--) {
await this.page.evaluate((i) => window.scrollTo(0, document.body.scrollHeight / i), i)
await this.page.waitForTimeout(10)
}
await this.page.waitForLoadState('networkidle')
await this.page.evaluate(() => window.scrollTo(0, 0))
await this.page.waitForLoadState('networkidle')
}

async waitForImages() {
for (const img of await this.page.locator('img[loading="lazy"]:visible').all()) {
await img.scrollIntoViewIfNeeded()
// Make all images eager loaded
await this.page.evaluate(() => window.document.querySelectorAll('img[loading="lazy"]').forEach((elem) => (elem.loading = 'eager')))

// Check all images for completed state
for (const img of await this.page.locator('img').all()) {
await expect(img).toHaveJSProperty('complete', true)
await expect(img).not.toHaveJSProperty('naturalWidth', 0)
}
}

await this.page.evaluate(() => window.scrollTo(0, 0))
async loadLazy() {
await this.page.waitForLoadState('networkidle')
await this.page.evaluate(() => window.$emit('load-lazy'))
await this.page.waitForTimeout(250)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of these timeouts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The whole issue with images not being loaded in is because these timeouts were missing. I had a low timeout at first, but then it was semi-random when images loaded in or not. This was the only consistent solution.

await this.page.waitForLoadState('networkidle')
await this.page.waitForTimeout(250)
}

async wcag(testInfo, disabledRules = []) {
Expand Down
Loading