-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b19a58d
commit f26b2da
Showing
4 changed files
with
181 additions
and
7 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/app/components/table/table-inspect-message-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Clipboard } from '@angular/cdk/clipboard'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { IconsService } from '@services/icons.service'; | ||
import { NotificationService } from '@services/notification.service'; | ||
import { TableInspectMessageDialogComponent, TableInspectMessageDialogData } from './table-inspect-message-dialog.component'; | ||
|
||
describe('TableInspectMessageDialogComponent', () => { | ||
let component: TableInspectMessageDialogComponent; | ||
|
||
const label = 'Message'; | ||
|
||
const message = 'A long and complete message'; | ||
|
||
const mockMatDialogRef = { | ||
close: jest.fn() | ||
}; | ||
|
||
const mockData: TableInspectMessageDialogData = { | ||
label: label, | ||
message: message, | ||
}; | ||
|
||
const mockNotificationService = { | ||
success: jest.fn(), | ||
}; | ||
|
||
const mockClipboard = { | ||
copy: jest.fn() | ||
}; | ||
|
||
beforeEach(() => { | ||
component = TestBed.configureTestingModule({ | ||
providers: [ | ||
TableInspectMessageDialogComponent, | ||
IconsService, | ||
{ provide: Clipboard, useValue: mockClipboard }, | ||
{ provide: NotificationService, useValue: mockNotificationService }, | ||
{ provide: MatDialogRef, useValue: mockMatDialogRef }, | ||
{ provide: MAT_DIALOG_DATA, useValue: mockData } | ||
] | ||
}).inject(TableInspectMessageDialogComponent); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should get label', () => { | ||
expect(component.label).toEqual(label); | ||
}); | ||
|
||
it('should get message', () => { | ||
expect(component.message).toEqual(message); | ||
}); | ||
|
||
describe('onCopy', () => { | ||
beforeEach(() => { | ||
component.copy(); | ||
}); | ||
|
||
it('should copy the message', () => { | ||
expect(mockClipboard.copy).toHaveBeenCalledWith(message); | ||
}); | ||
|
||
it('should notify the user', () => { | ||
expect(mockNotificationService.success).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should get icon', () => { | ||
expect(component.getIcon('heart')).toEqual('favorite'); | ||
}); | ||
|
||
it('should close dialog', () => { | ||
component.onNoClick(); | ||
expect(mockMatDialogRef.close).toHaveBeenCalled(); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
src/app/components/table/table-inspect-message.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/app/components/table/table-inspect-message.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Clipboard } from '@angular/cdk/clipboard'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MatDialog } from '@angular/material/dialog'; | ||
import { IconsService } from '@services/icons.service'; | ||
import { NotificationService } from '@services/notification.service'; | ||
import { TableInspectMessageDialogComponent } from './table-inspect-message-dialog.component'; | ||
import { TableInspectMessageComponent } from './table-inspect-message.component'; | ||
|
||
describe('TableInspectMessageComponent', () => { | ||
let component: TableInspectMessageComponent; | ||
|
||
const label = 'Message'; | ||
|
||
const message = 'A long and complete message'; | ||
|
||
const mockNotificationService = { | ||
success: jest.fn(), | ||
}; | ||
|
||
const mockDialog = { | ||
open: jest.fn() | ||
}; | ||
|
||
const mockClipboard = { | ||
copy: jest.fn() | ||
}; | ||
|
||
beforeEach(() => { | ||
component = TestBed.configureTestingModule({ | ||
providers: [ | ||
TableInspectMessageComponent, | ||
IconsService, | ||
{ provide: NotificationService, useValue: mockNotificationService }, | ||
{ provide: MatDialog, useValue: mockDialog }, | ||
{ provide: Clipboard, useValue: mockClipboard } | ||
] | ||
}).inject(TableInspectMessageComponent); | ||
component.label = label; | ||
component.message = message; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('setting message', () => { | ||
it('should set the cropped message', () => { | ||
expect(component.croppedMessage).toEqual('A long and com...'); | ||
}); | ||
|
||
it('should display the eye', () => { | ||
expect(component.displayEye).toBeTruthy(); | ||
}); | ||
|
||
it('should set the full message if it not too long', () => { | ||
const newMessage = 'message'; | ||
component.message = newMessage; | ||
expect(component.croppedMessage).toEqual(newMessage); | ||
}); | ||
|
||
it('should not display the eye if the message is too long', () => { | ||
component.message = 'message'; | ||
expect(component.displayEye).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('onCopy', () => { | ||
beforeEach(() => { | ||
component.copy(); | ||
}); | ||
|
||
it('should copy the message', () => { | ||
expect(mockClipboard.copy).toHaveBeenCalledWith(message); | ||
}); | ||
|
||
it('should notify the user', () => { | ||
expect(mockNotificationService.success).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should get icon', () => { | ||
expect(component.getIcon('heart')).toEqual('favorite'); | ||
}); | ||
|
||
describe('on View', () => { | ||
beforeEach(() => { | ||
component.onView(); | ||
}); | ||
|
||
it('should display pass the data to the dialog', () => { | ||
expect(mockDialog.open).toHaveBeenCalledWith(TableInspectMessageDialogComponent, { | ||
data: { | ||
label: label, | ||
message: message | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters