Skip to content

Commit b75d957

Browse files
author
Martynas Žilinskas
committed
Refactoring test components names.
1 parent bcfb991 commit b75d957

File tree

8 files changed

+66
-65
lines changed

8 files changed

+66
-65
lines changed

packages/simplr-forms-core/__tests__/abstractions/base-field.test.tsx

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { spy } from "sinon";
55

66
import { FormStoresHandlerClass, FSHContainer } from "../../src/stores/form-stores-handler";
77
import { FormStore } from "../../src/stores/form-store";
8-
import { BasicForm } from "../basic-components/basic-form";
9-
import { BasicField } from "../basic-components/basic-field";
8+
import { MyTestForm } from "../test-components/test-form";
9+
import { MyTestField, MyFieldProps } from "../test-components/test-field";
1010
import { FormChildContext } from "../../src/contracts/form";
11-
import { MyFieldProps } from "../basic-components/basic-field";
1211

1312
describe("Field Base", () => {
1413
beforeEach(() => {
@@ -21,7 +20,7 @@ describe("Field Base", () => {
2120

2221
it("is rendered outside of Form", () => {
2322
expect(() => shallow(
24-
<BasicField name="fieldName"></BasicField>
23+
<MyTestField name="fieldName"></MyTestField>
2524
)).toThrow();
2625
});
2726

@@ -30,9 +29,9 @@ describe("Field Base", () => {
3029
const formId = "FORM_ID";
3130
const fieldName = "fieldName";
3231

33-
mount(<BasicForm formId={formId} >
34-
<BasicField name="fieldName"></BasicField>
35-
</BasicForm>);
32+
mount(<MyTestForm formId={formId} >
33+
<MyTestField name="fieldName"></MyTestField>
34+
</MyTestForm>);
3635

3736
const formStore = FormStoresHandler.GetStore(formId);
3837
const fieldId = formStore.GetFieldId(fieldName);
@@ -45,9 +44,9 @@ describe("Field Base", () => {
4544
const formId = "FORM_ID";
4645
const fieldName = "fieldName";
4746

48-
let form = mount(<BasicForm formId={formId}>
49-
<BasicField name="fieldName"></BasicField>
50-
</BasicForm>);
47+
let form = mount(<MyTestForm formId={formId}>
48+
<MyTestField name="fieldName"></MyTestField>
49+
</MyTestForm>);
5150

5251
let formStore = FormStoresHandler.GetStore(formId);
5352
const fieldId = formStore.GetFieldId(fieldName);
@@ -67,9 +66,9 @@ describe("Field Base", () => {
6766
const formId = "FORM_ID";
6867
const fieldName = "fieldName";
6968

70-
let form = mount(<BasicForm formId={formId}>
71-
<BasicField destroyOnUnmount={true} name="fieldName"></BasicField>
72-
</BasicForm>);
69+
let form = mount(<MyTestForm formId={formId}>
70+
<MyTestField destroyOnUnmount={true} name="fieldName"></MyTestField>
71+
</MyTestForm>);
7372

7473
let formStore = FormStoresHandler.GetStore(formId);
7574
const fieldId = formStore.GetFieldId(fieldName);
@@ -88,42 +87,42 @@ describe("Field Base", () => {
8887
expect(() => {
8988
const fieldName = "fieldName";
9089

91-
mount(<BasicForm>
92-
<BasicField name={fieldName}></BasicField>
93-
<BasicField name={fieldName}></BasicField>
94-
</BasicForm>);
90+
mount(<MyTestForm>
91+
<MyTestField name={fieldName}></MyTestField>
92+
<MyTestField name={fieldName}></MyTestField>
93+
</MyTestForm>);
9594
}).toThrow();
9695
});
9796

9897
it("throws when rendering an empty fieldName", () => {
9998
expect(() => {
100-
mount(<BasicForm>
101-
<BasicField name=""></BasicField>
102-
</BasicForm>);
99+
mount(<MyTestForm>
100+
<MyTestField name=""></MyTestField>
101+
</MyTestForm>);
103102
}).toThrow();
104103
});
105104

106105
it("throws when rendering an undefined fieldName", () => {
107106
expect(() => {
108-
mount(<BasicForm>
109-
<BasicField name={undefined as any}></BasicField>
110-
</BasicForm>);
107+
mount(<MyTestForm>
108+
<MyTestField name={undefined as any}></MyTestField>
109+
</MyTestForm>);
111110
}).toThrow();
112111
});
113112

114113
it("throws when rendering a null fieldName", () => {
115114
expect(() => {
116-
mount(<BasicForm>
117-
<BasicField name={null as any}></BasicField>
118-
</BasicForm>);
115+
mount(<MyTestForm>
116+
<MyTestField name={null as any}></MyTestField>
117+
</MyTestForm>);
119118
}).toThrow();
120119
});
121120

122121
it("renders html without wrappers", () => {
123122
const formId = "FORM_ID";
124-
let form = mount(<BasicForm formId={formId}>
125-
<BasicField name="fieldName"></BasicField>
126-
</BasicForm>);
123+
let form = mount(<MyTestForm formId={formId}>
124+
<MyTestField name="fieldName"></MyTestField>
125+
</MyTestForm>);
127126

128127
const formDOM = ReactDOM.findDOMNode(form.instance());
129128
expect(formDOM.tagName).toEqual("FORM");
@@ -134,9 +133,9 @@ describe("Field Base", () => {
134133
it("adds event listener to form store when mounts", () => {
135134
const FormStoresHandler = FSHContainer.FormStoresHandler;
136135
const formId = "FORM_ID";
137-
mount(<BasicForm formId={formId}>
138-
<BasicField name="fieldName"></BasicField>
139-
</BasicForm>);
136+
mount(<MyTestForm formId={formId}>
137+
<MyTestField name="fieldName"></MyTestField>
138+
</MyTestForm>);
140139

141140
const formStore = FormStoresHandler.GetStore(formId);
142141

@@ -146,9 +145,9 @@ describe("Field Base", () => {
146145
it("removes event listener form store when destroyOnUnmount is true and it is unmounted", () => {
147146
const FormStoresHandler = FSHContainer.FormStoresHandler;
148147
const formId = "FORM_ID";
149-
const form = mount(<BasicForm formId={formId} >
150-
<BasicField name="fieldName" destroyOnUnmount={true}></BasicField>
151-
</BasicForm>);
148+
const form = mount(<MyTestForm formId={formId} >
149+
<MyTestField name="fieldName" destroyOnUnmount={true}></MyTestField>
150+
</MyTestForm>);
152151

153152
const formStore = FormStoresHandler.GetStore(formId);
154153
expect(formStore.listenersCount()).toBe(1);
@@ -168,9 +167,9 @@ describe("Field Base", () => {
168167
spy(FormStore.prototype, "ValueChanged");
169168

170169
const fieldName = "fieldName";
171-
const form = mount(<BasicForm formId={formId}>
172-
<BasicField name={fieldName}></BasicField>
173-
</BasicForm>);
170+
const form = mount(<MyTestForm formId={formId}>
171+
<MyTestField name={fieldName}></MyTestField>
172+
</MyTestForm>);
174173
const formStore = FSHContainer.FormStoresHandler.GetStore(formId);
175174

176175
expect((FormStore.prototype.ValueChanged as any).callCount).toEqual(0);
@@ -192,9 +191,9 @@ describe("Field Base", () => {
192191
const newValue = "NEW_VALUE";
193192
const fieldName = "fieldName";
194193

195-
const form = mount(<BasicForm>
196-
<BasicField name={fieldName}></BasicField>
197-
</BasicForm>);
194+
const form = mount(<MyTestForm>
195+
<MyTestField name={fieldName}></MyTestField>
196+
</MyTestForm>);
198197

199198
const input = form.find("input");
200199

@@ -216,9 +215,9 @@ describe("Field Base", () => {
216215
value: "initialValue"
217216
};
218217

219-
mount(<BasicForm formId={formId}>
220-
<BasicField {...fieldProps} />
221-
</BasicForm>);
218+
mount(<MyTestForm formId={formId}>
219+
<MyTestField {...fieldProps} />
220+
</MyTestForm>);
222221
const formStore = FSHContainer.FormStoresHandler.GetStore(formId);
223222

224223
expect((formStore.GetField(fieldName).Props as MyFieldProps).value).toBe(fieldProps.value);
@@ -238,25 +237,25 @@ describe("Field Base", () => {
238237

239238
// Set spies on methods
240239
spy(FormStore.prototype, "UpdateProps");
241-
spy(BasicField.prototype, "componentWillReceiveProps");
240+
spy(MyTestField.prototype, "componentWillReceiveProps");
242241

243242
// Render form to create FormStore
244-
shallow(<BasicForm formId={formId}></BasicForm>);
243+
shallow(<MyTestForm formId={formId}></MyTestForm>);
245244

246245
const formStore = FSHContainer.FormStoresHandler.GetStore(formId);
247246

248247
// Mount with formId as a context
249-
const field = mount<MyFieldProps>(<BasicField {...fieldProps} />, {
248+
const field = mount<MyFieldProps>(<MyTestField {...fieldProps} />, {
250249
context: {
251250
FormId: formId
252251
} as FormChildContext
253252
});
254253

255-
// Update BasicField props
254+
// Update MyTestField props
256255
field.setProps(fieldPropsNext);
257256

258257
expect((FormStore.prototype.UpdateProps as any).callCount).toEqual(1);
259-
expect((BasicField.prototype.componentWillReceiveProps as any).callCount).toEqual(1);
258+
expect((MyTestField.prototype.componentWillReceiveProps as any).callCount).toEqual(1);
260259
expect((formStore.GetField(fieldId).Props as MyFieldProps).value).toBe(fieldPropsNext.value);
261260
});
262261
});

packages/simplr-forms-core/__tests__/abstractions/base-form.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import { shallow, mount } from "enzyme";
33

44
import { FSHContainer, FormStoresHandlerClass } from "../../src/stores/form-stores-handler";
5-
import { BasicForm } from "../basic-components/basic-form";
5+
import { MyTestForm } from "../test-components/test-form";
66

77
describe("Form base", () => {
88
beforeEach(() => {
@@ -12,13 +12,13 @@ describe("Form base", () => {
1212
describe("registers when", () => {
1313
it("formId is undefined and destroyOnUnmount prop is false", () => {
1414
expect(() => shallow(
15-
<BasicForm destroyOnUnmount={false}></BasicForm>
15+
<MyTestForm destroyOnUnmount={false}></MyTestForm>
1616
)).toThrow();
1717
});
1818

1919
it("formId is undefined and destroyOnUnmount prop is true", () => {
2020
const FormStoresHandler = FSHContainer.FormStoresHandler;
21-
let form = shallow(<BasicForm></BasicForm>);
21+
let form = shallow(<MyTestForm></MyTestForm>);
2222
let formId = (form.instance() as any).FormId;
2323

2424
expect(FormStoresHandler.Exists(formId)).toBe(true);
@@ -28,7 +28,7 @@ describe("Form base", () => {
2828
const FormStoresHandler = FSHContainer.FormStoresHandler;
2929
const FORM_ID = "custom-form-id";
3030
shallow(
31-
<BasicForm destroyOnUnmount={true} formId={FORM_ID}></BasicForm>
31+
<MyTestForm destroyOnUnmount={true} formId={FORM_ID}></MyTestForm>
3232
);
3333

3434
expect(FormStoresHandler.Exists(FORM_ID)).toBe(true);
@@ -39,15 +39,15 @@ describe("Form base", () => {
3939
// and destroyOnUnmount true second
4040
const FORM_ID = "custom-form-id";
4141

42-
mount(<BasicForm destroyOnUnmount={false} formId={FORM_ID}></BasicForm>);
43-
expect(() => mount(<BasicForm destroyOnUnmount={true} formId={FORM_ID}></BasicForm>)).toThrow();
42+
mount(<MyTestForm destroyOnUnmount={false} formId={FORM_ID}></MyTestForm>);
43+
expect(() => mount(<MyTestForm destroyOnUnmount={true} formId={FORM_ID}></MyTestForm>)).toThrow();
4444
});
4545

4646
it("another FormBase registered with the same formId", () => {
4747
// This is to check the case, when form is rendered with destroyOnUnmount false first
4848
// and destroyOnUnmount true second
4949
const FORM_ID = "custom-form-id";
50-
const formComponent = <BasicForm destroyOnUnmount={true} formId={FORM_ID}></BasicForm>;
50+
const formComponent = <MyTestForm destroyOnUnmount={true} formId={FORM_ID}></MyTestForm>;
5151

5252
shallow(formComponent);
5353
expect(() => shallow(formComponent)).toThrow();
@@ -57,7 +57,7 @@ describe("Form base", () => {
5757
describe("unregisters when", () => {
5858
it("formId is undefined and destroyOnUnmount prop is true", () => {
5959
const FormStoresHandler = FSHContainer.FormStoresHandler;
60-
let form = shallow(<BasicForm></BasicForm>);
60+
let form = shallow(<MyTestForm></MyTestForm>);
6161
let formId = (form.instance() as any).FormId;
6262

6363
form.unmount();
@@ -70,7 +70,7 @@ describe("Form base", () => {
7070
const FormStoresHandler = FSHContainer.FormStoresHandler;
7171
const formId = "custom-form-id";
7272
let form = mount(
73-
<BasicForm destroyOnUnmount={true} formId={formId}></BasicForm>
73+
<MyTestForm destroyOnUnmount={true} formId={formId}></MyTestForm>
7474
);
7575

7676
form.unmount();

packages/simplr-forms-core/__tests__/stores/form-store.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FormStore } from "../../src/stores/form-store";
55
import { FormError } from "../../src/contracts/error";
66
import { FieldStatePropsRecord, FieldStateProps } from "../../src/contracts/field";
77

8-
import { MyFieldProps } from "../basic-components/basic-field";
8+
import { MyFieldProps } from "../test-components/test-field";
99

1010
describe("Form store", () => {
1111
it("returns state", () => {

packages/simplr-forms-core/__tests__/basic-components/basic-field.tsx renamed to packages/simplr-forms-core/__tests__/test-components/test-field.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface MyFieldProps extends FieldProps {
1010

1111
export interface MyFieldState extends BaseFieldState { }
1212

13-
export class BasicField extends BaseField<MyFieldProps, MyFieldState> {
13+
export class MyTestField extends BaseField<MyFieldProps, MyFieldState> {
1414
render() {
1515
return <input type="text" onChange={this.onChange} value={this.state.Value} />;
1616
}

packages/simplr-forms-core/__tests__/basic-components/basic-form.tsx renamed to packages/simplr-forms-core/__tests__/test-components/test-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface MyFormProps extends FormProps {
99

1010
export interface MyFormState { }
1111

12-
export class BasicForm extends BaseForm<MyFormProps, MyFormState> {
12+
export class MyTestForm extends BaseForm<MyFormProps, MyFormState> {
1313
static defaultProps: MyFormProps = {
1414
...BaseForm.defaultProps,
1515
renderChildren: true

packages/simplr-forms-core/src/stores/form-stores-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class FormStoresHandlerClass extends ActionEmitter {
110110
* @memberOf FormStoreHandlerBase
111111
*/
112112
public Exists(formId: string) {
113-
return this.formStores.get(formId) != null;
113+
return this.formStores.has(formId);
114114
}
115115

116116
private resetFormStores() {

packages/simplr-forms-core/src/utils/form-error-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FormError } from "../contracts/error";
22

3-
export function IsFormError(value: any): value is FormError {
4-
return (value != null && (value as FormError).Message != null);
3+
export function IsFormError(error: any): error is FormError {
4+
return (error != null && (error as FormError).Message != null);
55
}
66

77
export function ConstructFormError(error: any) {

packages/simplr-forms-core/src/utils/value-helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export function IsComponentOfType(component: JSX.Element, requiredType: string)
4646

4747
export function RenderComponents<TComponent>(components: Array<JSX.Element>): Array<TComponent> {
4848
const virtualDiv = document.createElement("div");
49-
const renderedComponents = components.map(component => ReactDOM.render(component, virtualDiv) as any as TComponent);
49+
const renderedComponents = components.map(component => {
50+
return ReactDOM.render(component, virtualDiv) as any as TComponent;
51+
});
5052

5153
ReactDOM.unmountComponentAtNode(virtualDiv);
5254
return renderedComponents;

0 commit comments

Comments
 (0)