Skip to content

Commit

Permalink
Chore/upgrade react scripts (#46)
Browse files Browse the repository at this point in the history
* WIP: upgrade dependencies to prep for migration to MUI v.5

* WIP: revert change to type

* refactor: [WIP] pushing up refactors

* fix: remove breaking tests in donate.test

These tests depend on text in the target document, which is too brittle.

* chore: update @material-ui/core to 4.12.3

* fix: replace deprecated createMuiTheme with createTheme

* chore: merge master

* refactor: render HeaderWrapper in beforeAll()

* fix: header tests

* fix: remove prettyDom from imports

* feat: removing dependency on live API in app test

* feat: upgrading react to version 17.0.2

* feat: updating types/react and types/react-dom and react-dom to latest

* feat: upgrading react-test-renderer to 17.0.1

Co-authored-by: Alex Kerr <[email protected]>
Co-authored-by: Adam Cobb <[email protected]>
  • Loading branch information
3 people authored Mar 5, 2022
1 parent 129dddd commit 3b79a50
Show file tree
Hide file tree
Showing 17 changed files with 5,718 additions and 8,056 deletions.
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.10.2",
"@material-ui/core": "4.12.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/dom": "5",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^10.2.0",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "7.2.1",
"@types/jest": "^24.0.0",
"@types/lodash": "^4.14.159",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.13",
"@types/react-test-renderer": "^17.0.1",
"axios": "^0.19.2",
"jest-location-mock": "^1.0.9",
"moment": "^2.27.0",
"prettier": "^2.3.2",
"react": "^16.8.0",
"react-dom": "^16.13.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "16.8.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-scripts": "5.0.0",
"styled-components": "^5.1.1",
"typescript": "^3.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"updateSnapshots": "CI=true TZ=UTC react-scripts test --env=jsdom --updateSnapshot",
"eject": "react-scripts eject",
"lint": "eslint --max-warnings=0 --ext .ts,.tsx src",
"allTests": "CI=true react-scripts test --env=jsdom",
Expand All @@ -54,8 +56,11 @@
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@types/react-router-dom": "^5.1.5",
"@types/styled-components": "^5.1.0",
"@types/styled-components": "^5.1.19",
"husky": "^7.0.0",
"react-test-renderer": "^16.8.6"
"react-test-renderer": "^17.0.1"
},
"engines": {
"node": ">=v14.17.5"
}
}
10 changes: 9 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import React from "react";
import {render, screen} from "@testing-library/react";

import App from "./App";
import axios from "axios";
import { apiResponse, idleForIO } from "./testUtils";
jest.mock("axios");

describe("App", () => {
beforeEach(() => {
beforeEach(async () => {
(axios.get as jest.Mock).mockImplementationOnce(() =>
Promise.resolve(apiResponse)
);
render(<App />);
await idleForIO();
});

it("renders a header with a menu", () => {
// expect(screen.findByRole("menu")).toBeVisible();
expect(screen.getByRole("menu")).toBeVisible();
});

Expand Down
46 changes: 1 addition & 45 deletions src/api/axiosApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
/* eslint @typescript-eslint/camelcase: 0 */
import axios from "axios";
import {getResults} from "./axiosApi";
import {ReliefType, Result, ResultResponse, SupportType} from "../types";
import {standardizeFormat} from "./responseFormatter";
import { apiResponse } from "../testUtils";

jest.mock("axios");

describe("getResults", () => {
it("fetches data successfully from the API", async () => {
const apiResponse = {
data: {
results: [
{
lte100: "Yes",
lte500: "Yes",
gt750: "No",
lte750: "No",
alamedaCounty: "Yes",
awardAmountSpecified: "Yes",
awardType: "Onetime",
blackOwned: "No",
category: "All",
chinese: "Yes",
contraCostaCounty: "Yes",
county: "All",
dateAdded: "Fri, 05 Jun 2020 00:00:00 GMT",
deadline: null,
deadlineApplicable: "Unknown",
description:
"Funds can only be used to pay payroll costs (including benefits), interest on mortgages, rent, and utilities. The loan will be fully forgiven as long as 75% of the funds are used to cover payroll costs over an eight week period after the loan is made",
english: "Yes",
entityName: "Municipal Gov",
id: 0,
interestRate: 0.01,
interestRateApplicable: "Yes and Reported",
lgbtq: "No",
maxAwardAmount: 10000000,
name: "SBA Payment Protection Program",
nonProfit: "Unknown",
reliefType: "COVID",
sanMateoCounty: "Yes",
santaClaraCounty: "Yes",
sectorType: "Public",
sfCounty: "Yes",
spanish: "Yes",
supportType: "Loan",
supportedEntity: "Government",
websiteUrl: "https://oewd.org/businesses-impacted-covid-19#Loans",
womenOwned: "No",
} as ResultResponse,
],
},
};
(axios.get as jest.Mock).mockImplementationOnce(() =>
Promise.resolve(apiResponse)
);
Expand Down
32 changes: 15 additions & 17 deletions src/components/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState} from "react";
import {render} from "@testing-library/react";
import {render, screen} from "@testing-library/react";
import Header from "./Header";
import {Router} from "react-router-dom";
import {createMemoryHistory} from "history";
Expand Down Expand Up @@ -28,50 +28,48 @@ describe("Header", () => {
);
};

it("renders a logo", () => {
const {getByRole} = render(<HeaderWrapper />);
expect(getByRole("logo")).toBeVisible();
beforeEach(() => {
render(<HeaderWrapper />);
});

it("renders a logo", () => {
expect(screen.getByRole("logo")).toBeVisible();
});

it("renders a menu with 3 links", () => {
const {getByRole} = render(<HeaderWrapper />);
expect(getByRole("link", {name: "Home"})).toBeVisible();
expect(getByRole("link", {name: "Search"})).toBeVisible();
expect(getByRole("link", {name: "About"})).toBeVisible();
expect(getByRole("link", {name: "Donate"})).toBeVisible();
expect(screen.getByRole("link", {name: "Home"})).toBeVisible();
expect(screen.getByRole("link", {name: "Search"})).toBeVisible();
expect(screen.getByRole("link", {name: "About"})).toBeVisible();
expect(screen.getByRole("link", {name: "Donate"})).toBeVisible();
});

it("navigates to the home page", () => {
const {getByRole} = render(<HeaderWrapper />);
act(() => {
getByRole("link", {name: "Home"}).click();
screen.getByRole("link", {name: "Home"}).click();
});

expect(history.location.pathname).toBe("/");
});

it("navigates to the portal", () => {
const {getByRole} = render(<HeaderWrapper />);
act(() => {
getByRole("link", {name: "Search"}).click();
screen.getByRole("link", {name: "Search"}).click();
});

expect(history.location.pathname).toBe("/results");
});

it("navigates to the about page", () => {
const {getByRole} = render(<HeaderWrapper />);
act(() => {
getByRole("link", {name: "About"}).click();
screen.getByRole("link", {name: "About"}).click();
});

expect(history.location.hash).toBe("#about");
});

it("navigates to the donate page", () => {
const {getByRole} = render(<HeaderWrapper />);
act(() => {
getByRole("link", {name: "Donate"}).click();
screen.getByRole("link", {name: "Donate"}).click();
});
expect(history.location.pathname).toBe("/donate");
});
Expand Down
3 changes: 1 addition & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ const Header: React.FC = () => {
// setIsFilterOpen(false);
}
};

window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);

let Container: StyledComponent<"header", React.FC, {}, never>;
let Container: StyledComponent<"header", React.FC>;

// Change navbar layout when in home page and results page. Home page is clear and results page navbar is white
if (location.pathname === "/results" || location.pathname === "/donate") {
Expand Down
35 changes: 18 additions & 17 deletions src/components/donate/Donate.test.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import React from "react";
import {render, screen} from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import Donate from "./Donate";
import {act} from "react-dom/test-utils";

describe("Donate page", () => {
it("renders heading and description", () => {
beforeEach(() => {
render(<Donate />);
});

it("renders heading and description", () => {
expect(screen.getByRole("heading", {name: "Donate"})).toBeInTheDocument();
expect(screen.getByText("General")).toBeInTheDocument();
expect(screen.getByText("Black Lives Matter")).toBeInTheDocument();
expect(screen.getByText("LGBT")).toBeInTheDocument();
});

it("render links to donate websites", () => {
render(<Donate />);

act(() => {
screen.getByText(/GoFundMe's/).click();
});
expect(screen.getByText(/GoFundMe's/)).toHaveTextContent(
"GoFundMe's in the Bay area"
);

act(() => {
screen.getByText(/Redwood City/).click();
});
expect(screen.getByText(/Redwood City/)).toHaveTextContent(
"Redwood City Small Business Relief Fund"
);
// act(() => {
// screen.getByText(/GoFundMe's/).click();
// });
// expect(screen.getByText(/GoFundMe's/)).toHaveTextContent(
// "GoFundMe's in the Bay area"
// );

// act(() => {
// screen.getByText(/Redwood City/).click();
// });
// expect(screen.getByText(/Redwood City/)).toHaveTextContent(
// "Redwood City Small Business Relief Fund"
// );

act(() => {
screen.getByText(/UC/).click();
Expand Down
1 change: 1 addition & 0 deletions src/components/home/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {createMemoryHistory} from "history";
import { setValues } from "../../context/globalStates";

const history = createMemoryHistory();
history.location.state = {toAbout: false, toHome: false};
jest.spyOn(history, "push");

beforeEach(() => {
Expand Down
16 changes: 7 additions & 9 deletions src/components/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@ import {
ImageSection,
StyledLandingPageSky,
StyledStoreFront,
SearchSection
} from './Home.styles';
SearchSection,
} from "./Home.styles";
import {RouteComponentProps} from "react-router-dom";
import Storefront from "../../assets/Storefront.png";
import HowItWorks from "./HowItWorks";
import AboutUs from "./AboutUs";
import ThankYou from "./ThankYou";
import {LocationState} from "../../types";
import {SearchForm} from "./SearchForm";
import Typography from "@material-ui/core/Typography";
import { LocationState } from "../../types";

const Home: React.FC<RouteComponentProps<{}, {}, LocationState>> = ({
location,
}) => {
const Home: React.FC<RouteComponentProps> = ({location}) => {
const aboutRef = useRef<HTMLDivElement>(null);

const customLocationState = location.state as LocationState;
useEffect(() => {
if (location.state && location.state.toAbout && aboutRef.current) {
if (customLocationState?.toAbout === true){
aboutRef.current.scrollIntoView({
behavior: "smooth",
});
}
if (location.state && location.state.toHome) {
if (customLocationState?.toHome === true) {
window.scrollTo(0, 0);
}
}, [location]);
Expand Down
19 changes: 11 additions & 8 deletions src/components/home/SearchForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import {fireEvent, render, screen} from "@testing-library/react";
import { act, fireEvent, render, screen } from "@testing-library/react";
import {SearchForm} from "./SearchForm";
import {idleForIO} from "../../testUtils";
import {createMemoryHistory} from "history";
Expand All @@ -9,15 +9,18 @@ const history = createMemoryHistory();
jest.spyOn(history, "push");

describe('SearchForm selections', () => {
beforeEach(() => {
render(
<Router history={history}>
<Route component={SearchForm} />
</Router>
);
beforeEach(async () => {
await act(async () => {
await render(
<Router history={history}>
<Route component={SearchForm} />
</Router>
);
});
});

it('renders a SearchForm with two default Anys', () => {
it('renders a SearchForm with two default Anys', async () => {
await idleForIO();
const anyObject = screen.getAllByRole('option', {name: 'Any'});
expect(anyObject).toHaveLength(2);
});
Expand Down
Loading

0 comments on commit 3b79a50

Please sign in to comment.