@@ -3,11 +3,33 @@ import configureStore from 'redux-mock-store';
3
3
import thunk from 'redux-thunk' ;
4
4
import { unmountComponentAtNode } from 'react-dom' ;
5
5
import { act } from 'react-dom/test-utils' ;
6
- import { reduxRender , prettyDOM } from '../../../test-utils' ;
6
+ import moxios from 'moxios' ;
7
+ import * as ProjectActions from '../actions/projects' ;
8
+ import * as ActionTypes from '../../../constants' ;
7
9
import SketchList from './SketchList' ;
10
+ import { reduxRender , fireEvent , screen } from '../../../test-utils' ;
8
11
9
12
const mockStore = configureStore ( [ thunk ] ) ;
10
13
14
+ const mockProjects = [
15
+ {
16
+ name : 'testsketch1' ,
17
+ _id : 'testid1' ,
18
+ updatedAt : '2021-02-26T04:58:29.390Z' ,
19
+ files : [ ] ,
20
+ createdAt : '2021-02-26T04:58:14.136Z' ,
21
+ id : 'testid1'
22
+ } ,
23
+ {
24
+ name : 'testsketch2' ,
25
+ _id : 'testid2' ,
26
+ updatedAt : '2021-02-23T17:40:43.789Z' ,
27
+ files : [ ] ,
28
+ createdAt : '2021-02-23T17:40:43.789Z' ,
29
+ id : 'testid2'
30
+ }
31
+ ] ;
32
+
11
33
const initialTestState = {
12
34
ide : null ,
13
35
files : [ ] ,
@@ -23,24 +45,7 @@ const initialTestState = {
23
45
authenticated : true
24
46
} ,
25
47
project : null ,
26
- sketches : [
27
- {
28
- name : 'testsketch1' ,
29
- _id : 'testid1' ,
30
- updatedAt : '2021-02-26T04:58:29.390Z' ,
31
- files : [ ] ,
32
- createdAt : '2021-02-26T04:58:14.136Z' ,
33
- id : 'testid1'
34
- } ,
35
- {
36
- name : 'testsketch2' ,
37
- _id : 'testid2' ,
38
- updatedAt : '2021-02-23T17:40:43.789Z' ,
39
- files : [ ] ,
40
- createdAt : '2021-02-23T17:40:43.789Z' ,
41
- id : 'testid2'
42
- }
43
- ] ,
48
+ sketches : mockProjects ,
44
49
search : {
45
50
collectionSearchTerm : '' ,
46
51
sketchSearchTerm : ''
@@ -64,24 +69,81 @@ describe('<Sketchlist />', () => {
64
69
// setup a DOM element as a render target
65
70
container = document . createElement ( 'div' ) ;
66
71
document . body . appendChild ( container ) ;
67
- store = mockStore ( initialTestState ) ;
68
72
} ) ;
69
73
70
74
afterEach ( ( ) => {
71
75
// cleanup on exiting
72
76
unmountComponentAtNode ( container ) ;
73
77
container . remove ( ) ;
74
78
container = null ;
79
+ store . clearActions ( ) ;
75
80
} ) ;
76
81
77
- describe ( '<SketchListRow />' , ( ) => {
78
- it ( 'render' , ( ) => {
79
- let component ;
80
- // render the component with autosave set to false as default
81
- act ( ( ) => {
82
- component = reduxRender ( < SketchList /> , { store, container } ) ;
83
- } ) ;
84
- console . log ( prettyDOM ( container ) ) ;
82
+ // it('creates GET_PROJECTS after successfuly fetching projects', async () => {
83
+ // moxios.install();
84
+ // function resolveAfter2Seconds() {
85
+ // console.log("called resolve");
86
+ // return new Promise(resolve => {
87
+ // setTimeout(() => {
88
+ // resolve('resolved');
89
+ // }, 5000);
90
+ // });
91
+ // }
92
+ // console.log("moxios", moxios);
93
+ // moxios.wait(() => {
94
+
95
+ // const request = moxios.requests.mostRecent();
96
+ // console.log(moxios.requests, request)
97
+ // console.log("recieved request for get projects")
98
+ // request.respondWith({
99
+ // status: 200,
100
+ // response: mockProjects,
101
+ // }).then(() => done());
102
+ // });
103
+
104
+ // const expectedActions = [
105
+ // {type: ActionTypes.START_LOADING},
106
+ // { type: ActionTypes.SET_PROJECTS,
107
+ // projects: mockProjects }
108
+ // ];
109
+
110
+ // store = mockStore(initialTestState);
111
+ // console.log("dispatching action");
112
+ // //store.dispatch(ProjectActions.getProjects("happydog"))
113
+ // act(() => {
114
+ // reduxRender(<SketchList />, { store, container });
115
+ // });
116
+
117
+ // const hasSetProjectKey = (currActions) => {
118
+ // return currActions.filter(ac => ac.type === ActionTypes.SET_PROJECTS).length > 0;
119
+ // }
120
+
121
+ // await waitFor(() => expect(hasSetProjectKey(store.getActions())).toEqual(true));
122
+ // moxios.uninstall();
123
+ // //expect(store.getActions()).toEqual(expectedActions);
124
+ // //return resolveAfter2Seconds().then(res => console.log("resolved"))
125
+ // });
126
+
127
+ it ( 'has both of the sample projects' , ( ) => {
128
+ store = mockStore ( initialTestState ) ;
129
+ let component ;
130
+ act ( ( ) => {
131
+ component = reduxRender ( < SketchList /> , { store, container } ) ;
132
+ } ) ;
133
+ expect ( screen . getByText ( 'testsketch1' ) ) . toBeInTheDocument ( ) ;
134
+ expect ( screen . getByText ( 'testsketch2' ) ) . toBeInTheDocument ( ) ;
135
+ } ) ;
136
+
137
+ it ( 'clicking on date created row header dispatches a reordering action' , ( ) => {
138
+ store = mockStore ( initialTestState ) ;
139
+ let component ;
140
+ act ( ( ) => {
141
+ component = reduxRender ( < SketchList /> , { store, container } ) ;
142
+ } ) ;
143
+ act ( ( ) => {
144
+ fireEvent . click ( screen . getByTestId ( 'toggle-direction-createdAt' ) ) ;
85
145
} ) ;
146
+ const expectedAction = [ { type : 'TOGGLE_DIRECTION' , field : 'createdAt' } ] ;
147
+ expect ( store . getActions ( ) ) . toEqual ( expect . arrayContaining ( expectedAction ) ) ;
86
148
} ) ;
87
149
} ) ;
0 commit comments