Skip to content

Commit

Permalink
Wait for images to load in visual tests, instead of blacking them out
Browse files Browse the repository at this point in the history
This reveals that the update indicator (which I'm still blacking out)
in the About window is obscured by the app icon in the Bubblegum theme.

Aside from that, it now tests that the correct icon is shown, and
it's just more satisfying to see the icons, plus it helps with
identifying screenshots at a glance.
  • Loading branch information
1j01 committed Mar 3, 2024
1 parent eb2f9a3 commit f1133dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cypress/integration/visual-tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ context('visual tests', () => {
closeMenus();
cy.wait(1000); // give a bit of time for theme to load
};
// `intercept` requires Cypress 6+
// cypress-image-snapshot@4.0.1 has a peer dependency on cypress@"^4.5.0",
// although I believe it works with v9, and only really has problems on v10.
// That said, this didn't work! So. No point in upgrading just yet.
// I'll upgrade when I'm ready to replace the visual testing framework.
// const waitForRequest = (urlPattern, callback) => {
// // intercept without changing or stubbing response
// cy.intercept(urlPattern).as('urlPattern');
// cy.wait('@urlPattern').then(callback);
// };
const waitForImage = (selector) => {
// should automatically retries
// checking visibility first ensures we're testing at least one image, theoretically
cy.get(selector).should('be.visible');
cy.get(selector).should(($imgs) => {
for (const img of $imgs) {
expect(img.naturalWidth).to.be.greaterThan(0);
expect(img.naturalHeight).to.be.greaterThan(0);
}
});
}

before(() => {
// Hides the news indicator, which shouldn't affect the visual tests.
Expand Down Expand Up @@ -161,8 +182,8 @@ context('visual tests', () => {
it('stretch and skew window', () => {
clickMenuButton('Image');
clickMenuItem('Stretch/Skew');
// @TODO: wait for images to load and include images?
cy.get('.window:visible').matchImageSnapshot(Object.assign({}, withTextCompareOptions, { blackout: ["img"] }));
waitForImage('.window:visible img');
cy.get('.window:visible').matchImageSnapshot(withTextCompareOptions);
});

it('help window', () => {
Expand All @@ -176,7 +197,8 @@ context('visual tests', () => {
it('about window', () => {
clickMenuButton('Help');
clickMenuItem('About Paint');
cy.get('.window:visible').matchImageSnapshot(Object.assign({}, withMuchTextCompareOptions, { blackout: ["img", "#maybe-outdated-line"] }));
waitForImage('#paint-32x32');
cy.get('.window:visible').matchImageSnapshot(Object.assign({}, withMuchTextCompareOptions, { blackout: ["#maybe-outdated-line"] }));
});

it('eye gaze mode', () => {
Expand Down Expand Up @@ -254,7 +276,12 @@ context('visual tests', () => {
it('bubblegum theme -- about window', () => {
clickMenuButton('Help');
clickMenuItem('About Paint');
cy.get('.window:visible').matchImageSnapshot(Object.assign({}, withMuchTextCompareOptions, { blackout: ["img", "#maybe-outdated-line"] }));
// waitForImage('#paint-32x32'); // it's actually replaced with a background image in this theme
// waitForRequest("/images/bubblegum/bubblegum-paint-128x128.png", () => { // not working
// waitForRequest("**/bubblegum-paint-*.png", () => { // not working
cy.wait(1000); // wait and hope it's loaded
cy.get('.window:visible').matchImageSnapshot(Object.assign({}, withMuchTextCompareOptions, { blackout: ["#maybe-outdated-line"] }));
// });
});

it('winter theme -- main screenshot', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f1133dc

Please sign in to comment.