Skip to content

Commit

Permalink
refactor: pr sugested adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
allan-chagas-brisa committed Sep 28, 2023
1 parent 62796d2 commit 33bd5bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 121 deletions.
149 changes: 31 additions & 118 deletions projects/ion/src/lib/modal/component/modal.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
});
});
});
3 changes: 1 addition & 2 deletions projects/ion/src/lib/modal/component/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
IonModalConfiguration,
IonModalResponse,
} from '../models/modal.interface';
import { SafeAny } from '../../utils/safe-any';

@Component({
selector: 'ion-modal',
Expand All @@ -35,7 +34,7 @@ export class IonModalComponent implements OnInit, OnDestroy {
@Input() configuration: IonModalConfiguration = {};

@Output()
ionOnHeaderButtonAction = new EventEmitter<SafeAny>();
ionOnHeaderButtonAction = new EventEmitter<IonModalResponse | undefined>();
ionOnClose = new EventEmitter<IonModalResponse | undefined>();

public DEFAULT_WIDTH = 500;
Expand Down
2 changes: 1 addition & 1 deletion projects/ion/src/lib/modal/models/modal.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface IonModalFooterConfiguration {
}

interface IonModalHeaderButton {
label: string;
icon: IconType;
label?: string;
disabled?: () => boolean;
hidden?: () => boolean;
}
Expand Down

0 comments on commit 33bd5bd

Please sign in to comment.