Browse Source

add isInViewport command

Yuki Takei 2 years ago
parent
commit
cc563528d3
2 changed files with 13 additions and 0 deletions
  1. 12 0
      apps/app/test/cypress/support/commands.ts
  2. 1 0
      apps/app/test/cypress/support/index.ts

+ 12 - 0
apps/app/test/cypress/support/commands.ts

@@ -98,3 +98,15 @@ Cypress.Commands.add('collapseSidebar', (isCollapsed: boolean, waitUntilSaving =
     });
   });
 });
+
+Cypress.Commands.add('isInViewport', (selector: string) => {
+  cy.get(selector).then($el => {
+    const bottom = Cypress.config("viewportWidth");
+    const rect = $el[0].getBoundingClientRect();
+
+    expect(rect.top).not.to.be.greaterThan(bottom);
+    expect(rect.bottom).not.to.be.greaterThan(bottom);
+    expect(rect.top).not.to.be.greaterThan(bottom);
+    expect(rect.bottom).not.to.be.greaterThan(bottom);
+  });
+});

+ 1 - 0
apps/app/test/cypress/support/index.ts

@@ -37,6 +37,7 @@ declare global {
        getByTestid(selector: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<Element>>,
        login(username: string, password: string): Chainable<void>,
        collapseSidebar(isCollapsed: boolean, waitUntilSaving?: boolean): Chainable<void>,
+       isInViewport(selector: string): Chainable<void>,
        waitUntilSkeletonDisappear(): Chainable<void>,
        waitUntilSpinnerDisappear(): Chainable<void>,
     }