Skip to content

Commit aa5fcf7

Browse files
committed
feat(components): implementa alternância no nível de acessibilidade
Implementa alternância no nível de acessibilidade dos componentes de formulário. fixes DTHFUI-10108
1 parent c150ef0 commit aa5fcf7

File tree

232 files changed

+4903
-895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+4903
-895
lines changed

Diff for: projects/portal/src/app/app.component.ts

+51-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
33

4-
import { PoMenuItem, PoNavbarIconAction, PoNavbarItem, PoNotificationService } from '@po-ui/ng-components';
4+
import {
5+
PoMenuItem,
6+
PoNavbarIconAction,
7+
PoNavbarItem,
8+
PoNotificationService,
9+
PoThemeA11yEnum
10+
} from '@po-ui/ng-components';
511

612
import { PoThemeService, PoThemeTypeEnum } from '../../../ui/src/lib';
713
import { poThemeConstant } from './shared/po-theme.constant';
@@ -19,11 +25,14 @@ export class AppComponent implements OnInit, OnDestroy {
1925
items: Array<PoNavbarItem> = [];
2026
iconActions: Array<PoNavbarIconAction> = [];
2127
themeStorage = 'po-theme-default';
28+
a11yStorage = 'po-a11y-AAA';
2229
logoPoUI = './assets/po-logos/po_black.png';
2330
theme: PoThemeTypeEnum = 0;
31+
a11y: PoThemeA11yEnum = PoThemeA11yEnum.AAA;
2432

2533
private location;
2634
private themeChangeListener: any;
35+
private a11yChangeListener: any;
2736

2837
constructor(
2938
private versionService: VersionService,
@@ -34,7 +43,7 @@ export class AppComponent implements OnInit, OnDestroy {
3443
const _poTheme = this.poTheme.applyTheme();
3544
if (!_poTheme) {
3645
this.theme = poThemeConstant.active;
37-
this.poTheme.setTheme(poThemeConstant, this.theme);
46+
this.poTheme.setTheme(poThemeConstant, this.theme, this.a11y);
3847
} else {
3948
this.theme = typeof _poTheme.active === 'object' ? _poTheme.active.type : _poTheme.active;
4049
}
@@ -45,6 +54,10 @@ export class AppComponent implements OnInit, OnDestroy {
4554
this.themeStorage = localStorage.getItem('po-ui-theme');
4655
}
4756

57+
if (localStorage.getItem('po-ui-a11y')) {
58+
this.a11yStorage = localStorage.getItem('po-ui-a11y');
59+
}
60+
4861
const version = await this.versionService.getCurrentVersion().toPromise();
4962

5063
this.items = [
@@ -67,7 +80,13 @@ export class AppComponent implements OnInit, OnDestroy {
6780
this.themeChangeListener = () => {
6881
this.changeTheme(false);
6982
};
83+
84+
this.a11yChangeListener = () => {
85+
this.changeA11yLevel(false);
86+
};
87+
7088
window.addEventListener('po-sample-change-theme', this.themeChangeListener);
89+
window.addEventListener('po-sample-change-a11y', this.a11yChangeListener);
7190
}
7291

7392
openExternalLink(url) {
@@ -82,27 +101,52 @@ export class AppComponent implements OnInit, OnDestroy {
82101
this.themeStorage === 'po-theme-default' ? './assets/po-logos/po_black.png' : './assets/po-logos/po_white.png';
83102
this.iconActions = this.actions;
84103

85-
this.poTheme.setTheme(poThemeConstant, this.theme);
104+
this.poTheme.setTheme(poThemeConstant, this.theme, this.a11y);
86105

87106
if (dispatchEvent) {
88107
window.dispatchEvent(new Event(this.themeStorage));
89108
}
90109
}
91110

111+
changeA11yLevel(dispatchEvent = true) {
112+
this.a11yStorage = this.a11yStorage === 'po-a11y-AAA' ? 'po-a11y-AA' : 'po-a11y-AAA';
113+
localStorage.setItem('po-ui-a11y', this.a11yStorage);
114+
this.a11y = this.a11yStorage === 'po-a11y-AAA' ? PoThemeA11yEnum.AAA : PoThemeA11yEnum.AA;
115+
this.iconActions = this.actions;
116+
117+
this.poTheme.setTheme(poThemeConstant, this.theme, this.a11y);
118+
119+
if (dispatchEvent) {
120+
window.dispatchEvent(new Event(this.a11yStorage));
121+
}
122+
}
123+
92124
get actions() {
93125
return [
94-
{ icon: 'an an-github-logo', link: 'https://github.com/po-ui', label: 'Github' },
95-
{ icon: 'an an-x-logo', link: 'https://twitter.com/@pouidev', label: 'Twitter' },
96-
{ icon: 'an an-instagram-logo', link: 'https://www.instagram.com/pouidev/', label: 'Instagram' },
126+
{ icon: 'an an-github-logo', link: 'https://github.com/po-ui', label: 'Github', tooltip: 'Github' },
127+
{
128+
icon: 'an an-instagram-logo',
129+
link: 'https://www.instagram.com/pouidev/',
130+
label: 'Instagram',
131+
tooltip: 'Instagram'
132+
},
97133
{
98134
icon: `${this.themeStorage === 'po-theme-dark' ? 'an an-sun' : 'an an-moon'}`,
99-
label: 'tema',
135+
label: `Tema ${this.themeStorage === 'po-theme-dark' ? 'Light' : 'Dark'}`,
136+
tooltip: `${this.themeStorage === 'po-theme-dark' ? 'Dark' : 'Light'}`,
100137
action: this.changeTheme.bind(this)
138+
},
139+
{
140+
icon: `${this.a11yStorage === 'po-a11y-AAA' ? 'an-fill an-person-arms-spread' : 'an an-person-arms-spread'}`,
141+
label: `Acessibilidade ${this.a11yStorage === 'po-a11y-AAA' ? 'AA' : 'AAA'}`,
142+
tooltip: `${this.a11yStorage === 'po-a11y-AAA' ? 'AAA' : 'AA'}`,
143+
action: this.changeA11yLevel.bind(this)
101144
}
102145
];
103146
}
104147

105148
ngOnDestroy(): void {
106149
window.removeEventListener('po-sample-change-theme', this.themeChangeListener);
150+
window.removeEventListener('po-sample-change-a11y', this.a11yChangeListener);
107151
}
108152
}

Diff for: projects/portal/src/styles.css

+4
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ a,
470470

471471
.show-me-the-code {
472472
float: right;
473+
}
474+
475+
.show-me-the-code,
476+
.show-me-the-code .po-icon {
473477
font-size: 16px;
474478
}
475479

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @usedBy PoPageDynamicEditComponent
3+
*
4+
* @description
5+
*
6+
* Enum para configurar o tamanho (`p-size`) dos fields no componente.
7+
*/
8+
export enum PoPageDynamicEditActionsSize {
9+
/** Define o tamanho dos fields com altura de 32px, disponível para acessibilidade AA. */
10+
small = 'small',
11+
12+
/** Define o tamanho dos fields com altura de 44px. */
13+
medium = 'medium'
14+
}

Diff for: projects/templates/src/lib/components/po-page-dynamic-edit/po-page-dynamic-edit.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</ng-template>
1313

1414
<ng-template #formFieldsTemplate>
15-
<po-dynamic-form #dynamicForm [p-fields]="controlFields" [p-value]="model"> </po-dynamic-form>
15+
<po-dynamic-form #dynamicForm [p-fields]="controlFields" [p-size]="size" [p-value]="model"> </po-dynamic-form>
1616

1717
<div *ngIf="detailFields.length > 0" class="po-sm-12">
1818
<po-divider [p-label]="detailFields[0].divider"></po-divider>
1919

2020
<div class="po-row po-mb-2">
21-
<po-button [p-label]="literals.detailActionNew" (p-click)="detailActionNew()"></po-button>
21+
<po-button [p-label]="literals.detailActionNew" [p-size]="size" (p-click)="detailActionNew()"></po-button>
2222
</div>
2323

2424
<po-grid

Diff for: projects/templates/src/lib/components/po-page-dynamic-edit/po-page-dynamic-edit.component.spec.ts

+98-10
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
1+
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
2+
import { provideHttpClientTesting } from '@angular/common/http/testing';
23
import { NO_ERRORS_SCHEMA } from '@angular/core';
4+
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
35
import { FormControl, FormsModule, NgForm, Validators } from '@angular/forms';
4-
import { provideHttpClientTesting } from '@angular/common/http/testing';
56
import { RouterTestingModule } from '@angular/router/testing';
67

7-
import { throwError, of } from 'rxjs';
8+
import { of, throwError } from 'rxjs';
89

9-
import { PoDialogModule } from '@po-ui/ng-components';
10+
import { PoDialogModule, PoThemeA11yEnum, PoThemeService } from '@po-ui/ng-components';
1011

11-
import * as util from './../../utils/util';
1212
import { expectPropertiesValues } from './../../util-test/util-expect.spec';
13+
import * as util from './../../utils/util';
1314

1415
import { poLocaleDefault } from './../../../../../ui/src/lib/services/po-language/po-language.constant';
1516

16-
import { PoPageDynamicEditComponent, poPageDynamicEditLiteralsDefault } from './po-page-dynamic-edit.component';
1717
import { PoPageDynamicEditActions } from './interfaces/po-page-dynamic-edit-actions.interface';
18-
import { PoDynamicFormStubComponent } from './test/po-dynamic-form-stub-component';
19-
import { PoPageDynamicEditBeforeSave } from './interfaces/po-page-dynamic-edit-before-save.interface';
2018
import { PoPageDynamicEditBeforeSaveNew } from './interfaces/po-page-dynamic-edit-before-save-new.interface';
21-
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
19+
import { PoPageDynamicEditBeforeSave } from './interfaces/po-page-dynamic-edit-before-save.interface';
20+
import { PoPageDynamicEditComponent, poPageDynamicEditLiteralsDefault } from './po-page-dynamic-edit.component';
21+
import { PoDynamicFormStubComponent } from './test/po-dynamic-form-stub-component';
2222

2323
describe('PoPageDynamicEditComponent: ', () => {
2424
let component: PoPageDynamicEditComponent;
2525
let fixture: ComponentFixture<PoPageDynamicEditComponent>;
26+
let poThemeService: jasmine.SpyObj<PoThemeService>;
2627

2728
beforeEach(waitForAsync(() => {
29+
poThemeService = jasmine.createSpyObj('PoThemeService', ['getA11yDefaultSize', 'getA11yLevel']);
30+
2831
TestBed.configureTestingModule({
2932
declarations: [PoPageDynamicEditComponent, PoDynamicFormStubComponent],
3033
schemas: [NO_ERRORS_SCHEMA],
3134
imports: [FormsModule, RouterTestingModule.withRoutes([]), PoDialogModule],
32-
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
35+
providers: [
36+
{ provide: PoThemeService, useValue: poThemeService },
37+
provideHttpClient(withInterceptorsFromDi()),
38+
provideHttpClientTesting()
39+
]
3340
}).compileComponents();
3441
}));
3542

@@ -206,6 +213,46 @@ describe('PoPageDynamicEditComponent: ', () => {
206213

207214
expect(component.duplicates).toEqual(duplicates);
208215
});
216+
217+
describe('p-size:', () => {
218+
it('should update size with valid values', () => {
219+
const validValues = ['medium'];
220+
221+
expectPropertiesValues(component, 'size', validValues, validValues);
222+
});
223+
224+
it('should update size to `medium` with invalid values', () => {
225+
poThemeService.getA11yDefaultSize.and.returnValue('medium');
226+
227+
const invalidValues = ['extraSmall', 'extraLarge'];
228+
229+
expectPropertiesValues(component, 'size', invalidValues, 'medium');
230+
});
231+
232+
it('should use default size when size is not set', () => {
233+
poThemeService.getA11yDefaultSize.and.returnValue('small');
234+
235+
component.size = undefined;
236+
expect(component.size).toBe('small');
237+
});
238+
239+
it('should return `p-size` if it is defined', () => {
240+
component['_size'] = 'large';
241+
expect(component.size).toBe('large');
242+
});
243+
244+
it('should call `getDefaultSize` and return its value if `p-size` is null or undefined', () => {
245+
spyOn(component as any, 'getDefaultSize').and.returnValue('medium');
246+
247+
component['_size'] = null;
248+
expect(component.size).toBe('medium');
249+
expect(component['getDefaultSize']).toHaveBeenCalled();
250+
251+
component['_size'] = undefined;
252+
expect(component.size).toBe('medium');
253+
expect(component['getDefaultSize']).toHaveBeenCalledTimes(2);
254+
});
255+
});
209256
});
210257

211258
describe('Methods: ', () => {
@@ -1620,5 +1667,46 @@ describe('PoPageDynamicEditComponent: ', () => {
16201667
expect(component.model).toEqual(expectedModel);
16211668
});
16221669
});
1670+
1671+
describe('validateSize:', () => {
1672+
it('should return the same size if valid and accessibility level allows it', () => {
1673+
poThemeService.getA11yLevel.and.returnValue(PoThemeA11yEnum.AA);
1674+
1675+
expect(component['validateSize']('small')).toBe('small');
1676+
expect(component['validateSize']('medium')).toBe('medium');
1677+
});
1678+
1679+
it('should return `medium` if p-size is `small` and accessibility level is not `AA`', () => {
1680+
poThemeService.getA11yLevel.and.returnValue(PoThemeA11yEnum.AAA);
1681+
1682+
expect(component['validateSize']('small')).toBe('medium');
1683+
});
1684+
1685+
it('should return default size from getA11yDefaultSize if value is invalid', () => {
1686+
poThemeService.getA11yDefaultSize.and.returnValue('small');
1687+
1688+
expect(component['validateSize']('invalid')).toBe('small');
1689+
});
1690+
1691+
it('should return `medium` if default size is `medium`', () => {
1692+
poThemeService.getA11yDefaultSize.and.returnValue('medium');
1693+
1694+
expect(component['validateSize']('invalid')).toBe('medium');
1695+
});
1696+
});
1697+
1698+
describe('getDefaultSize:', () => {
1699+
it('should return `small` if getA11yDefaultSize returns `small`', () => {
1700+
poThemeService.getA11yDefaultSize.and.returnValue('small');
1701+
1702+
expect(component['getDefaultSize']()).toBe('small');
1703+
});
1704+
1705+
it('should return `medium` if getA11yDefaultSize returns `medium`', () => {
1706+
poThemeService.getA11yDefaultSize.and.returnValue('medium');
1707+
1708+
expect(component['getDefaultSize']()).toBe('medium');
1709+
});
1710+
});
16231711
});
16241712
});

0 commit comments

Comments
 (0)