Skip to content

Commit 4f9be9c

Browse files
Enoah NetzachEnoahNetzach
authored andcommitted
Add various features to test
1 parent 07476b9 commit 4f9be9c

File tree

9 files changed

+71
-14
lines changed

9 files changed

+71
-14
lines changed
Loading

packages/react-scripts/templates/kitchensink/src/App.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
// @flow
22
import React, { Component } from 'react';
3-
import logo from './logo.svg';
4-
import './App.css';
5-
import EnvVariableMessages from './EnvVariableMessages';
63
// testing absolute imports using NODE_PATH=src
74
import CommentsList from 'CommentsList';
85
import UsersList from 'UsersList';
6+
import logo from './logo.svg';
7+
import './App.css';
8+
import EnvVariableMessages from './EnvVariableMessages';
9+
import { abstract } from './abstract.json';
10+
import verySmallImage from './1x1-img.jpg';
11+
import aFileWithoutExt from './aFileWithoutExt';
12+
import aFileWithUnknownExt from './aFileWithExt.unknown'
13+
import aDeepJsModule from './subfolder/lol'
914

1015
class App extends Component {
1116
render() {
1217
const templateName : string = "Kitchen Sink"
1318
return (
1419
<div className="App">
1520
<div className="App-header">
16-
<img src={logo} className="App-logo" alt="logo" />
21+
<img id="svg-import" src={logo} className="App-logo" alt="logo" />
1722
<h2>Welcome to the {templateName} Template</h2>
1823
</div>
19-
<p className="App-intro">
20-
To get started, edit <code>src/App.js</code> and save to reload.
21-
</p>
24+
25+
<details>
26+
<summary>
27+
{abstract}
28+
</summary>
29+
30+
<p className="App-intro">
31+
To get started, edit <code>src/App.js</code> and save to reload.
32+
</p>
33+
</details>
34+
35+
<img id="img-import" src={verySmallImage} alt="a very small cat" />
36+
37+
<span id="no-ext-import">{aFileWithoutExt}</span>
38+
<span id="unknown-ext-import">{aFileWithUnknownExt}</span>
39+
<span id="subfolder-js-import">{aDeepJsModule()} {aDeepJsModule.toString()}</span>
40+
2241
<EnvVariableMessages />
2342
<UsersList />
2443
<CommentsList user="User 1" />

packages/react-scripts/templates/kitchensink/src/CommentsList.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import React, { Component, PropTypes } from 'react';
33
import loadComments from './loadComments';
44

5+
const previousComments = {
6+
'idOld': { id: 'old', body: 'comment old' },
7+
};
8+
59
class CommentsList extends Component {
610
static propTypes = {
711
user: PropTypes.string,
@@ -13,7 +17,11 @@ class CommentsList extends Component {
1317
} = { loading: true, comments: [] };
1418

1519
componentDidMount() {
16-
loadComments().then(comments => this.setState({ loading: false, comments }))
20+
loadComments({ max: 4, ...previousComments })
21+
.then(comments => {
22+
const commentArray = Object.keys(comments).map(key => comments[key]);
23+
this.setState({ loading: false, comments: commentArray });
24+
})
1725
}
1826

1927
render() {
@@ -25,7 +33,7 @@ class CommentsList extends Component {
2533
{
2634
loading
2735
? <div>Comments are loading</div>
28-
: <ul>{comments.map((comment, i) => <li key={i}>{comment}</li>)}</ul>
36+
: <ul>{comments.map((comment) => <li key={comment.id}>{`message: ${comment.body}`}</li>)}</ul>
2937
}
3038
</div>
3139
)

packages/react-scripts/templates/kitchensink/src/UsersList.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import React, { Component } from 'react';
33
import userGenerator from './userGenerator';
44

5+
const styled = ([style]) => style.trim()
6+
.split(/\s*;\s*/)
7+
.map(rule => rule.split(/\s*:\s*/))
8+
.reduce((rules, rule) => ({ ...rules, [rule[0]]: rule[1] }), {})
9+
510
class UsersList extends Component {
611
static defaultProps: { limit: number } = { limit: 5 };
712

@@ -17,11 +22,16 @@ class UsersList extends Component {
1722
}
1823

1924
render() {
25+
const veryInlineStyle = styled`
26+
background: palevioletred;
27+
color: papayawhip;
28+
`;
29+
2030
return (
2131
<div>
2232
<h3>Users</h3>
2333
<ul>
24-
{this.state.users.map((user, i) => <li key={i}>{user}</li>)}
34+
{this.state.users.map((user, i) => <li key={i} style={veryInlineStyle}>{user}</li>)}
2535
</ul>
2636
</div>
2737
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
whoooo, spooky!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is just a file without an extension
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"abstract": "This is an abstract"
3+
}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
// @flow
22
function fakeApiCall() : Promise<string[]> {
3-
return Promise.resolve({ comments: ['Comment 1', 'Comment 2', 'Comment 3'] })
3+
return Promise.resolve({
4+
comments: {
5+
'id1': { id: 1, body: 'comment 1' },
6+
'id2': { id: 2, body: 'comment 2' },
7+
'id3': { id: 3, body: 'comment 3' },
8+
'id4': { id: 3, body: 'comment 4' },
9+
}
10+
});
411
}
512

6-
export default async function loadComments() : Promise<string[]> {
7-
const { comments } = await fakeApiCall();
8-
return comments;
13+
export default async function loadComments({ max, ...comments } = {}) : Promise<string[]> {
14+
const { comments: fetchedComments } = await fakeApiCall();
15+
const totalComments = {
16+
...comments,
17+
...fetchedComments,
18+
};
19+
20+
return Object.keys(totalComments)
21+
.slice(0, max)
22+
.reduce((slicedComments, key) => ({ ...slicedComments, [key]: totalComments[key] }), {});
923
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = function() { return `haha` }

0 commit comments

Comments
 (0)