Browse Source

Maintenance: Improve cypress stability

Vladimir Sheremet 2 years ago
parent
commit
5513653cc9

+ 13 - 6
.cypress/utils/index.ts

@@ -69,20 +69,27 @@ interface CheckFormMatchOptions {
   subTitle?: string
   type?: string
   wrapperSelector?: string
+  assertion?: (subject: JQuery<HTMLElement>) => void
 }
 
-export const checkFormMatchesSnapshot = (options?: CheckFormMatchOptions) => {
+export const checkFormMatchesSnapshot = (
+  options: CheckFormMatchOptions = {},
+) => {
   const title = options?.subTitle
     ? `${Cypress.currentTest.title} - ${options.subTitle}`
     : Cypress.currentTest.title
   const wrapperSelector = options?.wrapperSelector || '.formkit-outer'
 
   return cy.wrap(document.fonts.ready).then(() => {
-    cy.get(wrapperSelector).matchImage({
-      title,
-      imagesDir: options?.type
-        ? `__image_snapshots__/${options.type}`
-        : undefined,
+    cy.wrap(new Promise((resolve) => setTimeout(resolve))).then(() => {
+      cy.get(wrapperSelector)
+        .should(options?.assertion || (() => {}))
+        .matchImage({
+          title,
+          imagesDir: options?.type
+            ? `__image_snapshots__/${options.type}`
+            : undefined,
+        })
     })
   })
 }

+ 7 - 1
app/frontend/cypress/shared/components/Form/fields/FieldAutoComplete/autocomplete-visuals.cy.ts

@@ -140,7 +140,13 @@ describe('testing visuals for "FieldAutocomplete"', () => {
 
     it(`renders long ${type}`, () => {
       mountFormField(type, { label: type, value: 5, options })
-      checkFormMatchesSnapshot({ type })
+      checkFormMatchesSnapshot({
+        type,
+        assertion: ($el) => {
+          expect($el.height()).to.be.above(60)
+          return $el
+        },
+      })
     })
   })
 })