Skip to content

Commit

Permalink
Merge pull request #312 from PermanentOrg/PER-9374-show-amount-invita…
Browse files Browse the repository at this point in the history
…tion

Per 9374 show amount invitation
  • Loading branch information
crisnicandrei authored Oct 31, 2023
2 parents 047bd8c + f33f0fc commit efbe555
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- @format -->
<div class="dialog-content">
<div class="header">
<span>Invitations</span>
Expand All @@ -7,15 +8,25 @@
</div>
<div class="content">
<div class="tabs">
<div class="dialog-tab"
(click)="setTab('new')" [class.active]="activeTab === 'new'">
<div
class="dialog-tab"
(click)="setTab('new')"
[class.active]="activeTab === 'new'"
>
Send Invite
</div>
<div class="dialog-tab"
(click)="setTab('pending')" [class.active]="activeTab === 'pending'">
<div
class="dialog-tab"
(click)="setTab('pending')"
[class.active]="activeTab === 'pending'"
>
Pending Invites
</div>
<div class="dialog-tab" (click)="setTab('accepted')" [class.active]="activeTab === 'accepted'">
<div
class="dialog-tab"
(click)="setTab('accepted')"
[class.active]="activeTab === 'accepted'"
>
Accepted Invites
</div>
</div>
Expand All @@ -24,69 +35,120 @@
<ng-container *ngSwitchCase="'new'">
<div class="banner">
<div>
<div class="banner-heading">
Give a gig, get a gig
</div>
<div class="banner-heading">Give a gig, get a gig</div>
<div class="banner-text">
Invite your friends and family to sign up and both of your accounts will be credited with one free gigabyte of storage.
Invite your friends and family to sign up and both of your
accounts will be credited with one free gigabyte of storage.
</div>
</div>
</div>
<form [formGroup]="newInviteForm" class="dialog-form" (submit)="onNewInviteFormSubmit(newInviteForm.value)">
<form
[formGroup]="newInviteForm"
class="dialog-form"
(submit)="onNewInviteFormSubmit(newInviteForm.value)"
>
<div class="dialog-form-field">
<label for="name">Recipient Name</label>
<input type="text" class="form-control" id="newInviteName" name="name"
formControlName="fullName">
<input
type="text"
class="form-control"
id="newInviteName"
name="name"
formControlName="fullName"
/>
</div>
<div class="dialog-form-field">
<label for="email">Recipient Email</label>
<input type="email" class="form-control" id="newInviteEmail" name="email"
formControlName="email">
<input
type="email"
class="form-control"
id="newInviteEmail"
name="email"
formControlName="email"
/>
</div>
<div class="dialog-form-field">
<button class="btn btn-primary" [disabled]="newInviteForm.invalid || waiting">Send Invitation</button>
<button
class="btn btn-primary"
[disabled]="newInviteForm.invalid || waiting"
>
Send Invitation
</button>
</div>
</form>
</ng-container>
<ng-container *ngSwitchCase="'pending'">
<div class="invitation-list">
<div *ngIf="pendingInvites.length" class="invitation-list">
<div class="list-header">
<div class="date">Date Sent</div>
<div class="email">Email</div>
<div class="name">Name</div>
<div class="amount">Amount</div>
<div class="actions">&nbsp;</div>
</div>
<div class="invitation" *ngFor="let invite of pendingInvites">
<div class="date">{{invite.updatedDT | date}}</div>
<div class="email">{{invite.email}}</div>
<div class="name" [hidden]="!invite.fullName">{{invite.fullName}}</div>
<div class="name" [hidden]="invite.fullName"><em>None given</em></div>
<div class="date">{{ invite.updatedDT | date }}</div>
<div class="email">{{ invite.email }}</div>
<div class="name" [hidden]="!invite.fullName">
{{ invite.fullName }}
</div>
<div class="name" [hidden]="invite.fullName">
<em>None given</em>
</div>
<div class="amount none" *ngIf="!invite.giftSizeInMB">
<em>None given</em>
</div>
<div class="amount has-amount" *ngIf="invite.giftSizeInMB">
{{ invite.giftSizeInMB / 1024 }} GB
</div>
<div class="actions">
<button class="btn btn-primary" (click)="resendInvite(invite)" [disabled]="waiting">Resend</button>
<button
class="btn btn-primary"
(click)="resendInvite(invite)"
[disabled]="waiting"
>
Resend
</button>
</div>
</div>
<div class="text-muted">No invitations sent</div>
</div>
<div *ngIf="!pendingInvites.length" class="text-muted">
No invitations sent
</div>
</ng-container>
<ng-container *ngSwitchCase="'accepted'">
<div class="invitation-list">
<div *ngIf="acceptedInvites.length" class="invitation-list">
<div class="list-header">
<div class="date">Date Accepted</div>
<div class="email">Email</div>
<div class="name">Name</div>
<div class="amount">Amount</div>
<div class="actions">&nbsp;</div>
</div>
<div class="invitation" *ngFor="let invite of acceptedInvites">
<div class="date">{{invite.updatedDT | date}}</div>
<div class="email">{{invite.email}}</div>
<div class="name" [hidden]="!invite.fullName">{{invite.fullName}}</div>
<div class="name" [hidden]="invite.fullName"><em>None given</em></div>
<div class="date">{{ invite.updatedDT | date }}</div>
<div class="email">{{ invite.email }}</div>
<div class="name" [hidden]="!invite.fullName">
{{ invite.fullName }}
</div>
<div class="name" [hidden]="invite.fullName">
<em>None given</em>
</div>
<div class="amount none" [hidden]="invite.giftSizeInMB">
<em>None given</em>
</div>
<div class="amount has-amount" [hidden]="!invite.giftSizeInMB">
{{ invite.giftSizeInMB / 1024 }} GB
</div>

<div class="actions">&nbsp;</div>
</div>
<div class="text-muted">No invitations accepted</div>
</div>
<div *ngIf="!acceptedInvites.length" class="text-muted">
No invitations accepted
</div>
</ng-container>
</ng-container>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* @format */
@import 'variables';

:host {
Expand All @@ -6,7 +7,7 @@
}

.header {
@include tabbedDialogHeader($PR-purple)
@include tabbedDialogHeader($PR-purple);
}

.content {
Expand Down Expand Up @@ -41,7 +42,8 @@ form {
}

.invitation-list {
.invitation, .list-header {
.invitation,
.list-header {
display: flex;
align-items: center;
height: 3 * $grid-unit;
Expand All @@ -61,12 +63,18 @@ form {
flex: 0 0 9rem;
}

.name, .email {
.name,
.email,
.amount {
flex: 0 1 50%;
overflow: hidden;
text-overflow: ellipsis;
}

.amount {
flex: 0 1 30%;
}

.actions {
flex: 0 0 5rem;
margin-left: auto;
Expand All @@ -75,4 +83,4 @@ form {
@include gridHeightButtonSmall;
}
}
}
}
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);
});
});
Loading

0 comments on commit efbe555

Please sign in to comment.