Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 84c8d5c

Browse files
committed
added naming to nested forms for validation purposes
1 parent 80760d6 commit 84c8d5c

File tree

10 files changed

+72
-33
lines changed

10 files changed

+72
-33
lines changed

source/components/cardContainer/card/card.tests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ interface ICardContainerMock {
1414
columnTemplates?: any;
1515
}
1616

17+
interface IGuidServiceMock {
18+
random: Sinon.SinonSpy;
19+
}
20+
1721
describe('CardComponent', () => {
1822
let card: CardComponent<any>;
1923
let cardContainer: ICardContainerMock;
24+
let mockGuidService: IGuidServiceMock;
2025

2126
beforeEach(() => {
2227
cardContainer = {
@@ -25,8 +30,9 @@ describe('CardComponent', () => {
2530
remove: sinon.spy(),
2631
},
2732
};
33+
mockGuidService = { random: sinon.spy() };
2834

29-
card = new CardComponent(new __notification.NotificationService(<any>{}, <any>{}), null, new FormService(), null, <any>cardContainer);
35+
card = new CardComponent(new __notification.NotificationService(<any>{}, <any>{}), null, new FormService(), mockGuidService, null, <any>cardContainer);
3036
});
3137

3238
it('should pass the item to the save handler', (): void => {

source/components/cardContainer/card/card.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ export class CardComponent<T> extends FormComponent {
4848
cardContainer: CardContainerComponent<T>;
4949

5050
constructor(notification: __notification.NotificationService
51-
, asyncHelper: AsyncHelper
52-
, formService: FormService
53-
, @Optional() @SkipSelf() parentForm: FormComponent
54-
, @Inject(forwardRef(() => CardContainerComponent)) cardContainer: CardContainerComponent<T>) {
55-
super(notification, asyncHelper, formService, parentForm);
51+
, asyncHelper: AsyncHelper
52+
, formService: FormService
53+
, guidService: services.guid.GuidService
54+
, @Optional() @SkipSelf() parentForm: FormComponent
55+
, @Inject(forwardRef(() => CardContainerComponent)) cardContainer: CardContainerComponent<T>) {
56+
57+
super(notification, asyncHelper, formService, guidService, parentForm);
5658
this.cardContainer = cardContainer;
5759
this.showContent$ = new BehaviorSubject(false);
5860
}

source/components/cardContainer/card/selectableCard.tests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ interface ICardContainerMock {
99
setSelected: Sinon.SinonSpy;
1010
}
1111

12+
interface IGuidServiceMock {
13+
random: Sinon.SinonSpy;
14+
}
15+
1216
describe('SelectableCardComponent', () => {
1317
let card: SelectableCardComponent<any>;
1418
let cardContainer: ICardContainerMock;
19+
let mockGuidService: IGuidServiceMock;
1520

1621
beforeEach(() => {
1722
cardContainer = {
1823
setSelected: sinon.spy(),
1924
};
25+
mockGuidService = { random: sinon.spy() };
2026

21-
card = new SelectableCardComponent(new __notification.NotificationService(<any>{}, <any>{}), null, new FormService(), null, <any>cardContainer);
27+
card = new SelectableCardComponent(new __notification.NotificationService(<any>{}, <any>{}), null, new FormService(), mockGuidService, null, <any>cardContainer);
2228
const randomId = 11;
2329
card.selection = <any>{ id: randomId };
2430
});

source/components/cardContainer/card/selectableCard.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ export class SelectableCardComponent<T> extends CardComponent<T> {
3636
}
3737

3838
constructor(notification: __notification.NotificationService
39-
, asyncHelper: AsyncHelper
40-
, formService: FormService
41-
, @Optional() @SkipSelf() parentForm: FormComponent
42-
, @Inject(forwardRef(() => CardContainerComponent)) cardContainer: CardContainerComponent<T>) {
43-
super(notification, asyncHelper, formService, parentForm, cardContainer);
39+
, asyncHelper: AsyncHelper
40+
, formService: FormService
41+
, guidService: services.guid.GuidService
42+
, @Optional() @SkipSelf() parentForm: FormComponent
43+
, @Inject(forwardRef(() => CardContainerComponent)) cardContainer: CardContainerComponent<T>) {
44+
super(notification, asyncHelper, formService, guidService, parentForm, cardContainer);
4445
}
4546

4647
setSelected(value: boolean): void {

source/components/dialog/dialog.tests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import { DialogRootService, IDialogClosingHandler } from './dialogRoot.service';
66

77
import { AsyncHelper } from '../../services/async/async.service';
88

9+
interface IGuidServiceMock {
10+
random: Sinon.SinonSpy;
11+
}
12+
913
describe('DialogComponent', (): void => {
1014
let dialog: DialogComponent;
1115
let dialogRoot: DialogRootService;
16+
let mockGuidService: IGuidServiceMock;
1217

1318
beforeEach((): void => {
1419
dialogRoot = new DialogRootService();
15-
dialog = new DialogComponent(<any>{}, new AsyncHelper(), null, dialogRoot);
20+
mockGuidService = { random: sinon.spy() };
21+
dialog = new DialogComponent(<any>{}, new AsyncHelper(), null, dialogRoot, mockGuidService);
1622
});
1723

1824
it('should open a dialog on the root with the current dialog\'s context', (): void => {

source/components/dialog/dialog.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ export class DialogComponent extends FormComponent {
3333
dialogRoot: DialogRootService;
3434

3535
constructor(notification: __notification.NotificationService
36-
, asyncHelper: AsyncHelper
37-
, formService: FormService
38-
, dialogRoot: DialogRootService) {
39-
super(notification, asyncHelper, formService, null);
36+
, asyncHelper: AsyncHelper
37+
, formService: FormService
38+
, dialogRoot: DialogRootService
39+
, guidService: services.guid.GuidService) {
40+
41+
super(notification, asyncHelper, formService, guidService, null);
4042
this.dialogRoot = dialogRoot;
4143
}
4244

source/components/form/form.tests.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ interface IFormServiceMock {
1515
getAggregateError?: Sinon.SinonSpy;
1616
}
1717

18+
interface IGuidServiceMock {
19+
random: Sinon.SinonSpy;
20+
}
21+
1822
describe('FormComponent', (): void => {
1923
let form: FormComponent;
2024
let notification: INotificationMock;
2125
let formService: IFormServiceMock;
26+
let mockGuidService: IGuidServiceMock;
2227

2328
beforeEach((): void => {
2429
notification = { warning: sinon.spy() };
2530
formService = {};
31+
mockGuidService = { random: sinon.spy() };
2632

27-
form = new FormComponent(<any>notification, new AsyncHelper(), <any>formService, null);
33+
form = new FormComponent(<any>notification, new AsyncHelper(), <any>formService, mockGuidService, null);
2834
form.form = <any>{
2935
markAsPristine: sinon.spy(),
3036
};
@@ -53,7 +59,7 @@ describe('FormComponent', (): void => {
5359
addControl: addControlSpy,
5460
},
5561
};
56-
form = new FormComponent(<any>notification, new AsyncHelper(), <any>formService, parentForm);
62+
form = new FormComponent(<any>notification, new AsyncHelper(), <any>formService, mockGuidService, parentForm);
5763

5864
sinon.assert.calledOnce(addControlSpy);
5965
sinon.assert.calledWith(addControlSpy, '', form.form);

source/components/form/form.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ export class FormComponent {
3939
}
4040

4141
constructor(notification: __notification.NotificationService
42-
, asyncHelper: AsyncHelper
43-
, formService: FormService
44-
, @Optional() @SkipSelf() parentForm: FormComponent) {
42+
, asyncHelper: AsyncHelper
43+
, formService: FormService
44+
, guidService: services.guid.GuidService
45+
, @Optional() @SkipSelf() parentForm: FormComponent) {
46+
4547
this.notification = notification;
4648
this.asyncHelper = asyncHelper;
4749
this.formService = formService;
@@ -51,7 +53,7 @@ export class FormComponent {
5153
}
5254

5355
if (parentForm) {
54-
parentForm.form.addControl('', this.form);
56+
parentForm.form.addControl(`form-${guidService.random()}`, this.form);
5557
}
5658
}
5759

@@ -76,7 +78,7 @@ export class FormComponent {
7678
}
7779

7880
validate(): boolean {
79-
return this.form.valid;
81+
return !this.form.invalid;
8082
}
8183

8284
reset(): void {

source/components/simpleCardList/simpleCard.tests.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@ interface IFormMock {
99
submit: Sinon.SinonSpy;
1010
}
1111

12+
interface IGuidServiceMock {
13+
random: Sinon.SinonSpy;
14+
}
15+
1216
describe('SimpleCardComponent', () => {
1317
let card: SimpleCardComponent<any>;
1418
let list: IListMock;
19+
let mockGuidService: IGuidServiceMock;
1520

1621
beforeEach(() => {
1722
list = {
1823
openCard: sinon.spy(() => true),
1924
};
25+
mockGuidService = { random: sinon.spy() };
2026

21-
card = new SimpleCardComponent(<any>{}, null, null, null, null, <any>list);
27+
card = new SimpleCardComponent(<any>{}, null, null, mockGuidService, null, null, <any>list);
2228
});
2329

2430
it('should create an empty list if no list is provided', (): void => {
25-
card = new SimpleCardComponent(null, null, null, null, null, null);
31+
card = new SimpleCardComponent(null, null, null, mockGuidService, null, null, null);
2632
expect(card.list).to.exist;
2733
});
2834

@@ -80,7 +86,7 @@ describe('SimpleCardComponent', () => {
8086
});
8187

8288
it('should be able to open with an empty list', (): void => {
83-
card = new SimpleCardComponent(null, null, null, null, null, null);
89+
card = new SimpleCardComponent(null, null, null, mockGuidService, null, null, null);
8490
const onOpenSpy: Sinon.SinonSpy = sinon.spy();
8591
card.onOpen.emit = onOpenSpy;
8692
card.ngOnInit();

source/components/simpleCardList/simpleCard.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ export class SimpleCardComponent<T> extends FormComponent implements OnInit {
3636
alternatingClass: string = '';
3737

3838
constructor(notification: __notification.NotificationService
39-
, asyncHelper: AsyncHelper
40-
, formService: FormService
41-
, @Optional() @SkipSelf() parentForm: FormComponent
42-
, @Optional() nullInjectionConflictsWithCardParameter: AsyncHelper
43-
, @Optional() @Inject(forwardRef(() => SimpleCardListComponent)) list: SimpleCardListComponent<T>) {
44-
super(notification, asyncHelper, formService, parentForm);
39+
, asyncHelper: AsyncHelper
40+
, formService: FormService
41+
, guidService: services.guid.GuidService
42+
, @Optional() @SkipSelf() parentForm: FormComponent
43+
, @Optional() nullInjectionConflictsWithCardParameter: AsyncHelper
44+
, @Optional() @Inject(forwardRef(() => SimpleCardListComponent)) list: SimpleCardListComponent<T>) {
45+
46+
super(notification, asyncHelper, formService, guidService, parentForm);
4547
this.list = list || this.emptyList();
4648
}
4749

0 commit comments

Comments
 (0)