Skip to content

Commit

Permalink
PER-9374
Browse files Browse the repository at this point in the history
Added more tests.
  • Loading branch information
crisnicandrei committed Oct 31, 2023
1 parent 1c3f9b0 commit f33f0fc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
<div class="name" [hidden]="invite.fullName">
<em>None given</em>
</div>
<div class="amount" [hidden]="invite.giftSizeInMB">
<div class="amount none" *ngIf="!invite.giftSizeInMB">
<em>None given</em>
</div>
<div class="amount" [hidden]="!invite.giftSizeInMB">
<div class="amount has-amount" *ngIf="invite.giftSizeInMB">
{{ invite.giftSizeInMB / 1024 }} GB
</div>
<div class="actions">
Expand Down Expand Up @@ -134,10 +134,10 @@
<div class="name" [hidden]="invite.fullName">
<em>None given</em>
</div>
<div class="amount" [hidden]="invite.giftSizeInMB">
<div class="amount none" [hidden]="invite.giftSizeInMB">
<em>None given</em>
</div>
<div class="amount" [hidden]="!invite.giftSizeInMB">
<div class="amount has-amount" [hidden]="!invite.giftSizeInMB">
{{ invite.giftSizeInMB / 1024 }} GB
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ describe('InvitationsDialog', () => {
});
});

it('should exist', async () => {
it('exists', async () => {
const { element } = await shallow.render();
expect(element).not.toBeNull();
});

it('should display the pending invitations table if there are any invitations pending', async () => {
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]' })];
Expand All @@ -49,7 +49,7 @@ describe('InvitationsDialog', () => {
expect(table.length).toBe(instance.pendingInvites.length);
});

it('should display the "no pending invites" message if there are no invites', async () => {
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 = [];
Expand All @@ -61,7 +61,7 @@ describe('InvitationsDialog', () => {
expect(message).not.toBeNull();
});

it('should display the accepted invitations table if there are any accepted pending', async () => {
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]' })];
Expand All @@ -73,7 +73,7 @@ describe('InvitationsDialog', () => {
expect(table.length).toBe(instance.acceptedInvites.length);
});

it('should display the "no accepted invites" message if there are no invites', async () => {
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 = [];
Expand All @@ -84,4 +84,64 @@ describe('InvitationsDialog', () => {

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);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { Component, OnInit, Inject, ViewChild, ElementRef } from '@angular/core';
import { IsTabbedDialog, DIALOG_DATA, DialogRef } from '@root/app/dialog/dialog.module';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import {
Component,
OnInit,
Inject,
ViewChild,
ElementRef,
} from '@angular/core';
import {
IsTabbedDialog,
DIALOG_DATA,
DialogRef,
} from '@root/app/dialog/dialog.module';
import {
UntypedFormBuilder,
UntypedFormGroup,
Validators,
} from '@angular/forms';
import { ApiService } from '@shared/services/api/api.service';
import { InviteVOData, InviteVO } from '@models';
import { InviteResponse } from '@shared/services/api/index.repo';
Expand All @@ -12,7 +26,7 @@ type InvitationsTab = 'new' | 'pending' | 'accepted';
@Component({
selector: 'pr-invitations-dialog',
templateUrl: './invitations-dialog.component.html',
styleUrls: ['./invitations-dialog.component.scss']
styleUrls: ['./invitations-dialog.component.scss'],
})
export class InvitationsDialogComponent implements OnInit, IsTabbedDialog {
newInviteForm: UntypedFormGroup;
Expand All @@ -33,7 +47,7 @@ export class InvitationsDialogComponent implements OnInit, IsTabbedDialog {
) {
this.newInviteForm = this.fb.group({
fullName: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email]]
email: ['', [Validators.required, Validators.email]],
});
}

Expand All @@ -45,8 +59,12 @@ export class InvitationsDialogComponent implements OnInit, IsTabbedDialog {
try {
const response = await this.api.invite.getInvites();
const allInvites = response.getInviteVOs();
this.acceptedInvites = filter(allInvites, { status: 'status.invite.accepted' });
this.pendingInvites = filter(allInvites, { status: 'status.invite.pending' });
this.acceptedInvites = filter(allInvites, {
status: 'status.invite.accepted',
});
this.pendingInvites = filter(allInvites, {
status: 'status.invite.pending',
});
} catch (err) {
if (err instanceof InviteResponse) {
this.messageService.showError(err.getMessage(), true);
Expand Down Expand Up @@ -96,5 +114,4 @@ export class InvitationsDialogComponent implements OnInit, IsTabbedDialog {
this.waiting = false;
}
}

}
8 changes: 7 additions & 1 deletion src/app/models/invite-vo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* @format */
import { BaseVO } from '@models/base-vo';
import { ArchiveVO, AccountVO, RecordVO, FolderVO, ShareVO } from '.';

type InviteStatusType = 'status.invite.pending' | 'status.invite.accepted' | 'status.invite.revoked';
type InviteStatusType =
| 'status.invite.pending'
| 'status.invite.accepted'
| 'status.invite.revoked';

export class InviteVO extends BaseVO {
public email: string;
Expand All @@ -11,6 +15,7 @@ export class InviteVO extends BaseVO {
public accessRole: string;
public type: string;
public status: InviteStatusType;
public giftSizeInMB: number;

public ArchiveVO;
public AccountVO;
Expand Down Expand Up @@ -50,6 +55,7 @@ export interface InviteVOData {
relationship?: string;
type?: string;
status?: InviteStatusType;
giftSizeInMB?: number;

byArchiveId?: number;
accessRole?: string;
Expand Down

0 comments on commit f33f0fc

Please sign in to comment.