Skip to content

Commit

Permalink
✅ update E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steffinchen committed Aug 21, 2023
1 parent 08b2cfc commit 69ad1bf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/invitations-accept.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Test invitation accept for existing user', () => {
cy.wait('@createInvitationRedeemRequest');
cy.get('#title').should('contain.text', 'Invitation');
cy.get('.flex-row > .text-3xl', { timeout: 7000 }).should('contain.text', '[email protected]');
cy.get('p-toast').should('contain.text', 'Redeem successful');
cy.get('p-toast').should('contain.text', 'Invitation accepted');
});

it('should accept but display message if some targets failed', () => {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('Test invitation accept for existing user', () => {
cy.wait('@getInvitation');
cy.get('#title').should('contain.text', 'Invitation');
cy.get('.flex-row > .text-3xl').should('contain.text', '[email protected]');
cy.get('p-toast').should('contain.text', 'Redeem successful');
cy.get('p-toast').should('contain.text', 'Invitation accepted');

cy.get('app-navbar-item').contains('Organizations').click();
cy.get(':nth-child(2) > .flex-row > .text-3xl').should('contain.text', 'vshn');
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('Test invitation accept for existing user', () => {

cy.get('app-navbar-item').contains('Organizations').click();
cy.get(':nth-child(2) > .flex-row > .text-3xl').should('contain.text', 'nxt');
cy.get('p-toast', { timeout: 10000 }).should('contain.text', 'Redeem successful');
cy.get('p-toast', { timeout: 10000 }).should('contain.text', 'Invitation accepted');
});
});

Expand Down Expand Up @@ -332,7 +332,7 @@ describe('Test invitation accept for new user', () => {
cy.wait('@getInvitation');
cy.get('#title').should('contain.text', 'Invitation');
cy.get('.flex-row > .text-3xl', { timeout: 7000 }).should('contain.text', '[email protected]');
cy.get('p-toast').should('contain.text', 'Redeem successful');
cy.get('p-toast').should('contain.text', 'Invitation accepted');
});

it('should accept but display message if some targets failed', () => {
Expand Down
2 changes: 2 additions & 0 deletions cypress/e2e/zones.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('Test zones', () => {
it('no permission', () => {
cy.visit('/zones');
cy.get('h1').should('contain.text', 'Welcome to the APPUiO Cloud Portal');
cy.get('p-toast').should('contain.text', 'Error');
});
});

Expand Down Expand Up @@ -118,5 +119,6 @@ describe('Test single zone', () => {
it('no permission', () => {
cy.visit('/zones/cloudscale-lpg-0');
cy.get('h1').should('contain.text', 'Welcome to the APPUiO Cloud Portal');
cy.get('p-toast').should('contain.text', 'Error');
});
});
12 changes: 11 additions & 1 deletion src/app/core/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class NotificationService {
*/
showErrorMessageWithTitle(title: string, message: string) {
this.messageService.add({
severity: 'warn',
severity: 'error',
summary: title,
detail: message,
closable: true,
Expand All @@ -56,6 +56,16 @@ export class NotificationService {
});
}

showWarningMessage(message: string) {
this.messageService.add({
severity: 'warn',
summary: $localize`Warning`,
detail: message,
closable: true,
sticky: true,
});
}

/**
* Shows an info message and title as toast.
* The message is sticky and closable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<h1 class="pt-0 mt-0 mb-0" i18n id="title">Invitation</h1>
</div>

<div *ngIf="redeemSuccessMessage" class="mb-2">
<p-message [text]="redeemSuccessMessage" severity="success"></p-message>
</div>

<ng-container *ngrxLet="payload$ as payload; suspenseTpl: loading; error as err">
<ng-container *ngIf="payload">
<p-messages *ngIf="payload.isRedeemed" severity="warn">
Expand Down
19 changes: 11 additions & 8 deletions src/app/invitations/invitation-view/invitation-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InvitationCollectionService } from '../../store/invitation-collection.s
import { Invitation, invitationTokenLocalStorageKey } from '../../types/invitation';
import { faInfo, faWarning } from '@fortawesome/free-solid-svg-icons';
import { InvitationRedeemRequestCollectionService } from '../../store/invitation-redeem-request-collection.service';
import { MessageService, SharedModule } from 'primeng/api';
import { SharedModule } from 'primeng/api';
import { DataServiceError } from '@ngrx/data';
import { OrganizationCollectionService } from '../../store/organization-collection.service';
import { BillingEntityCollectionService } from '../../store/billingentity-collection.service';
Expand Down Expand Up @@ -44,8 +44,6 @@ export class InvitationViewComponent implements OnInit {
faWarning = faWarning;
faInfo = faInfo;

redeemSuccessMessage?: string;

constructor(
private activatedRoute: ActivatedRoute,
private invitationService: InvitationCollectionService,
Expand Down Expand Up @@ -158,19 +156,24 @@ export class InvitationViewComponent implements OnInit {
}

addErrorNotification(err: DataServiceError | Error): void {
let message = $localize`Redeem failed`;
if (err instanceof DataServiceError && err.error.status === 403) {
message = $localize`Not allowed, most likely already redeemed`;
this.notificationService.showErrorMessageWithTitle(
$localize`Redeem failed`,
$localize`Not allowed, most likely already redeemed`
);
} else {
this.notificationService.showErrorMessage($localize`Redeem failed`);
}
this.notificationService.showErrorMessage(message);
}

private checkInvitation(invitation: Invitation): void {
if (this.allTargetsReady(invitation)) {
this.redeemSuccessMessage = $localize`Invitation accepted.`;
this.notificationService.showSuccessMessage($localize`Invitation accepted.`);
}
if (this.someTargetsFailed(invitation)) {
this.redeemSuccessMessage = $localize`Invitation accepted, though not all permissions could be granted.`;
this.notificationService.showWarningMessage(
$localize`Invitation accepted, though not all permissions could be granted.`
);
}
this.billingService.resetMemoization();
this.organizationService.resetMemoization();
Expand Down

0 comments on commit 69ad1bf

Please sign in to comment.