Skip to content

Commit 5daf6e7

Browse files
authored
Merge pull request #4 from helpdotcom/CE/HELP-6485
Bumped to Material 4.x Added failing test. quality of life improvements.
2 parents 1ffe910 + 04d50ac commit 5daf6e7

File tree

8 files changed

+6283
-4075
lines changed

8 files changed

+6283
-4075
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The 3 priorities that we provide you are:
1414

1515
1. Messages should be rendered in a table-like structure. The newest messages should appear at the top of their respective columns.
1616

17-
Note: The example design below.
17+
1a. Use the mockup below. It contains some inconsistencies. Please ensure that your app represents a good faith effort at matching the mockup within reason. We welcome follow up questions if you have them.
1818

1919
![Example Design](https://github.com/helpdotcom/react-coding-challenge/raw/master/grid.png)
2020

@@ -31,6 +31,6 @@ Note: The example design below.
3131
6. A user should be able to start and stop incoming messages. By default the messages should be running and displaying on the grid. The start/stop button should update depending on the state of the feed.
3232
7. A user should see a count of specific messages in each column
3333
8. Use material-ui components and JSS styles.
34-
9. Test your application to the degree that you feel comfortable with. No specific testing frameworks are required.
34+
9. Test your application to the degree that you feel comfortable with. No specific testing frameworks are required. We have left a failing test for a breadcrumb.
3535

3636
*** Applicants are provided this challenge with no expectation on deadline. Please take the time you need to complete the challenge to the best of your ability. ***

package-lock.json

Lines changed: 6232 additions & 4042 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
"author": "Help.com",
1212
"license": "No license",
1313
"dependencies": {
14-
"@material-ui/core": "^3.8.2",
15-
"chance": "^0.8.0",
16-
"lodash": "^4.17.2",
17-
"prop-types": "^15.5.8",
18-
"react": "^16.8.6",
19-
"react-dom": "^16.8.6",
20-
"react-scripts": "^3.0.1"
14+
"@material-ui/core": "^4.9.3",
15+
"@material-ui/lab": "^4.0.0-alpha.43",
16+
"chance": "^1.1.4",
17+
"lodash.random": "^3.2.0",
18+
"prop-types": "^15.7.2",
19+
"react": "^16.12.0",
20+
"react-dom": "^16.12.0",
21+
"react-scripts": "^3.4.0"
22+
},
23+
"devDependencies": {
24+
"@testing-library/jest-dom": "^5.1.1",
25+
"@testing-library/react": "^9.4.0"
2126
},
22-
"devDependencies": {},
2327
"browserslist": {
2428
"production": [
2529
">0.2%",

src/api.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Chance from 'chance'
2-
import lodash from 'lodash'
2+
import random from 'lodash.random'
33

4+
/**
5+
* Do not edit this file.
6+
*/
47
class MessageGenerator {
58
constructor(options) {
69
this.messageCallback = options.messageCallback
@@ -28,12 +31,14 @@ class MessageGenerator {
2831
if (this.stopGeneration) {
2932
return
3033
}
31-
const message = this.chance.string()
32-
const priority = lodash.random(1, 3)
33-
const nextInMS = lodash.random(500, 3000)
34+
const message = this.chance.sentence({ words: 3 })
35+
const id = this.chance.guid()
36+
const priority = random(1, 3)
37+
const nextInMS = random(500, 3000)
3438
this.messageCallback({
3539
message,
3640
priority,
41+
id
3742
})
3843
setTimeout(() => {
3944
this.generate()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { render } from '@testing-library/react'
3+
import MessageList from '../message-list'
4+
5+
describe('message-list', () => {
6+
it('is a blank slate to write tests in', () => {
7+
const { container } = render(<MessageList />)
8+
expect(container).not.toBeVisible()
9+
})
10+
})

src/components/message-list.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import Button from '@material-ui/core/Button'
33
import Api from '../api'
44

5-
class MessageList extends Component {
5+
class MessageList extends React.PureComponent {
66
constructor(...args) {
77
super(...args)
88
this.state = {
@@ -33,29 +33,26 @@ class MessageList extends Component {
3333
})
3434
}
3535

36-
renderButton() {
36+
handleClick = () => {
3737
const isApiStarted = this.api.isStarted()
38-
return (
39-
<Button
40-
variant="contained"
41-
onClick={() => {
42-
if (isApiStarted) {
43-
this.api.stop()
44-
} else {
45-
this.api.start()
46-
}
47-
this.forceUpdate()
48-
}}
49-
>
50-
{isApiStarted ? 'Stop Messages' : 'Start Messages'}
51-
</Button>
52-
)
38+
if (isApiStarted) {
39+
this.api.stop()
40+
} else {
41+
this.api.start()
42+
}
43+
this.forceUpdate()
5344
}
5445

5546
render() {
47+
const isApiStarted = this.api.isStarted()
5648
return (
5749
<div>
58-
{this.renderButton()}
50+
<Button
51+
variant="contained"
52+
onClick={this.handleClick}
53+
>
54+
{isApiStarted ? 'Stop Messages' : 'Start Messages'}
55+
</Button>
5956
</div>
6057
)
6158
}

src/setupTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/extend-expect'

0 commit comments

Comments
 (0)