-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathconnect.spec.ts
245 lines (206 loc) · 6.51 KB
/
connect.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// import {
// ComponentFixtureNoNgZone,
// TestBed,
// fakeAsync,
// flushMicrotasks,
// inject,
// tick,
// } from '@angular/core/testing';
// import { Component } from '@angular/core';
// import {
// FormsModule,
// ReactiveFormsModule,
// } from '@angular/forms';
// import {
// Store,
// applyMiddleware,
// compose,
// combineReducers,
// createStore,
// } from 'redux';
// import { composeReducers } from '../compose-reducers';
// import { defaultFormReducer } from '../form-reducer';
// import { provideReduxForms } from '../configure';
// import { NgReduxFormModule } from '../module';
// import { logger, simulateUserTyping } from '../tests.utilities';
// interface AppState {
// fooState?: FooState;
// }
// interface FooState {
// example: string;
// deepInside: {
// foo: string;
// };
// bar: string;
// checkExample: boolean;
// }
// const initialState: FooState = {
// example: 'Test!',
// deepInside: {
// foo: 'Bar!',
// },
// bar: 'two',
// checkExample: true,
// };
// const testReducer = (state = initialState, _ = { type: '' }) => {
// return state;
// };
// const reducers = composeReducers(
// combineReducers({
// fooState: testReducer,
// }),
// defaultFormReducer(),
// );
// @Component({
// selector: 'test-component-1',
// template: `
// <form connect="fooState">
// <input type="text" name="example" ngControl ngModel />
// </form>
// `,
// })
// export class BasicUsageComponent {}
// @Component({
// selector: 'test-component-2',
// template: `
// <form connect="fooState.deepInside">
// <input type="text" name="foo" ngControl ngModel />
// </form>
// `,
// })
// export class DeepConnectComponent {}
// @Component({
// selector: 'test-component-3',
// template: `
// <form connect="fooState">
// <input type="checkbox" name="checkExample" ngControl ngModel />
// </form>
// `,
// })
// export class CheckboxComponent {}
// @Component({
// selector: 'test-component-4',
// template: `
// <form connect="fooState">
// <select name="bar" ngControl ngModel>
// <option value="none">None</option>
// <option value="one">One</option>
// <option value="two">Two</option>
// </select>
// </form>
// `,
// })
// export class SelectComponent {}
// @Component({
// selector: 'test-component-5',
// template: `
// <form connect="fooState">
// <input type="text" name="bar" ngControl ngModel />
// </form>
// `,
// })
// export class UpdateTextComponent {}
describe('connect directive', () => {
it('should have a fake test for now until we can fix them...', () =>
undefined);
// let store: Store<AppState>;
// beforeEach(done => {
// const create = compose(applyMiddleware(logger))(createStore);
// store = create(reducers, <AppState>{});
// TestBed.configureCompiler({
// providers: [{ provide: ComponentFixtureNoNgZone, useValue: true }],
// });
// TestBed.configureTestingModule({
// imports: [FormsModule, ReactiveFormsModule, NgReduxFormModule],
// declarations: [
// BasicUsageComponent,
// DeepConnectComponent,
// CheckboxComponent,
// SelectComponent,
// UpdateTextComponent,
// ],
// providers: [provideReduxForms(store)],
// });
// TestBed.compileComponents().then(() => done());
// });
// it(
// 'should bind all form controls to application state',
// fakeAsync(
// inject([], () => {
// const fixture = TestBed.createComponent(BasicUsageComponent);
// fixture.detectChanges();
// tick();
// flushMicrotasks();
// const textbox = fixture.nativeElement.querySelector('input');
// expect(textbox.value).toEqual('Test!');
// }),
// ),
// );
// it('should bind a form control to element deep inside application state', () => {
// return fakeAsync(
// inject([], () => {
// const fixture = TestBed.createComponent(DeepConnectComponent);
// fixture.detectChanges();
// tick();
// flushMicrotasks();
// const textbox = fixture.nativeElement.querySelector('input');
// expect(textbox.value).toEqual('Bar!');
// }),
// );
// });
// it(
// 'should bind a checkbox to a boolean state',
// fakeAsync(
// inject([], () => {
// const fixture = TestBed.createComponent(CheckboxComponent);
// fixture.detectChanges();
// tick();
// flushMicrotasks();
// const checkbox = fixture.nativeElement.querySelector(
// 'input[type="checkbox"]',
// );
// expect(checkbox.checked).toEqual(true);
// }),
// ),
// );
// it(
// 'should bind a select dropdown to application state',
// fakeAsync(
// inject([], () => {
// const fixture = TestBed.createComponent(SelectComponent);
// fixture.detectChanges();
// tick();
// flushMicrotasks();
// const select = fixture.nativeElement.querySelector('select');
// expect(select.value).toEqual('two');
// // TODO(cbond): How to simulate a click-select sequence on this control?
// // Just updating `value' does not appear to invoke all of the Angular
// // change routines and therefore does not update Redux. But manually clicking
// // and selecting does. Need to find a way to simulate that sequence.
// }),
// ),
// );
// it(
// 'should update Redux state when the user changes the value of a control',
// fakeAsync(
// inject([], () => {
// const fixture = TestBed.createComponent(UpdateTextComponent);
// fixture.detectChanges();
// tick();
// flushMicrotasks();
// // validate initial data before we do the UI tests
// let state = store.getState();
// expect(state.fooState.bar).toEqual('two');
// const textbox = fixture.nativeElement.querySelector('input');
// expect(textbox.value).toEqual('two');
// return simulateUserTyping(textbox, 'abc').then(() => {
// tick();
// flushMicrotasks();
// expect(textbox.value).toEqual('twoabc');
// state = store.getState();
// expect(state.fooState.bar).toEqual('twoabc');
// });
// }),
// ),
// );
});