Skip to content

Commit

Permalink
Update for unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
wize-hieunguyen committed May 7, 2020
1 parent e7f41c2 commit 3d46ab9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 206 deletions.
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import 'babel-polyfill';

configure({ adapter: new Adapter() })
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@material-ui/icons": "^4.9.1",
"@okta/okta-react": "^3.0.1",
"axios": "^0.19.2",
"babel-polyfill": "^6.26.0",
"css-loader": "^3.5.3",
"dotenv": "^8.2.0",
"file-loader": "^6.0.0",
Expand Down
2 changes: 0 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Container } from 'semantic-ui-react'
import config from './config'
import Navbar from './views/Navbar'
import Home from './views/Home'
import Profile from './views/Profile'

const App = () => (
<Router>
Expand All @@ -14,7 +13,6 @@ const App = () => (
<Container text style={{ marginTop: '7em' }}>
<Route path="/" exact component={Home} />
<Route path="/implicit/callback" component={LoginCallback} />
<SecureRoute path="/profile" component={Profile} />
</Container>
</Security>
</Router>
Expand Down
11 changes: 11 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import { shallow } from 'enzyme'
import App from './App'

describe('App component', () => {
const component = shallow(<App />)

it('renders without crashing', () => {
expect(component.length).toBe(1)
})
})
107 changes: 0 additions & 107 deletions src/__tests__/App.test.js

This file was deleted.

30 changes: 0 additions & 30 deletions src/__tests__/__snapshots__/App.test.js.snap

This file was deleted.

6 changes: 4 additions & 2 deletions src/views/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ const Dashboard = () => {
{authState.isAuthenticated && userInfo && (
<div>
<p>
Logged in, Welcome back,
Logged in, Welcome back,
{userInfo.name}
</p>
<p>
<a href="/profile">My Profile</a>
Token:
<br />
{authState.accessToken}
</p>
</div>
)}
Expand Down
20 changes: 20 additions & 0 deletions src/views/Home.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { shallow } from 'enzyme'
import Home from './Home'

jest.mock('@okta/okta-react', () => ({
useOktaAuth: () => {
return {
authState: {},
authService: {}
}
}
}))

describe('Home component', () => {
const component = shallow(<Home />)

it('renders without crashing', () => {
expect(component.length).toBe(1)
})
})
5 changes: 0 additions & 5 deletions src/views/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const Navbar = () => {
<Menu.Item as="a" header href="/">
GitWize
</Menu.Item>
{authState.isAuthenticated && (
<Menu.Item id="profile-button" as="a" href="/profile">
Profile
</Menu.Item>
)}
{authState.isAuthenticated && (
<Menu.Item id="logout-button" as="a" onClick={logout}>
Logout
Expand Down
57 changes: 0 additions & 57 deletions src/views/Profile.js

This file was deleted.

7 changes: 4 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
exclude: /node_modules/,
loader: 'babel-loader'
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{
test: /\.(jpg|png|gif|jpeg|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
Expand All @@ -29,8 +29,9 @@ module.exports = {
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.config().parsed)
})],
'process.env': JSON.stringify(dotenv.config().parsed)
})
],
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname, 'public'),
Expand Down

0 comments on commit 3d46ab9

Please sign in to comment.