Skip to content

Commit

Permalink
feat(multiselect): ajusta testes da tag
Browse files Browse the repository at this point in the history
  • Loading branch information
CSimoesJr committed Oct 27, 2023
1 parent 1dc06be commit fb80e13
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ export class PoMultiselectComponent
}

toggleDropdownVisibility() {
// this.inputElement.nativeElement.setAttribute('aria-label', `${this.label}`);
if (this.disabled) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { expectPropertiesValues } from '../../util-test/util-expect.spec';

import { PoColorPaletteEnum } from '../../enums/po-color-palette.enum';

import { PoTagBaseComponent } from './po-tag-base.component';
import { poLocaleDefault } from './../../services/po-language/po-language.constant';
import { PoLanguageService } from './../../services/po-language/po-language.service';
import { PoTagOrientation } from './enums/po-tag-orientation.enum';
import { PoTagType } from './enums/po-tag-type.enum';
import { PoLanguageService } from './../../services/po-language/po-language.service';
import { PoTagBaseComponent, PoTagLiteralsDefault } from './po-tag-base.component';

describe('PoTagBaseComponent:', () => {
const component = new PoTagBaseComponent(new PoLanguageService());
Expand Down Expand Up @@ -132,5 +133,74 @@ describe('PoTagBaseComponent:', () => {
component.textColor = 'deep red';
expect(component.customTextColor).toBe(undefined);
});

it('p-literals: should be in portuguese if browser is setted with an unsupported language', () => {
component['language'] = 'zw';

component.literals = {};

expect(component.literals).toEqual(PoTagLiteralsDefault[poLocaleDefault]);
});

it('p-literals: should be in portuguese if browser is setted with `pt`', () => {
component['language'] = 'pt';

component.literals = {};

expect(component.literals).toEqual(PoTagLiteralsDefault.pt);
});

it('p-literals: should be in english if browser is setted with `en`', () => {
component['language'] = 'en';

component.literals = {};

expect(component.literals).toEqual(PoTagLiteralsDefault.en);
});

it('p-literals: should be in spanish if browser is setted with `es`', () => {
component['language'] = 'es';

component.literals = {};

expect(component.literals).toEqual(PoTagLiteralsDefault.es);
});

it('p-literals: should be in russian if browser is setted with `ru`', () => {
component['language'] = 'ru';

component.literals = {};

expect(component.literals).toEqual(PoTagLiteralsDefault.ru);
});

it('p-literals: should accept custom literals', () => {
component['language'] = poLocaleDefault;

const customLiterals = Object.assign({}, PoTagLiteralsDefault[poLocaleDefault]);

// Custom some literals
customLiterals.remove = 'Remove custom';

component.literals = customLiterals;

expect(component.literals).toEqual(customLiterals);
});

it('p-literals: should update property with default literals if is setted with invalid values', () => {
const invalidValues = [null, undefined, false, true, '', 'literals', 0, 10, [], [1, 2], () => {}];

component['language'] = poLocaleDefault;

expectPropertiesValues(component, 'literals', invalidValues, PoTagLiteralsDefault[poLocaleDefault]);
});

it('p-literals: should update property with default literals if _literals is undefined', () => {
component['language'] = 'pt';

component['_literals'] = undefined;

expect(component.literals).toEqual(PoTagLiteralsDefault.pt);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,16 @@ export class PoTagBaseComponent {
*
* ```
* const customLiterals: PoTagLiterals = {
* noData: 'Sem dados'
* remove: 'Remover itens'
* };
* ```
*
* E para carregar as literais customizadas, basta apenas passar o objeto para o componente:
*
* ```
* <po-multiselect
* <po-tag
* [p-literals]="customLiterals">
* </po-po-multiselect>
* </po-tag>
* ```
*
* > O objeto padrão de literais será traduzido de acordo com o idioma do
Expand Down
8 changes: 7 additions & 1 deletion projects/ui/src/lib/components/po-tag/po-tag.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
>
</po-icon>

<div #tagContainer class="po-tag-value" [p-tooltip]="getWidthTag() ? value : ''" p-tooltip-position="top">
<div
#tagContainer
class="po-tag-value"
[p-tooltip]="getWidthTag() ? value : ''"
p-tooltip-position="top"
[class.po-tag-container-horizontal]="tagOrientation"
>
<span
[ngStyle]="
!tagColor && inverse && !customTextColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ describe('PoTagComponent:', () => {

component.onClick();

expect(component.click.emit).toHaveBeenCalledWith({ 'value': component.value, 'type': component.type });
expect(component.click.emit).toHaveBeenCalledWith({
'value': component.value,
'type': component.type,
'event': 'click'
});
});

it('onKeyPressed: should call `onClick` if the event `keydown` is used with `enter` key.', () => {
Expand Down Expand Up @@ -192,7 +196,7 @@ describe('PoTagComponent:', () => {

component.onClose();

expect(component.click.emit).toHaveBeenCalledWith(null);
expect(component.click.emit).toHaveBeenCalledWith('click');
});

it('onRemove: Should remove the element if not disabled', () => {
Expand Down

0 comments on commit fb80e13

Please sign in to comment.