Skip to content

Commit 8e725cc

Browse files
committed
chore: change co-located test directory structure to support snapshots
1 parent de043c3 commit 8e725cc

File tree

8 files changed

+227
-11
lines changed

8 files changed

+227
-11
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import TodoForm from '../index';
3+
import { mount } from 'enzyme';
4+
5+
describe('TodoForm', () => {
6+
it('renders correctly', () => {
7+
const component = mount(<TodoForm />);
8+
expect(component).toMatchSnapshot();
9+
});
10+
11+
describe('clicking on submit button', () => {
12+
test('calls the onSubmit prop', () => {
13+
const mockSubmit = jest.fn();
14+
const component = mount(<TodoForm onSubmit={mockSubmit} />);
15+
16+
// test form submission
17+
component.setState({ todoText: 'Foobar' });
18+
component.find('form').simulate('submit');
19+
20+
expect(mockSubmit.mock.calls.length).toEqual(1);
21+
});
22+
});
23+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TodoForm renders correctly 1`] = `
4+
<TodoForm>
5+
<Form
6+
as="form"
7+
className="todoForm"
8+
onSubmit={[Function]}
9+
>
10+
<form
11+
className="ui form todoForm"
12+
onSubmit={[Function]}
13+
>
14+
<FormGroup>
15+
<div
16+
className="fields"
17+
>
18+
<FormInput
19+
as={[Function]}
20+
control={[Function]}
21+
onChange={[Function]}
22+
placeholder="Add a todo..."
23+
type="text"
24+
value=""
25+
>
26+
<FormField
27+
control={[Function]}
28+
onChange={[Function]}
29+
placeholder="Add a todo..."
30+
type="text"
31+
value=""
32+
>
33+
<div
34+
className="field"
35+
>
36+
<Input
37+
onChange={[Function]}
38+
placeholder="Add a todo..."
39+
type="text"
40+
value=""
41+
>
42+
<div
43+
className="ui input"
44+
>
45+
<input
46+
key="text"
47+
onChange={[Function]}
48+
placeholder="Add a todo..."
49+
type="text"
50+
value=""
51+
/>
52+
</div>
53+
</Input>
54+
</div>
55+
</FormField>
56+
</FormInput>
57+
<FormButton
58+
as={[Function]}
59+
content="Add"
60+
control={[Function]}
61+
icon="plus"
62+
>
63+
<FormField
64+
content="Add"
65+
control={[Function]}
66+
icon="plus"
67+
>
68+
<div
69+
className="field"
70+
>
71+
<Button
72+
as="button"
73+
content="Add"
74+
icon="plus"
75+
>
76+
<button
77+
className="ui button"
78+
onClick={[Function]}
79+
role="button"
80+
>
81+
<Icon
82+
as="i"
83+
key="plus"
84+
name="plus"
85+
>
86+
<i
87+
aria-hidden="true"
88+
className="plus icon"
89+
/>
90+
</Icon>
91+
Add
92+
</button>
93+
</Button>
94+
</div>
95+
</FormField>
96+
</FormButton>
97+
</div>
98+
</FormGroup>
99+
</form>
100+
</Form>
101+
</TodoForm>
102+
`;
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 TodoItem from '../index';
3+
import { shallow } from 'enzyme';
4+
5+
describe('TodoItem', () => {
6+
it('renders correctly', () => {
7+
const component = shallow(<TodoItem todo={{ id: 1, text: 'Work' }} />);
8+
expect(component).toMatchSnapshot();
9+
});
10+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TodoItem renders correctly 1`] = `
4+
<ListItem
5+
className="todo extra"
6+
>
7+
<ListContent
8+
floated="right"
9+
>
10+
<Button
11+
as="button"
12+
icon="remove"
13+
onClick={[Function]}
14+
size="mini"
15+
/>
16+
</ListContent>
17+
<ListContent
18+
floated="left"
19+
>
20+
<Checkbox
21+
onChange={[Function]}
22+
type="checkbox"
23+
/>
24+
</ListContent>
25+
<ListContent
26+
className="text"
27+
>
28+
Work
29+
</ListContent>
30+
</ListItem>
31+
`;

common/js/components/todos/TodoList/index.test.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import TodoList from '../index';
3+
import { shallow } from 'enzyme';
4+
5+
describe('TodoList', () => {
6+
let todos = {
7+
isFetched: true,
8+
todos: [
9+
{
10+
id: 1,
11+
text: 'Learn React',
12+
completed: true
13+
},
14+
{
15+
id: 2,
16+
text: 'Learn Redux',
17+
completed: true
18+
}
19+
]
20+
};
21+
22+
23+
it('renders correctly', () => {
24+
const component = shallow(<TodoList todos={todos} />);
25+
expect(component).toMatchSnapshot();
26+
});
27+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TodoList renders correctly 1`] = `
4+
<List
5+
className="todos"
6+
divided={true}
7+
>
8+
<TodoItem
9+
key="0"
10+
onChange={[Function]}
11+
onRemove={[Function]}
12+
todo={
13+
Object {
14+
"completed": true,
15+
"id": 1,
16+
"text": "Learn React",
17+
}
18+
}
19+
/>
20+
<TodoItem
21+
key="1"
22+
onChange={[Function]}
23+
onRemove={[Function]}
24+
todo={
25+
Object {
26+
"completed": true,
27+
"id": 2,
28+
"text": "Learn Redux",
29+
}
30+
}
31+
/>
32+
</List>
33+
`;

server/api/todos/todos.controller.test.js renamed to server/api/todos/spec/todos.controller.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import request from 'supertest';
22
import express from 'express';
3-
import todos from './index';
3+
import todos from '../index';
44

55
let app, agent;
66

0 commit comments

Comments
 (0)