From 33bd5bd40ad7fcaa13ae6b6727fce3eef7e8df1b Mon Sep 17 00:00:00 2001 From: allan-chagas-brisa Date: Thu, 28 Sep 2023 10:57:26 -0300 Subject: [PATCH] refactor: pr sugested adjustments --- .../modal/component/modal.component.spec.ts | 149 ++++-------------- .../lib/modal/component/modal.component.ts | 3 +- .../src/lib/modal/models/modal.interface.ts | 2 +- 3 files changed, 33 insertions(+), 121 deletions(-) diff --git a/projects/ion/src/lib/modal/component/modal.component.spec.ts b/projects/ion/src/lib/modal/component/modal.component.spec.ts index 9ec417b8a..857454ba9 100644 --- a/projects/ion/src/lib/modal/component/modal.component.spec.ts +++ b/projects/ion/src/lib/modal/component/modal.component.spec.ts @@ -198,6 +198,28 @@ describe('IonModalComponent', () => { }); describe('IonModalComponent - Header left button', () => { + const configuration: IonModalConfiguration = { + id: '1', + title: 'Ion Test', + + footer: { + showDivider: false, + primaryButton: { + label: 'Ion Cancel', + iconType: 'icon', + }, + secondaryButton: { + label: 'Ion Confirm', + iconType: 'icon', + }, + }, + + headerButton: { + icon: 'left', + label: 'voltar', + }, + }; + it('should not be rendered as default', () => { expect(screen.queryByTestId('btn-voltar')).not.toBeInTheDocument(); }); @@ -211,146 +233,37 @@ describe('IonModalComponent', () => { }); it('should be visible as default if the config is informed', () => { - const configuration: IonModalConfiguration = { - id: '1', - title: 'Ion Test', - - footer: { - showDivider: false, - primaryButton: { - label: 'Ion Cancel', - iconType: 'icon', - }, - secondaryButton: { - label: 'Ion Confirm', - iconType: 'icon', - }, - }, - - headerButton: { - icon: 'left', - label: 'voltar', - }, - }; - component.setConfig(configuration); fixture.detectChanges(); expect(screen.getByTestId('btn-voltar')).toBeVisible(); }); - it('should be hidden when informed', () => { - const configuration: IonModalConfiguration = { - id: '1', - title: 'Ion Test', - - footer: { - showDivider: false, - primaryButton: { - label: 'Ion Cancel', - iconType: 'icon', - }, - secondaryButton: { - label: 'Ion Confirm', - iconType: 'icon', - }, - }, - - headerButton: { - icon: 'left', - label: 'voltar', - hidden: () => true, - }, - }; - - component.setConfig(configuration); - fixture.detectChanges(); - expect(screen.queryByTestId('btn-voltar')).not.toBeInTheDocument(); - }); - it('should be enabled as default', () => { - const configuration: IonModalConfiguration = { - id: '1', - title: 'Ion Test', - - footer: { - showDivider: false, - primaryButton: { - label: 'Ion Cancel', - iconType: 'icon', - }, - secondaryButton: { - label: 'Ion Confirm', - iconType: 'icon', - }, - }, - - headerButton: { - icon: 'left', - label: 'voltar', - }, - }; - component.setConfig(configuration); fixture.detectChanges(); expect(screen.getByTestId('btn-voltar')).toBeEnabled(); }); it('should be disabled when informed', () => { - const configuration: IonModalConfiguration = { - id: '1', - title: 'Ion Test', - - footer: { - showDivider: false, - primaryButton: { - label: 'Ion Cancel', - iconType: 'icon', - }, - secondaryButton: { - label: 'Ion Confirm', - iconType: 'icon', - }, - }, - - headerButton: { - icon: 'left', - label: 'voltar', - disabled: () => true, - }, - }; - + configuration.headerButton.disabled = (): boolean => true; component.setConfig(configuration); fixture.detectChanges(); expect(screen.getByTestId('btn-voltar')).toBeDisabled(); }); it('should render the specified icon', () => { - const configuration: IonModalConfiguration = { - id: '1', - title: 'Ion Test', - - footer: { - showDivider: false, - primaryButton: { - label: 'Ion Cancel', - iconType: 'icon', - }, - secondaryButton: { - label: 'Ion Confirm', - iconType: 'icon', - }, - }, - - headerButton: { - icon: 'left', - label: 'voltar', - }, - }; - component.setConfig(configuration); fixture.detectChanges(); const icon = document.getElementById('ion-icon-left'); expect(icon).toBeVisible(); }); + + it('should be hidden when informed', () => { + configuration.headerButton.hidden = (): boolean => true; + + component.setConfig(configuration); + fixture.detectChanges(); + expect(screen.queryByTestId('btn-voltar')).not.toBeInTheDocument(); + }); }); }); diff --git a/projects/ion/src/lib/modal/component/modal.component.ts b/projects/ion/src/lib/modal/component/modal.component.ts index c3f33e339..b83585328 100644 --- a/projects/ion/src/lib/modal/component/modal.component.ts +++ b/projects/ion/src/lib/modal/component/modal.component.ts @@ -18,7 +18,6 @@ import { IonModalConfiguration, IonModalResponse, } from '../models/modal.interface'; -import { SafeAny } from '../../utils/safe-any'; @Component({ selector: 'ion-modal', @@ -35,7 +34,7 @@ export class IonModalComponent implements OnInit, OnDestroy { @Input() configuration: IonModalConfiguration = {}; @Output() - ionOnHeaderButtonAction = new EventEmitter(); + ionOnHeaderButtonAction = new EventEmitter(); ionOnClose = new EventEmitter(); public DEFAULT_WIDTH = 500; diff --git a/projects/ion/src/lib/modal/models/modal.interface.ts b/projects/ion/src/lib/modal/models/modal.interface.ts index d2f9fcb27..e6fb34b31 100644 --- a/projects/ion/src/lib/modal/models/modal.interface.ts +++ b/projects/ion/src/lib/modal/models/modal.interface.ts @@ -22,8 +22,8 @@ export interface IonModalFooterConfiguration { } interface IonModalHeaderButton { - label: string; icon: IconType; + label?: string; disabled?: () => boolean; hidden?: () => boolean; }