From ffd3974d1454db03834f05e93c62dba529d857a0 Mon Sep 17 00:00:00 2001 From: Amir Rustamzadeh <334337+amirrustam@users.noreply.github.com> Date: Sun, 17 May 2020 19:52:22 -0400 Subject: [PATCH] achieve 100% code coverage (#337) * add codecov.yml * remove codecov flags on custom status paths * I have a need, a need for speed... * I have a need, a need for more 100% coverage * directly cy.visit notifications page * move click-handler to item element * fix pathname assertion after user logout * istanbul ignore currently unused query string sanitizer * attempt inline istanbul comment on onclick handler * temporary fix for firefox mobile flakiness during paginated scrolling * add gh issue to temporary fix comment * istanbul ignore currently unused xstate action * ignore unused statement and added todo to determine its fate --- .circleci/config.yml | 4 ++-- backend/validators.ts | 1 + codecov.yml | 24 ++++++++++++++++++++++ cypress/tests/ui/auth.spec.ts | 4 ++-- cypress/tests/ui/notifications.spec.ts | 9 ++++++-- cypress/tests/ui/transaction-feeds.spec.ts | 7 +++++-- src/components/NavDrawer.tsx | 7 ++++--- src/containers/UserOnboardingContainer.tsx | 3 +-- src/machines/authMachine.ts | 2 ++ src/machines/dataMachine.ts | 4 ++-- 10 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 codecov.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index b08d410e1..715fd40e4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,7 +101,7 @@ workflows: start: yarn start:ci record: true parallel: true - parallelism: 4 + parallelism: 5 group: "UI - Firefox" requires: - Setup @@ -120,7 +120,7 @@ workflows: start: yarn start:ci record: true parallel: true - parallelism: 4 + parallelism: 5 group: "UI - Firefox - Mobile" requires: - Setup diff --git a/backend/validators.ts b/backend/validators.ts index e67982f80..2cf514fab 100644 --- a/backend/validators.ts +++ b/backend/validators.ts @@ -51,6 +51,7 @@ export const isUserValidator = [ ]; export const sanitizeTransactionStatus = sanitizeQuery("status").customSanitizer((value) => { + /* istanbul ignore if*/ if (includes(value, TransactionStatusValues)) { return value; } diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..beac60c3c --- /dev/null +++ b/codecov.yml @@ -0,0 +1,24 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: nearest + range: "90...100" + status: + project: + default: + base: auto + target: auto + threshold: 0.1% + if_not_found: success + backend: + paths: + - backend + frontend: + paths: + - src + +comment: + layout: "reach,diff,flags,tree" + behavior: default diff --git a/cypress/tests/ui/auth.spec.ts b/cypress/tests/ui/auth.spec.ts index 5264a409b..0c1f683ae 100644 --- a/cypress/tests/ui/auth.spec.ts +++ b/cypress/tests/ui/auth.spec.ts @@ -28,7 +28,7 @@ describe("User Sign-up and Login", function () { cy.getBySel("sidenav-toggle").click(); } cy.getBySel("sidenav-signout").click(); - cy.location("pathname").should("eq", "/"); + cy.location("pathname").should("eq", "/signin"); }); it("should allow a visitor to sign-up, login, and logout", function () { @@ -78,7 +78,7 @@ describe("User Sign-up and Login", function () { cy.getBySel("sidenav-toggle").click(); } cy.getBySel("sidenav-signout").click(); - cy.location("pathname").should("eq", "/"); + cy.location("pathname").should("eq", "/signin"); }); it("should display login errors", function () { diff --git a/cypress/tests/ui/notifications.spec.ts b/cypress/tests/ui/notifications.spec.ts index 9b68b1325..d4e858278 100644 --- a/cypress/tests/ui/notifications.spec.ts +++ b/cypress/tests/ui/notifications.spec.ts @@ -1,4 +1,5 @@ import { User, Transaction } from "../../../src/models"; +import { isMobile } from "../../support/utils"; type NotificationsCtx = { userA: User; @@ -51,7 +52,6 @@ describe("Notifications", function () { .its("response.body.results.length") .as("preDismissedNotificationCount"); - //cy.getBySelLike("notifications-link").click(); cy.visit("/notifications"); cy.getBySelLike("notification-list-item") @@ -82,6 +82,7 @@ describe("Notifications", function () { cy.switchUser(ctx.userA.username); cy.getBySelLike("notifications-link").click(); + cy.location("pathname").should("equal", "/notifications"); cy.getBySelLike("notification-list-item") .first() @@ -196,7 +197,11 @@ describe("Notifications", function () { cy.loginByXstate(ctx.userA.username); - cy.getBySelLike("notifications-link").click(); + if (isMobile()) { + cy.getBySel("sidenav-toggle").click(); + } + cy.getBySel("sidenav-notifications").click(); + cy.location("pathname").should("equal", "/notifications"); cy.getBySel("notification-list").should("not.be.visible"); cy.getBySel("empty-list-header").should("contain", "No Notifications"); }); diff --git a/cypress/tests/ui/transaction-feeds.spec.ts b/cypress/tests/ui/transaction-feeds.spec.ts index d804080dc..ddbada6c6 100644 --- a/cypress/tests/ui/transaction-feeds.spec.ts +++ b/cypress/tests/ui/transaction-feeds.spec.ts @@ -57,7 +57,7 @@ describe("Transaction Feed", function () { cy.loginByXstate(ctx.user.username); }); }); - describe("app layout and responsivness", function () { + describe("app layout and responsiveness", function () { it("toggles the navigation drawer", function () { if (isMobile()) { cy.getBySel("sidenav-home").should("not.be.visible"); @@ -65,6 +65,9 @@ describe("Transaction Feed", function () { cy.getBySel("sidenav-home").should("be.visible"); cy.get(".MuiBackdrop-root").click({ force: true }); cy.getBySel("sidenav-home").should("not.be.visible"); + + cy.getBySel("sidenav-toggle").click(); + cy.getBySel("sidenav-home").click().should("not.be.visible"); } else { cy.getBySel("sidenav-home").should("be.visible"); cy.getBySel("sidenav-toggle").click(); @@ -165,7 +168,7 @@ describe("Transaction Feed", function () { .its("response.body.results") .should("have.length", Cypress.env("paginationPageSize")); - // Temporary fix + // Temporary fix: https://github.com/cypress-io/cypress-realworld-app/issues/338 if (isMobile()) { cy.wait(10); } diff --git a/src/components/NavDrawer.tsx b/src/components/NavDrawer.tsx index 70f1f42e4..4e1ba4db1 100644 --- a/src/components/NavDrawer.tsx +++ b/src/components/NavDrawer.tsx @@ -73,7 +73,7 @@ export const mainListItems = ( onClick={() => showTemporaryDrawer && toggleDrawer()} component={RouterLink} to="/notifications" - data-test="sidenav-auth" + data-test="sidenav-notifications" > @@ -85,11 +85,11 @@ export const mainListItems = ( export const secondaryListItems = (signOutPending: Function) => (
- + signOutPending()} data-test="sidenav-signout"> - signOutPending()} /> +
); @@ -172,6 +172,7 @@ const NavDrawer: React.FC = ({ return ( = ({ authService, bankAccountsSer