@cauca-911/material 21.0.1-beta.4 → 21.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +79 -0
- package/README_PACKAGE.md +5 -0
- package/cauca-911-material-21.0.0.tgz +0 -0
- package/karma.conf.js +50 -0
- package/ng-package.json +7 -0
- package/package.json +23 -38
- package/src/assets/i18n/cauca/en-material.json +104 -0
- package/src/assets/i18n/cauca/es-material.json +104 -0
- package/src/assets/i18n/cauca/fr-material.json +106 -0
- package/src/assets/images/loading.gif +0 -0
- package/src/lib/cauca-material.component.html +1 -0
- package/src/lib/cauca-material.component.spec.ts +29 -0
- package/src/lib/cauca-material.component.ts +12 -0
- package/src/lib/cauca-material.service.spec.ts +16 -0
- package/src/lib/cauca-material.service.ts +7 -0
- package/src/lib/components/button/button.component.html +52 -0
- package/src/lib/components/button/button.component.scss +6 -0
- package/src/lib/components/button/button.component.spec.ts +142 -0
- package/src/lib/components/button/button.component.ts +22 -0
- package/src/lib/components/buttons/base-button.ts +35 -0
- package/src/lib/components/buttons/basic-button/basic-button.component.html +5 -0
- package/src/lib/components/buttons/basic-button/basic-button.component.scss +12 -0
- package/src/lib/components/buttons/basic-button/basic-button.component.spec.ts +106 -0
- package/src/lib/components/buttons/basic-button/basic-button.component.ts +17 -0
- package/src/lib/components/buttons/fab-button/fab-button.component.html +3 -0
- package/src/lib/components/buttons/fab-button/fab-button.component.scss +12 -0
- package/src/lib/components/buttons/fab-button/fab-button.component.spec.ts +82 -0
- package/src/lib/components/buttons/fab-button/fab-button.component.ts +16 -0
- package/src/lib/components/buttons/flat-button/flat-button.component.html +5 -0
- package/src/lib/components/buttons/flat-button/flat-button.component.scss +12 -0
- package/src/lib/components/buttons/flat-button/flat-button.component.spec.ts +106 -0
- package/src/lib/components/buttons/flat-button/flat-button.component.ts +17 -0
- package/src/lib/components/buttons/icon-button/icon-button.component.html +3 -0
- package/src/lib/components/buttons/icon-button/icon-button.component.scss +23 -0
- package/src/lib/components/buttons/icon-button/icon-button.component.spec.ts +38 -0
- package/src/lib/components/buttons/icon-button/icon-button.component.ts +15 -0
- package/src/lib/components/buttons/link-button/link-button.component.html +1 -0
- package/src/lib/components/buttons/link-button/link-button.component.scss +3 -0
- package/src/lib/components/buttons/link-button/link-button.component.spec.ts +97 -0
- package/src/lib/components/buttons/link-button/link-button.component.ts +25 -0
- package/src/lib/components/buttons/menu-item/menu-item.component.html +5 -0
- package/src/lib/components/buttons/menu-item/menu-item.component.scss +6 -0
- package/src/lib/components/buttons/menu-item/menu-item.component.spec.ts +66 -0
- package/src/lib/components/buttons/menu-item/menu-item.component.ts +19 -0
- package/src/lib/components/buttons/raised-button/raised-button.component.html +5 -0
- package/src/lib/components/buttons/raised-button/raised-button.component.scss +12 -0
- package/src/lib/components/buttons/raised-button/raised-button.component.spec.ts +108 -0
- package/src/lib/components/buttons/raised-button/raised-button.component.ts +17 -0
- package/src/lib/components/buttons/refresh-button/refresh-button.component.html +1 -0
- package/src/lib/components/buttons/refresh-button/refresh-button.component.scss +0 -0
- package/src/lib/components/buttons/refresh-button/refresh-button.component.spec.ts +81 -0
- package/src/lib/components/buttons/refresh-button/refresh-button.component.ts +19 -0
- package/src/lib/components/buttons/round-button/round-button.component.html +3 -0
- package/src/lib/components/buttons/round-button/round-button.component.scss +34 -0
- package/src/lib/components/buttons/round-button/round-button.component.spec.ts +26 -0
- package/src/lib/components/buttons/round-button/round-button.component.ts +14 -0
- package/src/lib/components/buttons/stroked-button/stroked-button.component.html +5 -0
- package/src/lib/components/buttons/stroked-button/stroked-button.component.scss +23 -0
- package/src/lib/components/buttons/stroked-button/stroked-button.component.spec.ts +114 -0
- package/src/lib/components/buttons/stroked-button/stroked-button.component.ts +17 -0
- package/src/lib/components/cauca-date-time-picker/cauca-date-time-picker.component.html +9 -0
- package/src/lib/components/cauca-date-time-picker/cauca-date-time-picker.component.scss +7 -0
- package/src/lib/components/cauca-date-time-picker/cauca-date-time-picker.component.spec.ts +68 -0
- package/src/lib/components/cauca-date-time-picker/cauca-date-time-picker.component.ts +155 -0
- package/src/lib/components/cauca-date-time-picker/components/desktop-time-picker/desktop-time-picker.component.html +6 -0
- package/src/lib/components/cauca-date-time-picker/components/desktop-time-picker/desktop-time-picker.component.scss +25 -0
- package/src/lib/components/cauca-date-time-picker/components/desktop-time-picker/desktop-time-picker.component.spec.ts +23 -0
- package/src/lib/components/cauca-date-time-picker/components/desktop-time-picker/desktop-time-picker.component.ts +23 -0
- package/src/lib/components/cauca-date-time-picker/components/dialog-date-time-picker/dialog-date-time-picker.component.html +77 -0
- package/src/lib/components/cauca-date-time-picker/components/dialog-date-time-picker/dialog-date-time-picker.component.scss +124 -0
- package/src/lib/components/cauca-date-time-picker/components/dialog-date-time-picker/dialog-date-time-picker.component.spec.ts +96 -0
- package/src/lib/components/cauca-date-time-picker/components/dialog-date-time-picker/dialog-date-time-picker.component.ts +228 -0
- package/src/lib/components/cauca-date-time-picker/components/mobile-time-picker/mobile-time-picker.component.html +9 -0
- package/src/lib/components/cauca-date-time-picker/components/mobile-time-picker/mobile-time-picker.component.scss +15 -0
- package/src/lib/components/cauca-date-time-picker/components/mobile-time-picker/mobile-time-picker.component.spec.ts +105 -0
- package/src/lib/components/cauca-date-time-picker/components/mobile-time-picker/mobile-time-picker.component.ts +48 -0
- package/src/lib/components/cauca-date-time-picker/models/dialog-date-time-picker-data.ts +29 -0
- package/src/lib/components/deprecated-components/cauca-input-file/cauca-input-file.component.html +14 -0
- package/src/lib/components/deprecated-components/cauca-input-file/cauca-input-file.component.scss +3 -0
- package/src/lib/components/deprecated-components/cauca-input-file/cauca-input-file.component.ts +87 -0
- package/src/lib/components/deprecated-components/cauca-input-multiple-langue/cauca-input-multiple-langue.component.html +12 -0
- package/src/lib/components/deprecated-components/cauca-input-multiple-langue/cauca-input-multiple-langue.component.scss +3 -0
- package/src/lib/components/deprecated-components/cauca-input-multiple-langue/cauca-input-multiple-langue.component.spec.ts +35 -0
- package/src/lib/components/deprecated-components/cauca-input-multiple-langue/cauca-input-multiple-langue.component.ts +57 -0
- package/src/lib/components/deprecated-components/cauca-menu-vertical/cauca-menu-vertical.component.html +49 -0
- package/src/lib/components/deprecated-components/cauca-menu-vertical/cauca-menu-vertical.component.ts +56 -0
- package/src/lib/components/deprecated-components/cauca-simple-dialog/cauca-simple-dialog.component.html +11 -0
- package/src/lib/components/deprecated-components/cauca-simple-dialog/cauca-simple-dialog.component.scss +4 -0
- package/src/lib/components/deprecated-components/cauca-simple-dialog/cauca-simple-dialog.component.spec.ts +39 -0
- package/src/lib/components/deprecated-components/cauca-simple-dialog/cauca-simple-dialog.component.ts +20 -0
- package/src/lib/components/deprecated-components/cauca-slideshow/cauca-slideshow.component.html +7 -0
- package/src/lib/components/deprecated-components/cauca-slideshow/cauca-slideshow.component.scss +41 -0
- package/src/lib/components/deprecated-components/cauca-slideshow/cauca-slideshow.component.spec.ts +24 -0
- package/src/lib/components/deprecated-components/cauca-slideshow/cauca-slideshow.component.ts +67 -0
- package/src/lib/components/deprecated-components/shared/models/menu-item.ts +11 -0
- package/src/lib/components/deprecated-components/shared/models/simple-dialog-data.ts +5 -0
- package/src/lib/components/dialogs/alert-dialog/alert-dialog.component.html +10 -0
- package/src/lib/components/dialogs/alert-dialog/alert-dialog.component.scss +14 -0
- package/src/lib/components/dialogs/alert-dialog/alert-dialog.component.spec.ts +90 -0
- package/src/lib/components/dialogs/alert-dialog/alert-dialog.component.ts +41 -0
- package/src/lib/components/dialogs/confirm-dialog/confirm-dialog.component.html +11 -0
- package/src/lib/components/dialogs/confirm-dialog/confirm-dialog.component.scss +29 -0
- package/src/lib/components/dialogs/confirm-dialog/confirm-dialog.component.spec.ts +137 -0
- package/src/lib/components/dialogs/confirm-dialog/confirm-dialog.component.ts +47 -0
- package/src/lib/components/dialogs/delete-dialog/delete-dialog.component.html +17 -0
- package/src/lib/components/dialogs/delete-dialog/delete-dialog.component.scss +14 -0
- package/src/lib/components/dialogs/delete-dialog/delete-dialog.component.spec.ts +96 -0
- package/src/lib/components/dialogs/delete-dialog/delete-dialog.component.ts +40 -0
- package/src/lib/components/dialogs/delete-dialog/models/delete-dialog-data.spec.ts +7 -0
- package/src/lib/components/dialogs/delete-dialog/models/delete-dialog-data.ts +5 -0
- package/src/lib/components/dialogs/dialog-styles.css +9 -0
- package/src/lib/components/dialogs/dialog-styles.scss +9 -0
- package/src/lib/components/dialogs/error-dialog/error-dialog.component.html +10 -0
- package/src/lib/components/dialogs/error-dialog/error-dialog.component.scss +10 -0
- package/src/lib/components/dialogs/error-dialog/error-dialog.component.spec.ts +91 -0
- package/src/lib/components/dialogs/error-dialog/error-dialog.component.ts +32 -0
- package/src/lib/components/dialogs/services/dialog.service.spec.ts +82 -0
- package/src/lib/components/dialogs/services/dialog.service.ts +107 -0
- package/src/lib/components/dialogs/text-input-dialog/text-input-dialog.component.html +24 -0
- package/src/lib/components/dialogs/text-input-dialog/text-input-dialog.component.scss +22 -0
- package/src/lib/components/dialogs/text-input-dialog/text-input-dialog.component.spec.ts +126 -0
- package/src/lib/components/dialogs/text-input-dialog/text-input-dialog.component.ts +66 -0
- package/src/lib/components/inputs/color-picker/color-picker.component.html +9 -0
- package/src/lib/components/inputs/color-picker/color-picker.component.scss +0 -0
- package/src/lib/components/inputs/color-picker/color-picker.component.spec.ts +29 -0
- package/src/lib/components/inputs/color-picker/color-picker.component.ts +111 -0
- package/src/lib/components/inputs/date-range-picker/date-range-picker.component.html +13 -0
- package/src/lib/components/inputs/date-range-picker/date-range-picker.component.scss +0 -0
- package/src/lib/components/inputs/date-range-picker/date-range-picker.component.spec.ts +80 -0
- package/src/lib/components/inputs/date-range-picker/date-range-picker.component.ts +46 -0
- package/src/lib/components/inputs/dropdown-chip-autocomplete/dropdown-chip-autocomplete.component.html +40 -0
- package/src/lib/components/inputs/dropdown-chip-autocomplete/dropdown-chip-autocomplete.component.scss +39 -0
- package/src/lib/components/inputs/dropdown-chip-autocomplete/dropdown-chip-autocomplete.component.spec.ts +135 -0
- package/src/lib/components/inputs/dropdown-chip-autocomplete/dropdown-chip-autocomplete.component.ts +263 -0
- package/src/lib/components/inputs/password/password-criteria/password-criteria.component.html +6 -0
- package/src/lib/components/inputs/password/password-criteria/password-criteria.component.scss +27 -0
- package/src/lib/components/inputs/password/password-criteria/password-criteria.component.spec.ts +90 -0
- package/src/lib/components/inputs/password/password-criteria/password-criteria.component.ts +17 -0
- package/src/lib/components/inputs/password/password-criteria-viewer/password-criteria-viewer.component.html +5 -0
- package/src/lib/components/inputs/password/password-criteria-viewer/password-criteria-viewer.component.scss +8 -0
- package/src/lib/components/inputs/password/password-criteria-viewer/password-criteria-viewer.component.spec.ts +98 -0
- package/src/lib/components/inputs/password/password-criteria-viewer/password-criteria-viewer.component.ts +16 -0
- package/src/lib/components/inputs/password/password-input/password-input.component.html +11 -0
- package/src/lib/components/inputs/password/password-input/password-input.component.scss +12 -0
- package/src/lib/components/inputs/password/password-input/password-input.component.spec.ts +141 -0
- package/src/lib/components/inputs/password/password-input/password-input.component.ts +67 -0
- package/src/lib/components/inputs/password/password-selection/password-selection.component.html +15 -0
- package/src/lib/components/inputs/password/password-selection/password-selection.component.scss +32 -0
- package/src/lib/components/inputs/password/password-selection/password-selection.component.spec.ts +138 -0
- package/src/lib/components/inputs/password/password-selection/password-selection.component.ts +101 -0
- package/src/lib/components/inputs/select-with-search/select-with-search.component.html +19 -0
- package/src/lib/components/inputs/select-with-search/select-with-search.component.scss +0 -0
- package/src/lib/components/inputs/select-with-search/select-with-search.component.spec.ts +215 -0
- package/src/lib/components/inputs/select-with-search/select-with-search.component.ts +108 -0
- package/src/lib/components/layout/expandable-panel/expandable-panel.component.html +14 -0
- package/src/lib/components/layout/expandable-panel/expandable-panel.component.scss +48 -0
- package/src/lib/components/layout/expandable-panel/expandable-panel.component.spec.ts +48 -0
- package/src/lib/components/layout/expandable-panel/expandable-panel.component.ts +19 -0
- package/src/lib/components/layout/group-container/group-container.component.html +6 -0
- package/src/lib/components/layout/group-container/group-container.component.scss +22 -0
- package/src/lib/components/layout/group-container/group-container.component.spec.ts +34 -0
- package/src/lib/components/layout/group-container/group-container.component.ts +14 -0
- package/src/lib/components/layout/menu-expandable-panel/menu-expandable-panel.component.html +13 -0
- package/src/lib/components/layout/menu-expandable-panel/menu-expandable-panel.component.scss +27 -0
- package/src/lib/components/layout/menu-expandable-panel/menu-expandable-panel.component.spec.ts +144 -0
- package/src/lib/components/layout/menu-expandable-panel/menu-expandable-panel.component.ts +52 -0
- package/src/lib/components/layout/menu-expandable-panel-item/menu-expandable-panel-item.component.html +4 -0
- package/src/lib/components/layout/menu-expandable-panel-item/menu-expandable-panel-item.component.scss +10 -0
- package/src/lib/components/layout/menu-expandable-panel-item/menu-expandable-panel-item.component.spec.ts +80 -0
- package/src/lib/components/layout/menu-expandable-panel-item/menu-expandable-panel-item.component.ts +28 -0
- package/src/lib/components/layout/page-title/page-title.component.html +28 -0
- package/src/lib/components/layout/page-title/page-title.component.scss +40 -0
- package/src/lib/components/layout/page-title/page-title.component.spec.ts +162 -0
- package/src/lib/components/layout/page-title/page-title.component.ts +28 -0
- package/src/lib/components/layout/sections/main-section/main-section.component.html +6 -0
- package/src/lib/components/layout/sections/main-section/main-section.component.scss +27 -0
- package/src/lib/components/layout/sections/main-section/main-section.component.spec.ts +42 -0
- package/src/lib/components/layout/sections/main-section/main-section.component.ts +13 -0
- package/src/lib/components/layout/sections/section-column/section-column.component.html +3 -0
- package/src/lib/components/layout/sections/section-column/section-column.component.scss +18 -0
- package/src/lib/components/layout/sections/section-column/section-column.component.spec.ts +35 -0
- package/src/lib/components/layout/sections/section-column/section-column.component.ts +12 -0
- package/src/lib/components/layout/sections/section-field/section-field.component.html +21 -0
- package/src/lib/components/layout/sections/section-field/section-field.component.scss +44 -0
- package/src/lib/components/layout/sections/section-field/section-field.component.spec.ts +74 -0
- package/src/lib/components/layout/sections/section-field/section-field.component.ts +22 -0
- package/src/lib/components/list-paginator/list-paginator.component.html +16 -0
- package/src/lib/components/list-paginator/list-paginator.component.scss +46 -0
- package/src/lib/components/list-paginator/list-paginator.component.spec.ts +248 -0
- package/src/lib/components/list-paginator/list-paginator.component.ts +81 -0
- package/src/lib/components/misc/loading-error/loading-error.component.html +11 -0
- package/src/lib/components/misc/loading-error/loading-error.component.scss +0 -0
- package/src/lib/components/misc/loading-error/loading-error.component.spec.ts +75 -0
- package/src/lib/components/misc/loading-error/loading-error.component.ts +18 -0
- package/src/lib/components/misc/loading-spinner-indicator/loading-spinner-indicator.component.html +3 -0
- package/src/lib/components/misc/loading-spinner-indicator/loading-spinner-indicator.component.scss +0 -0
- package/src/lib/components/misc/loading-spinner-indicator/loading-spinner-indicator.component.spec.ts +43 -0
- package/src/lib/components/misc/loading-spinner-indicator/loading-spinner-indicator.component.ts +16 -0
- package/src/lib/components/misc/snack-bar/snack-bar.component.html +16 -0
- package/src/lib/components/misc/snack-bar/snack-bar.component.scss +84 -0
- package/src/lib/components/misc/snack-bar/snack-bar.component.spec.ts +136 -0
- package/src/lib/components/misc/snack-bar/snack-bar.component.ts +39 -0
- package/src/lib/components/notifications/saving-confirmed-box/saving-confirmed-box.component.html +11 -0
- package/src/lib/components/notifications/saving-confirmed-box/saving-confirmed-box.component.scss +0 -0
- package/src/lib/components/notifications/saving-confirmed-box/saving-confirmed-box.component.spec.ts +67 -0
- package/src/lib/components/notifications/saving-confirmed-box/saving-confirmed-box.component.ts +15 -0
- package/src/lib/components/notifications/saving-error-box/saving-error-box.component.html +11 -0
- package/src/lib/components/notifications/saving-error-box/saving-error-box.component.scss +0 -0
- package/src/lib/components/notifications/saving-error-box/saving-error-box.component.spec.ts +77 -0
- package/src/lib/components/notifications/saving-error-box/saving-error-box.component.ts +17 -0
- package/src/lib/components/presenters/badge/badge.component.html +6 -0
- package/src/lib/components/presenters/badge/badge.component.scss +10 -0
- package/src/lib/components/presenters/badge/badge.component.spec.ts +41 -0
- package/src/lib/components/presenters/badge/badge.component.ts +18 -0
- package/src/lib/components/presenters/icon/icon.component.scss +9 -0
- package/src/lib/components/presenters/icon/icon.component.spec.ts +38 -0
- package/src/lib/components/presenters/icon/icon.component.ts +37 -0
- package/src/lib/core/breadcrumb.service.spec.ts +35 -0
- package/src/lib/core/breadcrumb.service.ts +24 -0
- package/src/lib/core/directives/auto-trim-and-lower.directive.spec.ts +22 -0
- package/src/lib/core/directives/auto-trim-and-lower.directive.ts +19 -0
- package/src/lib/core/directives/form-error/form-error.module.ts +21 -0
- package/src/lib/core/directives/form-error/has-error-root.directive.ts +31 -0
- package/src/lib/core/directives/form-error/has-error.directive.ts +95 -0
- package/src/lib/core/loading-state.service.spec.ts +57 -0
- package/src/lib/core/loading-state.service.ts +44 -0
- package/src/lib/core/models/breadcrumb-location.ts +6 -0
- package/src/lib/core/models/password-validation.ts +20 -0
- package/src/lib/core/validators/password/password-validator.spec.ts +155 -0
- package/src/lib/core/validators/password/password-validator.ts +30 -0
- package/src/lib/provide-cauca-material.ts +10 -0
- package/src/public-api.ts +70 -0
- package/src/test.ts +17 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +4 -0
- package/tsconfig.spec.json +17 -0
- package/fesm2022/cauca-911-material.mjs +0 -4323
- package/fesm2022/cauca-911-material.mjs.map +0 -1
- package/types/cauca-911-material.d.ts +0 -755
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { PasswordCriteriaViewerComponent } from './password-criteria-viewer.component';
|
|
4
|
+
import { MockComponent, ngMocks } from 'ng-mocks';
|
|
5
|
+
import { PasswordCriteriaComponent } from '../password-criteria/password-criteria.component';
|
|
6
|
+
import { PasswordValidation } from '../../../../core/models/password-validation';
|
|
7
|
+
|
|
8
|
+
describe('PasswordCriteriaViewerComponent', () => {
|
|
9
|
+
let component: PasswordCriteriaViewerComponent;
|
|
10
|
+
let fixture: ComponentFixture<PasswordCriteriaViewerComponent>;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
await TestBed.configureTestingModule({
|
|
14
|
+
imports: [PasswordCriteriaViewerComponent, MockComponent(PasswordCriteriaComponent)]
|
|
15
|
+
}).compileComponents();
|
|
16
|
+
|
|
17
|
+
fixture = TestBed.createComponent(PasswordCriteriaViewerComponent);
|
|
18
|
+
component = fixture.componentInstance;
|
|
19
|
+
fixture.componentRef.setInput('passwordValidation', new PasswordValidation());
|
|
20
|
+
fixture.detectChanges();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should create', () => {
|
|
24
|
+
expect(component).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should display criteria component for each password criteria', () => {
|
|
28
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
29
|
+
|
|
30
|
+
expect(criterias.length).toBe(5);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should display minimum character has first criteria and send condition', () => {
|
|
34
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
35
|
+
const criteria = criterias[0].componentInstance;
|
|
36
|
+
|
|
37
|
+
const passwordValidation = new PasswordValidation();
|
|
38
|
+
passwordValidation.hasMinimumCharacters = true;
|
|
39
|
+
fixture.componentRef.setInput('passwordValidation', passwordValidation);
|
|
40
|
+
fixture.detectChanges();
|
|
41
|
+
|
|
42
|
+
expect(criteria.label).toBe('passwordEdition.minimumCharacters');
|
|
43
|
+
expect(criteria.condition).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
it('should display minimum numeric has second criteria and send condition', () => {
|
|
48
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
49
|
+
const criteria = criterias[1].componentInstance;
|
|
50
|
+
|
|
51
|
+
const passwordValidation = new PasswordValidation();
|
|
52
|
+
passwordValidation.hasMinimumNumeric = true;
|
|
53
|
+
fixture.componentRef.setInput('passwordValidation', passwordValidation);
|
|
54
|
+
fixture.detectChanges();
|
|
55
|
+
|
|
56
|
+
expect(criteria.label).toBe('passwordEdition.minimumOneNumeric');
|
|
57
|
+
expect(criteria.condition).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should display minimum special character has third criteria and send condition', () => {
|
|
61
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
62
|
+
const criteria = criterias[2].componentInstance;
|
|
63
|
+
|
|
64
|
+
const passwordValidation = new PasswordValidation();
|
|
65
|
+
passwordValidation.hasSpecialCharacter = true;
|
|
66
|
+
fixture.componentRef.setInput('passwordValidation', passwordValidation);
|
|
67
|
+
fixture.detectChanges();
|
|
68
|
+
|
|
69
|
+
expect(criteria.label).toBe('passwordEdition.minimumOneSpecialCharacter');
|
|
70
|
+
expect(criteria.condition).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should display minimum upper and lowercase has fourth criteria and send condition', () => {
|
|
74
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
75
|
+
const criteria = criterias[3].componentInstance;
|
|
76
|
+
|
|
77
|
+
const passwordValidation = new PasswordValidation();
|
|
78
|
+
passwordValidation.hasLowerAndUppercase = true;
|
|
79
|
+
fixture.componentRef.setInput('passwordValidation', passwordValidation);
|
|
80
|
+
fixture.detectChanges();
|
|
81
|
+
|
|
82
|
+
expect(criteria.label).toBe('passwordEdition.needLowerAndUppercase');
|
|
83
|
+
expect(criteria.condition).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should display identical password has fifth criteria and send condition', () => {
|
|
87
|
+
const criterias = ngMocks.findAll<PasswordCriteriaComponent>('cauca-password-criteria');
|
|
88
|
+
const criteria = criterias[4].componentInstance;
|
|
89
|
+
|
|
90
|
+
const passwordValidation = new PasswordValidation();
|
|
91
|
+
passwordValidation.hasIdenticalPassword = true;
|
|
92
|
+
fixture.componentRef.setInput('passwordValidation', passwordValidation);
|
|
93
|
+
fixture.detectChanges();
|
|
94
|
+
|
|
95
|
+
expect(criteria.label).toBe('passwordEdition.equalPasswords');
|
|
96
|
+
expect(criteria.condition).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Component, InputSignal, input } from '@angular/core';
|
|
2
|
+
import { PasswordCriteriaComponent } from '../password-criteria/password-criteria.component';
|
|
3
|
+
import { PasswordValidation } from '../../../../core/models/password-validation';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
selector: 'cauca-password-criteria-viewer',
|
|
8
|
+
standalone: true,
|
|
9
|
+
imports: [PasswordCriteriaComponent],
|
|
10
|
+
templateUrl: './password-criteria-viewer.component.html',
|
|
11
|
+
styleUrl: './password-criteria-viewer.component.scss'
|
|
12
|
+
})
|
|
13
|
+
export class PasswordCriteriaViewerComponent {
|
|
14
|
+
public passwordValidation: InputSignal<PasswordValidation> = input.required();
|
|
15
|
+
public disabled: InputSignal<boolean> = input(false);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<mat-form-field subscriptSizing="dynamic">
|
|
2
|
+
@if(translateLabel()) {<mat-label>{{label() | translate}}</mat-label>}
|
|
3
|
+
@else {<mat-label>{{label()}}</mat-label>}
|
|
4
|
+
<input (keydown.enter)="enterKeyDown.emit()" [autocomplete]="autocomplete()" #password class="password"
|
|
5
|
+
[type]="inputType()" [formControl]="passwordControl" matInput [required]="required()"
|
|
6
|
+
[placeholder]="translatePlaceholder() ? (placeholder() | translate) : placeholder()" />
|
|
7
|
+
<mat-icon [ngClass]="disabled() ? 'disabled' : ''" style="cursor: pointer" matSuffix
|
|
8
|
+
(click)="showPassword.set(!showPassword())">
|
|
9
|
+
{{ password.type === "password" ? "visibility_off" : "visibility" }}
|
|
10
|
+
</mat-icon>
|
|
11
|
+
</mat-form-field>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { PasswordInputComponent } from './password-input.component';
|
|
4
|
+
import { MockComponent, MockModule, MockPipe } from 'ng-mocks';
|
|
5
|
+
import { TranslateModule, TranslatePipe } from '@ngx-translate/core';
|
|
6
|
+
import { By } from '@angular/platform-browser';
|
|
7
|
+
import { MatIcon } from '@angular/material/icon';
|
|
8
|
+
|
|
9
|
+
describe('PasswordInputComponent', () => {
|
|
10
|
+
let component: PasswordInputComponent;
|
|
11
|
+
let fixture: ComponentFixture<PasswordInputComponent>;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
await TestBed.configureTestingModule({
|
|
15
|
+
imports: [PasswordInputComponent,
|
|
16
|
+
MockModule(TranslateModule),
|
|
17
|
+
MockComponent(MatIcon)
|
|
18
|
+
],
|
|
19
|
+
declarations: [
|
|
20
|
+
MockPipe(TranslatePipe, value => `${value}:translated`)
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
.compileComponents();
|
|
24
|
+
|
|
25
|
+
fixture = TestBed.createComponent(PasswordInputComponent);
|
|
26
|
+
component = fixture.componentInstance;
|
|
27
|
+
fixture.detectChanges();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should create', () => {
|
|
31
|
+
expect(component).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should update the value when writeValue is called', () => {
|
|
35
|
+
const value = 'test123';
|
|
36
|
+
|
|
37
|
+
component.writeValue(value);
|
|
38
|
+
|
|
39
|
+
expect(component.passwordControl.value).toEqual(value);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should call onChange when passwordControl value changes', () => {
|
|
43
|
+
const value = 'test123';
|
|
44
|
+
const spy = spyOn(component, 'onChange');
|
|
45
|
+
|
|
46
|
+
component.passwordControl.setValue(value);
|
|
47
|
+
|
|
48
|
+
expect(spy).toHaveBeenCalledWith(value);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should disable passwordControl when setDisabledState is called with true', () => {
|
|
52
|
+
component.setDisabledState(true);
|
|
53
|
+
expect(component.passwordControl.disabled).toBeTrue();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should enable passwordControl when setDisabledState is called with false', () => {
|
|
57
|
+
component.setDisabledState(false);
|
|
58
|
+
expect(component.passwordControl.enabled).toBeTrue();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should translate label when translateLabel is true', () => {
|
|
62
|
+
fixture.componentRef.setInput('translateLabel', true);
|
|
63
|
+
fixture.componentRef.setInput('label', 'PASSWORD');
|
|
64
|
+
fixture.detectChanges();
|
|
65
|
+
|
|
66
|
+
const label = fixture.debugElement.query(By.css('mat-label')).nativeElement;
|
|
67
|
+
expect(label.textContent).toBe('PASSWORD:translated');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should not translate label when translateLabel is false', () => {
|
|
71
|
+
fixture.componentRef.setInput('translateLabel', false);
|
|
72
|
+
fixture.componentRef.setInput('label', 'PASSWORD');
|
|
73
|
+
fixture.detectChanges();
|
|
74
|
+
|
|
75
|
+
const label = fixture.debugElement.query(By.css('mat-label')).nativeElement;
|
|
76
|
+
expect(label.textContent).toBe('PASSWORD');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should translate placeholder when translatePlaceholder is true', () => {
|
|
80
|
+
fixture.componentRef.setInput('translatePlaceholder', true);
|
|
81
|
+
fixture.componentRef.setInput('placeholder', 'placeholder');
|
|
82
|
+
fixture.detectChanges();
|
|
83
|
+
|
|
84
|
+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
|
85
|
+
expect(input.placeholder).toBe('placeholder:translated');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should not translate placeholder when translatePlaceholder is false', () => {
|
|
89
|
+
fixture.componentRef.setInput('translatePlaceholder', false);
|
|
90
|
+
fixture.componentRef.setInput('placeholder', 'placeholder');
|
|
91
|
+
fixture.detectChanges();
|
|
92
|
+
|
|
93
|
+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
|
94
|
+
|
|
95
|
+
expect(input.placeholder).toBe('placeholder');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should toggle password visibility', () => {
|
|
99
|
+
const icon = fixture.debugElement.query(By.css('mat-icon')).nativeElement;
|
|
100
|
+
|
|
101
|
+
icon.click();
|
|
102
|
+
fixture.detectChanges();
|
|
103
|
+
|
|
104
|
+
expect(fixture.debugElement.query(By.css('mat-icon')).nativeElement.textContent.trim()).toBe('visibility');
|
|
105
|
+
expect(component.showPassword()).toBeTrue();
|
|
106
|
+
expect(component.inputType()).toBe('text');
|
|
107
|
+
|
|
108
|
+
icon.click();
|
|
109
|
+
fixture.detectChanges();
|
|
110
|
+
|
|
111
|
+
expect(fixture.debugElement.query(By.css('mat-icon')).nativeElement.textContent.trim()).toBe('visibility_off');
|
|
112
|
+
expect(component.showPassword()).toBeFalse();
|
|
113
|
+
expect(component.inputType()).toBe('password');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should emit enterKeyDown when enter key is pressed', () => {
|
|
117
|
+
const spy = spyOn(component.enterKeyDown, 'emit');
|
|
118
|
+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
|
119
|
+
|
|
120
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
|
|
121
|
+
fixture.detectChanges();
|
|
122
|
+
|
|
123
|
+
expect(spy).toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should set required', () => {
|
|
127
|
+
fixture.componentRef.setInput('required', true);
|
|
128
|
+
fixture.detectChanges();
|
|
129
|
+
|
|
130
|
+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
|
131
|
+
expect(input.required).toBeTrue();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should set autocomplete', () => {
|
|
135
|
+
fixture.componentRef.setInput('autocomplete', 'new-password');
|
|
136
|
+
fixture.detectChanges();
|
|
137
|
+
|
|
138
|
+
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
|
139
|
+
expect(input.autocomplete).toBe('new-password');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NgClass } from '@angular/common';
|
|
2
|
+
import { Component, computed, forwardRef, input, InputSignal, output, signal, WritableSignal } from '@angular/core';
|
|
3
|
+
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
5
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
6
|
+
import { MatInputModule } from '@angular/material/input';
|
|
7
|
+
import { TranslateModule } from '@ngx-translate/core';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'cauca-password-input',
|
|
11
|
+
standalone: true,
|
|
12
|
+
imports: [TranslateModule, NgClass, MatFormFieldModule, MatIconModule, MatInputModule, ReactiveFormsModule],
|
|
13
|
+
templateUrl: './password-input.component.html',
|
|
14
|
+
styleUrl: './password-input.component.scss',
|
|
15
|
+
providers: [
|
|
16
|
+
{
|
|
17
|
+
provide: NG_VALUE_ACCESSOR,
|
|
18
|
+
multi: true,
|
|
19
|
+
useExisting: forwardRef(() => PasswordInputComponent),
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
export class PasswordInputComponent implements ControlValueAccessor {
|
|
24
|
+
public autocomplete: InputSignal<string> = input<'password' | 'new-password'>('password');
|
|
25
|
+
public translateLabel: InputSignal<boolean> = input(true);
|
|
26
|
+
public label: InputSignal<string> = input();
|
|
27
|
+
public translatePlaceholder: InputSignal<boolean> = input(true);
|
|
28
|
+
public placeholder: InputSignal<string> = input();
|
|
29
|
+
public required: InputSignal<boolean> = input(false);
|
|
30
|
+
public enterKeyDown = output();
|
|
31
|
+
|
|
32
|
+
public passwordControl: FormControl = new FormControl('');
|
|
33
|
+
public disabled: WritableSignal<boolean> = signal(false);
|
|
34
|
+
public showPassword: WritableSignal<boolean> = signal(false);
|
|
35
|
+
public inputType = computed(() => this.showPassword() ? 'text' : 'password');
|
|
36
|
+
|
|
37
|
+
public constructor() {
|
|
38
|
+
this.passwordControl.valueChanges.subscribe(value => {
|
|
39
|
+
this.onChange(value);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public writeValue(value: string): void {
|
|
44
|
+
this.passwordControl.setValue(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public registerOnChange(fn: any): void {
|
|
48
|
+
this.onChange = fn;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public registerOnTouched(fn: any): void {
|
|
52
|
+
this.onTouched = fn;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public setDisabledState?(isDisabled: boolean): void {
|
|
56
|
+
this.disabled.set(isDisabled);
|
|
57
|
+
if (isDisabled) {
|
|
58
|
+
this.passwordControl.disable();
|
|
59
|
+
} else {
|
|
60
|
+
this.passwordControl.enable();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public onChange = (value: string): string => value;
|
|
65
|
+
|
|
66
|
+
public onTouched = (): void => {/* This method needs to be empty */ };
|
|
67
|
+
}
|
package/src/lib/components/inputs/password/password-selection/password-selection.component.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<form [formGroup]="form" [class.full-width-form]="direction === 'column'">
|
|
2
|
+
<div class="passwords">
|
|
3
|
+
<cauca-password-input [autocomplete]="'new-password'" [label]="passwordLabel()" [translateLabel]="true" [required]="true" formControlName="password" />
|
|
4
|
+
<cauca-password-input [autocomplete]="'new-password'" [label]="passwordConfirmationLabel()" [translateLabel]="true" [required]="true" formControlName="confirmation" />
|
|
5
|
+
</div>
|
|
6
|
+
<div class="errors">
|
|
7
|
+
<ng-content></ng-content>
|
|
8
|
+
</div>
|
|
9
|
+
</form>
|
|
10
|
+
|
|
11
|
+
@if (showCriteria()) {
|
|
12
|
+
<cauca-password-criteria-viewer [disabled]="disabled()" [passwordValidation]="passwordValidation" />
|
|
13
|
+
} @else {
|
|
14
|
+
<span></span>
|
|
15
|
+
}
|
package/src/lib/components/inputs/password/password-selection/password-selection.component.scss
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: flex;
|
|
3
|
+
gap: 20px;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
form {
|
|
7
|
+
width: 50%;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.full-width-form {
|
|
13
|
+
width: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.passwords {
|
|
17
|
+
gap: 16px;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.criteria {
|
|
23
|
+
flex-grow: 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.disabled {
|
|
27
|
+
opacity: 0.5;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.errors {
|
|
31
|
+
padding: 0 16px;
|
|
32
|
+
}
|
package/src/lib/components/inputs/password/password-selection/password-selection.component.spec.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { PasswordSelectionComponent } from './password-selection.component';
|
|
4
|
+
import { MockComponents, MockDirective, MockModule, ngMocks } from 'ng-mocks';
|
|
5
|
+
import { TranslateDirective, TranslateModule } from '@ngx-translate/core';
|
|
6
|
+
import { PasswordCriteriaViewerComponent } from '../password-criteria-viewer/password-criteria-viewer.component';
|
|
7
|
+
import { PasswordInputComponent } from '../password-input/password-input.component';
|
|
8
|
+
|
|
9
|
+
describe('PasswordSelectionComponent', () => {
|
|
10
|
+
let component: PasswordSelectionComponent;
|
|
11
|
+
let fixture: ComponentFixture<PasswordSelectionComponent>;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
await TestBed.configureTestingModule({
|
|
15
|
+
imports: [PasswordSelectionComponent,
|
|
16
|
+
MockModule(TranslateModule),
|
|
17
|
+
...MockComponents(PasswordCriteriaViewerComponent, PasswordInputComponent),
|
|
18
|
+
],
|
|
19
|
+
declarations: [
|
|
20
|
+
MockDirective(TranslateDirective)
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
.compileComponents();
|
|
24
|
+
|
|
25
|
+
fixture = TestBed.createComponent(PasswordSelectionComponent);
|
|
26
|
+
component = fixture.componentInstance;
|
|
27
|
+
fixture.detectChanges();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should create', () => {
|
|
31
|
+
expect(component).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should validate password when form change', () => {
|
|
35
|
+
const somePasswordWithNumeric = '4321';
|
|
36
|
+
const somePasswordWithNumericAndSpecialCharacter = '4321#';
|
|
37
|
+
|
|
38
|
+
component.form.get('password').setValue(somePasswordWithNumeric);
|
|
39
|
+
|
|
40
|
+
expect(component.passwordValidation.hasMinimumNumeric).toBeTrue();
|
|
41
|
+
expect(component.passwordValidation.hasSpecialCharacter).toBeFalse();
|
|
42
|
+
|
|
43
|
+
component.form.get('password').setValue(somePasswordWithNumericAndSpecialCharacter);
|
|
44
|
+
|
|
45
|
+
expect(component.passwordValidation.hasMinimumNumeric).toBeTrue();
|
|
46
|
+
expect(component.passwordValidation.hasSpecialCharacter).toBeTrue();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should only emit full password when form is valid', () => {
|
|
50
|
+
const spy = spyOn(component, 'onChange');
|
|
51
|
+
const somePassword = 'CaucaTest4321#';
|
|
52
|
+
|
|
53
|
+
component.form.get('password').setValue(somePassword);
|
|
54
|
+
component.form.get('confirmation').setValue(somePassword);
|
|
55
|
+
fixture.detectChanges();
|
|
56
|
+
|
|
57
|
+
expect(spy).toHaveBeenCalledOnceWith(somePassword);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should emit empty password when form validity change to to invalid', async () => {
|
|
61
|
+
const spy = spyOn(component, 'onChange');
|
|
62
|
+
const somePassword = 'CaucaTest4321#';
|
|
63
|
+
component.form.get('password').setValue(somePassword);
|
|
64
|
+
component.form.get('confirmation').setValue(somePassword);
|
|
65
|
+
|
|
66
|
+
expect(spy).toHaveBeenCalledOnceWith(somePassword);
|
|
67
|
+
|
|
68
|
+
const password = component.form.get('password');
|
|
69
|
+
await password.setValue('C');
|
|
70
|
+
await password.setValue('Ca');
|
|
71
|
+
await password.setValue('Cau');
|
|
72
|
+
await password.setValue('Cauc');
|
|
73
|
+
fixture.detectChanges();
|
|
74
|
+
|
|
75
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
76
|
+
expect(spy).toHaveBeenCalledWith('');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should disable input when disable is set', () => {
|
|
80
|
+
const password = component.form.get('password');
|
|
81
|
+
const confirmation = component.form.get('confirmation');
|
|
82
|
+
|
|
83
|
+
component.setDisabledState(true);
|
|
84
|
+
fixture.detectChanges();
|
|
85
|
+
|
|
86
|
+
expect(password.disabled).toBeTrue();
|
|
87
|
+
expect(confirmation.disabled).toBeTrue();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should not show criteria when password has no value', () => {
|
|
91
|
+
fixture.componentRef.setInput('showCriteriaOnlyWhenPasswordHasValue', true);
|
|
92
|
+
fixture.componentRef.setInput('alwaysShowCriteria', false);
|
|
93
|
+
component.form.get('password').setValue('');
|
|
94
|
+
component.form.get('confirmation').setValue('');
|
|
95
|
+
fixture.detectChanges();
|
|
96
|
+
|
|
97
|
+
expect(component.showCriteria()).toBeFalse();
|
|
98
|
+
expect(ngMocks.find('cauca-password-criteria-viewer', null)).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should show criteria when password has value', () => {
|
|
102
|
+
fixture.componentRef.setInput('showCriteriaOnlyWhenPasswordHasValue', true);
|
|
103
|
+
|
|
104
|
+
component.form.get('password').setValue('CaucaTest4321#');
|
|
105
|
+
component.form.get('confirmation').setValue('CaucaTest4321#');
|
|
106
|
+
fixture.detectChanges();
|
|
107
|
+
|
|
108
|
+
expect(component.showCriteria()).toBeTrue();
|
|
109
|
+
expect(ngMocks.find('cauca-password-criteria-viewer', null)).not.toBeNull();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should show criteria when alwaysShowCriteria is set to true', () => {
|
|
113
|
+
fixture.componentRef.setInput('showCriteriaOnlyWhenPasswordHasValue', true);
|
|
114
|
+
fixture.componentRef.setInput('alwaysShowCriteria', true);
|
|
115
|
+
component.form.get('password').setValue('');
|
|
116
|
+
component.form.get('confirmation').setValue('');
|
|
117
|
+
fixture.detectChanges();
|
|
118
|
+
|
|
119
|
+
expect(component.showCriteria()).toBeTrue();
|
|
120
|
+
expect(ngMocks.find('cauca-password-criteria-viewer', null)).not.toBeNull();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should set password label from input', () => {
|
|
124
|
+
const passwordLabel = 'newPassword';
|
|
125
|
+
fixture.componentRef.setInput('passwordLabel', passwordLabel);
|
|
126
|
+
fixture.detectChanges();
|
|
127
|
+
|
|
128
|
+
expect(component.passwordLabel()).toBe(passwordLabel);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should set password confirmation from input', () => {
|
|
132
|
+
const passwordConfirmationLabel = 'confirmPassword';
|
|
133
|
+
fixture.componentRef.setInput('passwordConfirmationLabel', passwordConfirmationLabel);
|
|
134
|
+
fixture.detectChanges();
|
|
135
|
+
|
|
136
|
+
expect(component.passwordConfirmationLabel()).toBe(passwordConfirmationLabel);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, forwardRef, HostBinding, input, Input, output, signal } from '@angular/core';
|
|
2
|
+
import { TranslateModule } from '@ngx-translate/core';
|
|
3
|
+
import { PasswordCriteriaViewerComponent } from '../password-criteria-viewer/password-criteria-viewer.component';
|
|
4
|
+
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule, UntypedFormBuilder, UntypedFormGroup, ValidationErrors, Validators } from '@angular/forms';
|
|
5
|
+
import { filter } from 'rxjs';
|
|
6
|
+
import { PasswordInputComponent } from '../password-input/password-input.component';
|
|
7
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
|
+
import { PasswordValidation } from '../../../../core/models/password-validation';
|
|
9
|
+
import { PasswordValidator } from '../../../../core/validators/password/password-validator';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@Component({
|
|
13
|
+
selector: 'cauca-password-selection',
|
|
14
|
+
standalone: true,
|
|
15
|
+
imports: [PasswordInputComponent, FormsModule, ReactiveFormsModule, TranslateModule, PasswordCriteriaViewerComponent],
|
|
16
|
+
templateUrl: './password-selection.component.html',
|
|
17
|
+
styleUrl: './password-selection.component.scss',
|
|
18
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
+
providers: [
|
|
20
|
+
{
|
|
21
|
+
provide: NG_VALUE_ACCESSOR,
|
|
22
|
+
multi: true,
|
|
23
|
+
useExisting: forwardRef(() => PasswordSelectionComponent),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
export class PasswordSelectionComponent implements ControlValueAccessor {
|
|
28
|
+
public form: UntypedFormGroup;
|
|
29
|
+
public passwordValidation: PasswordValidation = new PasswordValidation();
|
|
30
|
+
public disabled = signal<boolean>(false);
|
|
31
|
+
|
|
32
|
+
@Input() @HostBinding('style.flex-direction') public direction: 'row'|'column' = 'row';
|
|
33
|
+
@Input() @HostBinding('style.form.width') public formWidth: string = '50%';
|
|
34
|
+
public showCriteriaOnlyWhenPasswordHasValue = input<boolean>(true);
|
|
35
|
+
public alwaysShowCriteria = input<boolean>(true);
|
|
36
|
+
public showCriteria = signal<boolean>(true);
|
|
37
|
+
public passwordLabel = input<string>('passwordEdition.password');
|
|
38
|
+
public passwordConfirmationLabel = input<string>('passwordEdition.passwordConfirmation');
|
|
39
|
+
public hasValueChange = output<boolean>();
|
|
40
|
+
|
|
41
|
+
private lastPasswordValidationSent = false;
|
|
42
|
+
|
|
43
|
+
public constructor(formBuilder: UntypedFormBuilder) {
|
|
44
|
+
this.form = formBuilder.group({
|
|
45
|
+
password: ['', Validators.required],
|
|
46
|
+
confirmation: ['', Validators.required]
|
|
47
|
+
}, { validators: (formGroup: UntypedFormGroup): ValidationErrors | null => {
|
|
48
|
+
this.passwordValidation = PasswordValidator.validate(formGroup);
|
|
49
|
+
if (!this.passwordValidation.isValid()) {
|
|
50
|
+
return ({ validation: this.passwordValidation});
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}});
|
|
54
|
+
this.form.valueChanges.pipe(takeUntilDestroyed())
|
|
55
|
+
.subscribe(() => {
|
|
56
|
+
if (!this.alwaysShowCriteria()) {
|
|
57
|
+
if (this.showCriteriaOnlyWhenPasswordHasValue()) {
|
|
58
|
+
this.showCriteria.set(this.form.controls.password.value?.length > 0 || this.form.controls.confirmation.value?.length > 0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this.hasValueChange.emit(this.form.controls.password.value?.length > 0);
|
|
62
|
+
});
|
|
63
|
+
this.form.valueChanges.pipe(takeUntilDestroyed(), filter(_ => this.form.valid != this.lastPasswordValidationSent)).subscribe(form => {
|
|
64
|
+
this.lastPasswordValidationSent = this.form.valid;
|
|
65
|
+
if (this.form.valid) {
|
|
66
|
+
this.onChange(form.password);
|
|
67
|
+
} else {
|
|
68
|
+
this.onChange('');
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public writeValue(value: string): void {
|
|
74
|
+
this.form.get('password').setValue(value);
|
|
75
|
+
this.form.get('confirmation').setValue(value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public registerOnChange(fn: any): void {
|
|
79
|
+
this.onChange = fn;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public registerOnTouched(fn: any): void {
|
|
83
|
+
this.onTouched = fn;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public setDisabledState?(isDisabled: boolean): void {
|
|
87
|
+
this.disabled.set(isDisabled);
|
|
88
|
+
if (isDisabled) {
|
|
89
|
+
this.form.get('password').disable();
|
|
90
|
+
this.form.get('confirmation').disable();
|
|
91
|
+
} else {
|
|
92
|
+
this.form.get('password').enable();
|
|
93
|
+
this.form.get('confirmation').enable();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public onChange = (value: string): string => value;
|
|
98
|
+
|
|
99
|
+
public onTouched = (): void => {/* This method needs to be empty */ };
|
|
100
|
+
|
|
101
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<mat-form-field class="full-width-field header dense" subscriptSizing="dynamic">
|
|
2
|
+
<ng-content></ng-content>
|
|
3
|
+
<mat-label>{{ label | translate }}</mat-label>
|
|
4
|
+
<mat-select [(value)]="value" [disabled]="disableControl()" [class.readonly-field]="disableControl()" [multiple]="allowMultiSelection()" >
|
|
5
|
+
@if (enableSearch()) {
|
|
6
|
+
<mat-option>
|
|
7
|
+
<ngx-mat-select-search [formControl]="optionFilterControl" [placeholderLabel]="'search' | translate"
|
|
8
|
+
[noEntriesFoundLabel]="'noResult' | translate">
|
|
9
|
+
</ngx-mat-select-search>
|
|
10
|
+
</mat-option>
|
|
11
|
+
}
|
|
12
|
+
@for (option of filteredOptions.value() || []; track option) {
|
|
13
|
+
<mat-option [value]="option.id">
|
|
14
|
+
{{option.name}}
|
|
15
|
+
</mat-option>
|
|
16
|
+
}
|
|
17
|
+
</mat-select>
|
|
18
|
+
|
|
19
|
+
</mat-form-field>
|
|
File without changes
|