Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(message-hour): cria novo componente message-hour #1874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions projects/ui/src/lib/components/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';

import { PoAccordionModule } from './po-accordion/po-accordion.module';
import { PoAvatarModule } from './po-avatar/po-avatar.module';
import { PoBadgeModule } from './po-badge/po-badge.module';
import { PoBreadcrumbModule } from './po-breadcrumb/po-breadcrumb.module';
import { PoButtonGroupModule } from './po-button-group/po-button-group.module';
import { PoButtonModule } from './po-button/po-button.module';
Expand Down Expand Up @@ -37,7 +36,6 @@ import { PoPageModule } from './po-page/po-page.module';
import { PoPopoverModule } from './po-popover/po-popover.module';
import { PoPopupModule } from './po-popup/po-popup.module';
import { PoProgressModule } from './po-progress/po-progress.module';
import { PoSearchModule } from './po-search';
import { PoSlideModule } from './po-slide/po-slide.module';
import { PoStepperModule } from './po-stepper/po-stepper.module';
import { PoTableModule } from './po-table/po-table.module';
Expand All @@ -47,6 +45,10 @@ import { PoToolbarModule } from './po-toolbar/po-toolbar.module';
import { PoTreeViewModule } from './po-tree-view/po-tree-view.module';
import { PoWidgetModule } from './po-widget/po-widget.module';
import { PoToasterModule } from './po-toaster';
import { PoSearchModule } from './po-search';
import { PoBadgeModule } from './po-badge/po-badge.module';
import { PoMessageHourModule } from './po-message-hour';

@NgModule({
imports: [
PoAccordionModule,
Expand Down Expand Up @@ -95,7 +97,8 @@ import { PoToasterModule } from './po-toaster';
PoSwitchModule,
PoSearchModule,
PoBadgeModule,
PoToasterModule
PoToasterModule,
PoMessageHourModule
],
exports: [
PoAccordionModule,
Expand Down Expand Up @@ -144,7 +147,8 @@ import { PoToasterModule } from './po-toaster';
PoSwitchModule,
PoSearchModule,
PoBadgeModule,
PoToasterModule
PoToasterModule,
PoMessageHourModule
],
providers: [],
bootstrap: [],
Expand Down
1 change: 1 addition & 0 deletions projects/ui/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export * from './po-tree-view/index';
export * from './po-widget/index';
export * from './po-search/index';
export * from './po-toaster/index';
export * from './po-message-hour/index';
3 changes: 3 additions & 0 deletions projects/ui/src/lib/components/po-message-hour/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './po-message-hour.component';

export * from './po-message-hour.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface PoMessageHourLiterals {
/**
* @usedBy PoMessageHour
*
* @description
*
* Interface para configuração de mensagem de saudação.
*/
salutation?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PoMessageHourBaseComponent } from './po-message-hour-base.component';

describe('PoMessageHourBaseComponent:', () => {
let component: PoMessageHourBaseComponent;

beforeEach(() => {
component = new PoMessageHourBaseComponent();
});

it('should be created', () => {
expect(component instanceof PoMessageHourBaseComponent).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Directive, EventEmitter, Input, Output } from '@angular/core';

/**
* @description
*
* O componente `PoMessageHour` é responsável por exibir mensagens horárias personalizadas com base no período do dia.
*
* #### Boas Práticas
*
* Este componente é projetado seguindo as práticas recomendadas para proporcionar uma experiência de usuário eficiente e acessível, sendo especialmente útil para saudações exibidas após alguma ação do usuário:
*
* ##### Uso
* - Gera mensagens de saudação de acordo com o período do dia: madrugada, manhã, tarde ou noite.
*
* ##### Acessibilidade
* - Utiliza controles HTML padrão para permitir a identificação por tecnologias assistivas.
* - Mantém o underline no link para diferenciar de textos comuns, atendendo às diretrizes de contraste.
* - Preserva o estado de foco do componente e garante que a aparência do foco atenda aos requisitos de acessibilidade.
*
*/
@Directive()
export class PoMessageHourBaseComponent {
/**
* @optional
*
* @description
*
* Label da mensagem.
*/
@Input('p-label') label?: string;

/**
* @optional
*
* @description
*
* Evento emitido quando o período do dia da mensagem é atualizado.
* O período do dia pode ser 'dawn' (madrugada), 'morning' (manhã), 'afternoon' (tarde) ou 'night' (noite).
*/
@Output('p-message-hour') messageHour = new EventEmitter<string>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="container">
<span class="label">{{ label }}</span>
<po-link [p-label]="message"></po-link>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { PoMessageHourComponent } from './po-message-hour.component';

describe('PoMessageHourComponent', () => {
let component: PoMessageHourComponent;
let fixture: ComponentFixture<PoMessageHourComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [PoMessageHourComponent]
});
fixture = TestBed.createComponent(PoMessageHourComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should set message for dawn', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(4);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.dawn}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.dawn}`
);
});

it('should set message for morning', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(10);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.morning}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.morning}`
);
});

it('should set message for night', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(21);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.night}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.night}`
);
});

it('should set message for afternoon', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(15);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.afternoon}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.afternoon}`
);
});

it('should set message for edge case: 5 AM', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(5);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.dawn}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.dawn}`
);
});

it('should set message for edge case: 12 PM', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(12);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.afternoon}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.afternoon}`
);
});

it('should set message for edge case: 6 PM', () => {
spyOn(component.messageHour, 'emit');

spyOn(component, 'getCurrentHour').and.returnValue(18);

component.setMessage();

expect(component.message).toEqual(`${component.literals.salutation} ${component.literals.night}`);
expect(component.messageHour.emit).toHaveBeenCalledWith(
`${component.literals.salutation} ${component.literals.night}`
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Component } from '@angular/core';
import { PoMessageHourLiterals } from './literals/po-message-hour-literals';
import { PoMessageHourBaseComponent } from './po-message-hour-base.component';

export const poMessageHourDefault = {
en: <PoMessageHourLiterals>{
salutation: 'Welcome',
dawn: 'Good dawn',
morning: 'Good morning',
afternoon: 'Good afternoon',
night: 'Good night'
},
es: <PoMessageHourLiterals>{
salutation: 'Bienvenido',
dawn: 'Buen amanecer',
morning: 'Buenos días',
afternoon: 'Buenas tardes',
night: 'Buenas noches'
},
pt: <PoMessageHourLiterals>{
salutation: 'Bem vindo',
dawn: 'Boa madrugada',
morning: 'Bom dia',
afternoon: 'Boa tarde',
night: 'Boa noite'
},
ru: <PoMessageHourLiterals>{
salutation: 'добро пожаловать',
dawn: 'Доброй ночи',
morning: 'Доброе утро',
afternoon: 'Добрый день',
night: 'Добрый вечер'
}
};

/**
* @docsExtends PoMessageHourBaseComponent
*
* @example
*
* <example name="po-message-hour-basic" title="PO Message Hour Basic">
* <file name="sample-po-message-hour-basic/sample-po-message-hour-basic.component.html"> </file>
* <file name="sample-po-message-hour-basic/sample-po-message-hour-basic.component.ts"> </file>
* </example>
*
* <example name="po-message-hour-menu" title="PO Message Hour - Human Resources">
* <file name="sample-po-message-hour-menu/sample-po-message-hour-menu.component.html"> </file>
* <file name="sample-po-message-hour-menu/sample-po-message-hour-menu.component.ts"> </file>
* </example>
*/
@Component({
selector: 'po-message-hour',
templateUrl: './po-message-hour.component.html'
})
export class PoMessageHourComponent extends PoMessageHourBaseComponent {
public literals?: any;

message: string;

ngOnInit() {

Check warning on line 60 in projects/ui/src/lib/components/po-message-hour/po-message-hour.component.ts

View workflow job for this annotation

GitHub Actions / lint

Lifecycle interface 'OnInit' should be implemented for method 'ngOnInit'. (https://angular.io/styleguide#style-09-01)
const browserLanguage = navigator.language.split('-')[0];
this.literals = poMessageHourDefault[browserLanguage];

this.setMessage();
}

getCurrentHour() {
return new Date().getHours();
}

setMessage() {
const hour = this.getCurrentHour();
let timeOfDay = '';

if (hour <= 5) {
timeOfDay = this.literals.dawn;
} else if (hour < 12) {
timeOfDay = this.literals.morning;
} else if (hour < 18) {
timeOfDay = this.literals.afternoon;
} else {
timeOfDay = this.literals.night;
}

this.message = `${this.literals.salutation} ${timeOfDay}`;
this.messageHour.emit(this.message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { PoMessageHourComponent } from './po-message-hour.component';
import { PoLinkModule } from '../po-link';

/**
* @description
*
* Módulo do componente po-message-hour.
*/
@NgModule({
declarations: [PoMessageHourComponent],
imports: [CommonModule, RouterModule, PoLinkModule],
exports: [PoMessageHourComponent, PoLinkModule]
})
export class PoMessageHourModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<po-message-hour p-label="Arya Stark"></po-message-hour>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from '@angular/core';

@Component({
selector: 'sample-po-message-hour-basic',
templateUrl: './sample-po-message-hour-basic.component.html'
})
export class SamplePoMessageHourBasicComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="po-wrapper">
<po-menu p-filter="true" p-collapsed [p-menus]="menus">
<ng-template p-menu-header-template>
<po-message-hour p-label="Jon Snow"></po-message-hour>
</ng-template>
</po-menu>
</div>
Loading
Loading