Skip to content

Commit

Permalink
add unit testing to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwgreene committed Oct 2, 2020
1 parent c877aca commit a73aa42
Show file tree
Hide file tree
Showing 68 changed files with 15,673 additions and 3 deletions.
9 changes: 9 additions & 0 deletions demo-app/exercises/exercise-19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Exercise 19

1. Implement a snapshot test for Car View Row.

2. Implement a DOM-based test for Car View Row.

Ideally, use the "getAllByRole" and test the content of the tds.

3. Ensure it works!
71 changes: 71 additions & 0 deletions demo-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions demo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
]
},
"devDependencies": {
"@testing-library/react-hooks": "^3.4.2",
"@types/react-redux": "^7.1.9",
"jest-fetch-mock": "^3.0.3",
"json-server": "^0.16.2",
"npm-run-all": "^4.1.5",
"react-test-renderer": "^16.13.1",
"redux-devtools-extension": "^2.13.8"
}
}
25 changes: 25 additions & 0 deletions demo-app/src/components/ToolHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

import { render } from '@testing-library/react';
import renderer from 'react-test-renderer';

import { ToolHeader } from './ToolHeader';

test('snapshot ToolHeader component', () => {
expect(
renderer.create(<ToolHeader headerText="The Tool" />).toJSON(),
).toMatchSnapshot();
});

describe('ToolHeader component', () => {
test('renders ToolHeader component', () => {
const { getByText, getByRole, getAllByRole } = render(
<ToolHeader headerText="The Tool" />,
);

// expect(getByText('The Tool').textContent).toBe('The Tool');
expect(getByText('The Tool')).toBeInTheDocument();

expect(getByRole('heading').textContent).toBe('The Tool');
});
});
2 changes: 1 addition & 1 deletion demo-app/src/components/ToolHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from "react";
import React, { FC } from 'react';

export interface ToolHeaderProps {
headerText: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot ToolHeader component 1`] = `
<header>
<h1>
The Tool
</h1>
</header>
`;
1 change: 1 addition & 0 deletions demo-app/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-dom/extend-expect';
11 changes: 9 additions & 2 deletions demo-app/src/services/RestClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Item, ItemId } from '../models/item';

export class RestClient<T extends Item> {

// private baseUrl: string;

// constructor(baseUrl: string) {
// this.baseUrl = baseUrl;
// }

constructor(private baseUrl: string) {}

async all() {
Expand All @@ -9,7 +16,7 @@ export class RestClient<T extends Item> {
return items as T[];
}

async append(newItem: Omit<Item, 'id'>) {
async append(newItem: Omit<T, 'id'>) {
const res = await fetch(`${this.baseUrl}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -20,7 +27,7 @@ export class RestClient<T extends Item> {
return car.id;
}

async replace(item: Item) {
async replace(item: T) {
await fetch(`${this.baseUrl}/${encodeURIComponent(item.id)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
Expand Down
23 changes: 23 additions & 0 deletions perf-car-tool-app-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
19 changes: 19 additions & 0 deletions perf-car-tool-app-starter/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": true,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "consistent",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false,
"vueIndentScriptAndStyle": false
}
1 change: 1 addition & 0 deletions perf-car-tool-app-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Performance Car Tool App Starter
Loading

0 comments on commit a73aa42

Please sign in to comment.