Skip to content

Commit

Permalink
Implemented basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FLiotta committed Oct 30, 2020
1 parent 2b63d33 commit e5e2be7
Show file tree
Hide file tree
Showing 13 changed files with 8,728 additions and 3,544 deletions.
20 changes: 20 additions & 0 deletions client/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defaults } from 'jest-config';

export default {
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
'^.+\\.tsx?$': 'ts-jest',
"^.+\\.svg$": "<rootDir>/svgTransform.ts"
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
roots: ["<rootDir>/src"],
setupFilesAfterEnv: [
"@testing-library/jest-dom/extend-expect"
],
moduleNameMapper: {
"\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/jest-css-modules",
'^@backend/(.*)$': '<rootDir>/../server/src/api/$1',
},
};
12,145 changes: 8,608 additions & 3,537 deletions client/package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"main": "index.js",
"scripts": {
"bundle": "webpack --mode production",
"start": "webpack-dev-server"
"start": "webpack-dev-server",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"@babel/preset-react": "^7.12.1",
"@types/jest": "^26.0.13",
"@types/node": "^14.10.1",
"@types/react": "^16.9.49",
Expand All @@ -30,6 +31,8 @@
"dayjs": "^1.8.31",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^26.6.1",
"jest-css-modules": "^2.1.0",
"live-server": "^1.2.1",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.12.0",
Expand All @@ -53,7 +56,9 @@
"sass": "^1.24.0",
"sass-loader": "^8.0.0",
"style-loader": "^1.0.0",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.3",
"ts-node": "^9.0.0",
"typescript": "^4.0.2",
"uglifyjs-webpack-plugin": "^2.2.0",
"universal-cookie": "^4.0.3",
Expand All @@ -62,5 +67,9 @@
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0"
}
}
2 changes: 1 addition & 1 deletion client/src/components/BoardCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './styles.scss';
// Declarations
const boardService = new BoardsService();

interface BoardCardProps {
export interface BoardCardProps {
className?: string,
onDelete?: Function,
boardInfo: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<EditableText /> Matches snapshot 1`] = `
<div
class="editable-text"
>
<p
class="editable-text__title"
>
test text
<i
class="fas fa-pencil-alt editable-text__icon"
/>
</p>
</div>
`;
21 changes: 21 additions & 0 deletions client/src/components/EditableText/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Packages
import * as React from 'react';
import { render } from '@testing-library/react';

// Project
import EditableText from '../index';


describe('<EditableText />', () => {
it('Matches snapshot', () => {
const { container } = render(
<EditableText
text="test text"
tag="p"
onSuccess={jest.fn()}
/>
);

expect(container.firstChild).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Loading /> Matches snapshot 1`] = `
<div
class="loading"
>
<img
src="[object Object]"
/>
</div>
`;
24 changes: 24 additions & 0 deletions client/src/components/Loading/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Packages
import * as React from 'react';
import { render } from '@testing-library/react';

// Project
import Loading from '../index';


describe('<Loading />', () => {
it('Matches snapshot', () => {
const { container } = render(
<Loading display />
);

expect(container.firstChild).toMatchSnapshot();
});

it('Not visible when false display prop', () => {
const { container } = render(
<Loading />
);
expect(container.firstChild).toHaveClass('loading--hidden');
});
});
2 changes: 1 addition & 1 deletion client/src/components/Loading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Spinner from '../../assets/images/spinner.svg';
import './styles.scss'

interface LoadingProps {
display: Boolean
display?: Boolean
};

const Loading = ({ display }: LoadingProps): JSX.Element => (
Expand Down
Empty file added client/src/jest-utils.ts
Empty file.
1 change: 1 addition & 0 deletions client/src/setupTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom/extend-expect'
8 changes: 8 additions & 0 deletions client/svgTransform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
process() {
return 'module.exports = {};';
},
getCacheKey() {
return 'svgTransform';
},
}
8 changes: 5 additions & 3 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"jsx": "react",
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "node",
"lib": [
"es2019",
"dom"
]
}
"dom",
],
},
"exclude": ["node_modules"]
}

0 comments on commit e5e2be7

Please sign in to comment.