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

Commit 440b6c4

Browse files
authored
Merge pull request #401 from jbeck8176/validation_Fix
Validation changes and additions
2 parents 74f0959 + d80f51d commit 440b6c4

File tree

14 files changed

+95
-35
lines changed

14 files changed

+95
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-angular-components",
3-
"version": "4.2.1",
3+
"version": "4.2.2",
44
"description": "Reusable responsive angular components",
55
"author": "Renovo Development Team",
66
"keywords": [

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/RecluseForm.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, forwardRef } from '@angular/core';
2+
import { FormGroup } from '@angular/forms';
3+
4+
import { FormComponent } from '../form/form';
5+
6+
@Component({
7+
selector: 'rlRecluseForm',
8+
template: '<ng-content></ng-content>',
9+
providers: [
10+
{
11+
provide: FormComponent,
12+
useExisting: forwardRef(() => RecluseFormComponent),
13+
},
14+
],
15+
})
16+
export class RecluseFormComponent {
17+
form = new FormGroup({});
18+
}

source/components/form/form.tests.ts

Lines changed: 9 additions & 3 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(() => { return '2979637a-1fc1-4c5e-bf9d-a89154342aba'}) };
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,10 +59,10 @@ 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);
59-
sinon.assert.calledWith(addControlSpy, '', form.form);
65+
sinon.assert.calledWith(addControlSpy, `form-${mockGuidService.random()}`, form.form);
6066
});
6167

6268
it('should reset the form', () => {

source/components/form/form.ts

Lines changed: 6 additions & 4 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

source/components/form/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { FormComponent } from './form';
22
import { INPUT_DIRECTIVES } from '../inputs/index';
33
import { AutosaveDirective } from '../../behaviors/autosave/autosave';
4+
import { RecluseFormComponent } from './RecluseForm';
45

5-
export const FORM_DIRECTIVES = [FormComponent, INPUT_DIRECTIVES, AutosaveDirective];
6+
export const FORM_DIRECTIVES = [FormComponent, INPUT_DIRECTIVES, AutosaveDirective, RecluseFormComponent];
67

78
export * from './form';

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

source/ui.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ButtonModule } from'./components/buttons/button.module';
99
import { CARD_CONTAINER_DIRECTIVES } from'./components/cardContainer/index';
1010
import { CommaListComponent } from'./components/commaList/commaList';
1111
import { DIALOG_DIRECTIVES } from'./components/dialog/index';
12+
import { RecluseFormComponent } from'./components/form/RecluseForm';
1213
import { FormComponent } from'./components/form/form';
1314
import { INPUT_DIRECTIVES } from'./components/inputs/index';
1415
import { MultiStepIndicatorComponent } from'./components/multiStepIndicator/multiStepIndicator';
@@ -41,6 +42,7 @@ export const componentsList: any[] = [
4142
CARD_CONTAINER_DIRECTIVES,
4243
CommaListComponent,
4344
DIALOG_DIRECTIVES,
45+
RecluseFormComponent,
4446
FormComponent,
4547
INPUT_DIRECTIVES,
4648
MultiStepIndicatorComponent,

0 commit comments

Comments
 (0)