-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from PermanentOrg/PER-9374-show-amount-invita…
…tion Per 9374 show amount invitation
- Loading branch information
Showing
5 changed files
with
282 additions
and
42 deletions.
There are no files selected for viewing
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
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
147 changes: 147 additions & 0 deletions
147
src/app/core/components/invitations-dialog/invitations-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,147 @@ | ||
/* @format */ | ||
import { ApiService } from '@shared/services/api/api.service'; | ||
import { DialogRef, DIALOG_DATA } from '@root/app/dialog/dialog.module'; | ||
import { InviteVO } from '@root/app/models'; | ||
import { CoreModule } from '@core/core.module'; | ||
import { Shallow } from 'shallow-render'; | ||
import { MessageService } from '@shared/services/message/message.service'; | ||
import { InvitationsDialogComponent } from './invitations-dialog.component'; | ||
|
||
const mockApiService = { | ||
invite: { | ||
getInvites(): Promise<InviteVO[]> { | ||
return Promise.resolve([new InviteVO({ email: '[email protected]' })]); | ||
}, | ||
}, | ||
}; | ||
|
||
describe('InvitationsDialog', () => { | ||
let shallow: Shallow<InvitationsDialogComponent>; | ||
const dialogRef = new DialogRef(1, null); | ||
let messageShown: boolean = false; | ||
|
||
beforeEach(() => { | ||
shallow = new Shallow(InvitationsDialogComponent, CoreModule) | ||
.mock(DIALOG_DATA, { useValue: {} }) | ||
.mock(DialogRef, dialogRef) | ||
.mock(ApiService, mockApiService) | ||
.mock(MessageService, { | ||
showError: () => { | ||
messageShown = true; | ||
}, | ||
}); | ||
}); | ||
|
||
it('exists', async () => { | ||
const { element } = await shallow.render(); | ||
expect(element).not.toBeNull(); | ||
}); | ||
|
||
it('displays the pending invitations table if there are any invitations pending', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'pending'; | ||
instance.pendingInvites = [new InviteVO({ email: '[email protected]' })]; | ||
|
||
fixture.detectChanges(); | ||
|
||
const table = find('.invitation'); | ||
|
||
expect(table.length).toBe(instance.pendingInvites.length); | ||
}); | ||
|
||
it('displays the "no pending invites" message if there are no invites', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'pending'; | ||
instance.pendingInvites = []; | ||
|
||
fixture.detectChanges(); | ||
|
||
const message = find('.text-muted'); | ||
|
||
expect(message).not.toBeNull(); | ||
}); | ||
|
||
it('displays the accepted invitations table if there are any accepted pending', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'accepted'; | ||
instance.acceptedInvites = [new InviteVO({ email: '[email protected]' })]; | ||
|
||
fixture.detectChanges(); | ||
|
||
const table = find('.invitation'); | ||
|
||
expect(table.length).toBe(instance.acceptedInvites.length); | ||
}); | ||
|
||
it('displays the "no accepted invites" message if there are no invites', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'accepted'; | ||
instance.acceptedInvites = []; | ||
|
||
fixture.detectChanges(); | ||
|
||
const message = find('.text-muted'); | ||
|
||
expect(message).not.toBeNull(); | ||
}); | ||
|
||
it('displays the gifted amount in the table if there is any, otherwise display the "None Given" text', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'pending'; | ||
instance.pendingInvites = [ | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: null }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: null }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
]; | ||
|
||
fixture.detectChanges(); | ||
|
||
const invitesWithGift = find('.has-amount'); | ||
const invitesWithoutGift = find('.none'); | ||
|
||
expect(invitesWithGift.length).toBe(3); | ||
expect(invitesWithoutGift.length).toBe(2); | ||
}); | ||
|
||
it('displays the amount sent in the invite', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'pending'; | ||
instance.pendingInvites = [ | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 2048 }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
]; | ||
|
||
fixture.detectChanges(); | ||
|
||
const invitesWithGift = find('.has-amount'); | ||
|
||
const giftedAmount = invitesWithGift[1].nativeElement.textContent.trim(); | ||
|
||
const expectedText = `${instance.pendingInvites[1].giftSizeInMB / 1024} GB`; | ||
|
||
expect(giftedAmount).toBe(expectedText); | ||
}); | ||
|
||
it('displays the "None given" text if no amount was sent in the invite', async () => { | ||
const { fixture, find, instance } = await shallow.render(); | ||
instance.activeTab = 'pending'; | ||
instance.pendingInvites = [ | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: null }), | ||
new InviteVO({ email: '[email protected]', giftSizeInMB: 1024 }), | ||
]; | ||
|
||
fixture.detectChanges(); | ||
|
||
const invitesWithGift = find('.invitation .amount'); | ||
|
||
const giftedAmount = invitesWithGift[1].nativeElement.textContent.trim(); | ||
|
||
const expectedText = `None given`; | ||
|
||
expect(giftedAmount).toBe(expectedText); | ||
}); | ||
}); |
Oops, something went wrong.