Skip to content

Commit

Permalink
Merge pull request #15493 from dobanisola-scottlogic/fix-messages-com…
Browse files Browse the repository at this point in the history
…ponent-unit-test

fix message and messages component unit test #15492
  • Loading branch information
cetincakiroglu authored May 8, 2024
2 parents a521b10 + 04f6e4c commit 78b52cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/components/dynamicdialog/dynamicdialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class TestDynamicDialogWithClosableFalseComponent {
})
export class FakeTestDialogModule {}

fdescribe('DynamicDialog', () => {
describe('DynamicDialog', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, FakeTestDialogModule],
Expand Down
11 changes: 6 additions & 5 deletions src/app/components/message/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ describe('UIMessage', () => {
expect(iconEl.nativeElement.parentElement.tagName.toLowerCase()).toEqual('infocircleicon');
});

it('should change severity to error', () => {
message.severity = 'error';
it('should change severity to danger', () => {
message.severity = 'danger';
fixture.detectChanges();

const messageEl = fixture.debugElement.query(By.css('div'));
const iconEl = fixture.debugElement.query(By.css('.p-inline-message-icon'));
expect(messageEl.nativeElement).toBeTruthy();
expect(messageEl.nativeElement.className).toContain('p-inline-message-error');
expect(messageEl.nativeElement.className).toContain('p-inline-message-danger');
expect(iconEl.nativeElement.parentElement.tagName.toLowerCase()).toEqual('timescircleicon');
});

it('should change severity to warning', () => {
message.severity = 'warn';
message.severity = 'warning';
fixture.detectChanges();

const messageEl = fixture.debugElement.query(By.css('div'));
Expand All @@ -67,8 +67,9 @@ describe('UIMessage', () => {
expect(messageEl.nativeElement.className).toContain('p-inline-message-warn');
expect(iconEl.nativeElement.parentElement.tagName.toLowerCase()).toEqual('exclamationtriangleicon');
});

it('should change severity to default', () => {
message.severity = ' ';
message.severity = 'primary';
fixture.detectChanges();

const messageEl = fixture.debugElement.query(By.css('div'));
Expand Down
20 changes: 20 additions & 0 deletions src/app/components/messages/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TimesIcon } from 'primeng/icons/times';
<button type="button" pButton (click)="showAllViaService()" label="Use Service"></button>
<button type="button" pButton (click)="clearWithService()" label="Use Service"></button>
<button type="button" pButton (click)="clearWithServiceAndKey()" label="Use Service"></button>
<button type="button" pButton (click)="showClosableFalse()" label="Not Closable"></button>
`
})
class TestMessagesComponent {
Expand Down Expand Up @@ -69,6 +70,11 @@ class TestMessagesComponent {
]);
}

showClosableFalse() {
this.msgs = [];
this.msgs.push({ summary: 'Not Closable Message', detail: 'Not closable', closable: false });
}

clearWithService() {
this.messageService.clear();
}
Expand Down Expand Up @@ -243,4 +249,18 @@ describe('Messages', () => {
const messageEl = fixture.debugElement.queryAll(By.css('.p-message-icon'));
expect(messageEl.length).toEqual(2);
});

it('should disable closable messages', () => {
fixture.detectChanges();

const closableButton = fixture.debugElement.queryAll(By.css('button'))[9];
closableButton.nativeElement.click();
fixture.detectChanges();

const detailEl = fixture.debugElement.query(By.css('.p-message-detail'));
const clearButton = fixture.debugElement.query(By.css('.p-message-close'));

expect(clearButton).toBeFalsy();
expect(detailEl.nativeElement.innerHTML).toContain('Not closable');
});
});

0 comments on commit 78b52cb

Please sign in to comment.