Skip to content

Commit

Permalink
achieve 100% code coverage (#337)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
amirrustam authored May 17, 2020
1 parent 5272fb7 commit ffd3974
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ workflows:
start: yarn start:ci
record: true
parallel: true
parallelism: 4
parallelism: 5
group: "UI - Firefox"
requires:
- Setup
Expand All @@ -120,7 +120,7 @@ workflows:
start: yarn start:ci
record: true
parallel: true
parallelism: 4
parallelism: 5
group: "UI - Firefox - Mobile"
requires:
- Setup
Expand Down
1 change: 1 addition & 0 deletions backend/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const isUserValidator = [
];

export const sanitizeTransactionStatus = sanitizeQuery("status").customSanitizer((value) => {
/* istanbul ignore if*/
if (includes(value, TransactionStatusValues)) {
return value;
}
Expand Down
24 changes: 24 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions cypress/tests/ui/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down
9 changes: 7 additions & 2 deletions cypress/tests/ui/notifications.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { User, Transaction } from "../../../src/models";
import { isMobile } from "../../support/utils";

type NotificationsCtx = {
userA: User;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
});
Expand Down
7 changes: 5 additions & 2 deletions cypress/tests/ui/transaction-feeds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ 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");
cy.getBySel("sidenav-toggle").click();
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();
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/NavDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const mainListItems = (
onClick={() => showTemporaryDrawer && toggleDrawer()}
component={RouterLink}
to="/notifications"
data-test="sidenav-auth"
data-test="sidenav-notifications"
>
<ListItemIcon>
<NotificationsIcon />
Expand All @@ -85,11 +85,11 @@ export const mainListItems = (

export const secondaryListItems = (signOutPending: Function) => (
<div>
<ListItem button data-test="sidenav-signout">
<ListItem button onClick={() => signOutPending()} data-test="sidenav-signout">
<ListItemIcon>
<LogoutIcon />
</ListItemIcon>
<ListItemText primary="Logout" onClick={() => signOutPending()} />
<ListItemText primary="Logout" />
</ListItem>
</div>
);
Expand Down Expand Up @@ -172,6 +172,7 @@ const NavDrawer: React.FC<Props> = ({

return (
<Drawer
data-test="sidenav"
variant={showTemporaryDrawer ? "temporary" : "persistent"}
classes={{
paper: clsx(classes.drawerPaper, !drawerOpen && classes.drawerPaperClose),
Expand Down
3 changes: 1 addition & 2 deletions src/containers/UserOnboardingContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ const UserOnboardingContainer: React.FC<Props> = ({ authService, bankAccountsSer
<Grid item>
<Button
style={{ paddingRight: "80%" }}
/* istanbul ignore next */
onClick={() => sendAuth("LOGOUT")}
onClick={/* istanbul ignore next */ () => sendAuth("LOGOUT")}
color="secondary"
data-test="user-onboarding-logout"
>
Expand Down
2 changes: 2 additions & 0 deletions src/machines/authMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const authMachine = Machine<AuthMachineContext, AuthMachineSchema, AuthMa
actions: {
redirectHomeAfterLogin: async (ctx, event) => {
if (history.location.pathname === "/signin") {
// TODO: @kevinold: determine if this is necessary. This statement never runs.
/* istanbul ignore next */
window.location.pathname = "/";
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/machines/dataMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export const dataMachine = (machineId: string) =>
setPageData: assign((ctx: DataContext, event: any) => ({
pageData: event.data.pageData,
})),
/* istanbul ignore next */
setMessage: assign((ctx, event: any) => ({

setMessage: /* istanbul ignore next */ assign((ctx, event: any) => ({
message: event.message,
})),
},
Expand Down

0 comments on commit ffd3974

Please sign in to comment.