Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: disable spellcheck in argosScreenshot (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfez authored Sep 21, 2023
1 parent ccf8e07 commit e8e4144
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cypress/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h3>Red square</h3>
class="red-square"
style="width: 100px; height: 100px; background-color: red"
></div>

<h3>Editable contents</h3>
<div class="field">
<div><input value="an orrange carrot" /></div>
<div><textarea>an orrange carrot</textarea></div>
<p contenteditable="true" autofocus>an orrange carrot</p>
</div>
</main>

<script>
Expand Down
44 changes: 34 additions & 10 deletions support.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ function waitUntilNoBusy() {
);
}

/**
* Wait until all images are loaded.
*/
function waitForImagesLoading() {
cy.waitUntil(() =>
cy.document().then((document) => {
const allImages = Array.from(document.images);
allImages.forEach((img) => {
img.loading = "eager";
img.decoding = "sync";
});
return allImages.every((img) => img.complete && img.naturalWidth > 0);
})
);
}

/**
* Disable spellcheck on inputs, textareas, and contenteditable elements to avoid red underlines
*/
function disableSpellCheck() {
cy.document().then((document) => {
const query =
"[contenteditable]:not([contenteditable=false]):not([spellcheck=false]), input:not([spellcheck=false]), textarea:not([spellcheck=false])";
document.querySelectorAll(query).forEach((element) => {
element.setAttribute("spellcheck", "false");
});
});
return true;
}

Cypress.Commands.add(
"argosScreenshot",
{ prevSubject: ["optional", "element", "window", "document"] },
Expand All @@ -83,16 +113,10 @@ Cypress.Commands.add(
cy.document().its("fonts.status").should("equal", "loaded");

// Wait for images to be loaded
cy.waitUntil(() =>
cy.document().then((document) => {
const allImages = Array.from(document.images);
allImages.forEach((img) => {
img.loading = "eager";
img.decoding = "sync";
});
return allImages.every((img) => img.complete && img.naturalWidth > 0);
})
);
waitForImagesLoading();

// Wait for images to be loaded
disableSpellCheck();

// Screenshot
cy.wrap(subject).screenshot(name, {
Expand Down

0 comments on commit e8e4144

Please sign in to comment.