Skip to content

Commit

Permalink
Merge branch 'master' into 767-delete-button-in-debug-tab-should-be-d…
Browse files Browse the repository at this point in the history
…isabled-or-invisible-for-logstorage
  • Loading branch information
kodiakhq[bot] authored Nov 5, 2024
2 parents d69f241 + 8001af0 commit a4dc655
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/app/report/edit-display/edit-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export class EditDisplayComponent implements OnChanges {
} else if (ReportUtil.isCheckPoint(node)) {
reportId = ReportUtil.getStorageIdFromUid(node.uid);
}
if (reportId) {
if (reportId == undefined) {
this.toastService.showDanger('Could not find report to rerun');
} else {
this.httpService
.runReport(this.currentView.storageName, reportId)
.pipe(catchError(this.errorHandler.handleError()))
Expand All @@ -155,8 +157,6 @@ export class EditDisplayComponent implements OnChanges {
this.debugTab.refreshTable({ displayToast: false });
},
});
} else {
this.toastService.showDanger('Could not find report to rerun');
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/app/shared/components/toast/toast.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ngb-toast class="fade animate-show animate-hide position-relative" [ngClass]="'bg-' + toast.type"
[autohide]="toast.type !== 'danger'"
[delay]="toast.type === 'info' || toast.type ==='success' ? 3000 : toast.type ==='warning' ? 8000 : 0"
(click)="toast.detailed ? showDetailedErrorMessages(toast) : null"
(hidden)="close(toast)">
<i class="fa fa-close close-icon" (click)="close(toast)"></i>
<div class="d-flex flex-row align-items-center">
Expand All @@ -23,31 +24,31 @@
}
}
<div class="ml-2 mr-4">{{ toast.message }}</div>
@if (toast.detailed) {
<span>
<br>
<i>Click to see a more detailed description</i>
</span>
}
@if (toast.toastCallback) {
<button class="btn btn-info" (click)="toast.toastCallback.callback()">{{ toast.toastCallback.buttonText }}</button>
}
</div>
@if (toast.detailed) {
<span>
<br>
<i>Click to see a more detailed description</i>
</span>
}
</ngb-toast>
</div>
}
</div>

<ng-template #modal let-modal>
<div class="modal-header">
<h5 class="modal-title" id="settingsModal">{{ selectedAlert.message }}</h5>
<h5 class="modal-title" id="settingsModal">{{ selected.message }}</h5>
</div>
<div class="modal-body text-wrap" id="detailedErrorMessage">
{{ selectedAlert.detailed }}
{{ selected.detailed }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" id="CopyToClipboard" title="Copy to Clipboard"
[cdkCopyToClipboard]="selectedAlert.detailed ?? ''"
[cdkCopyToClipboard]="selected.detailed ?? ''"
(click)="copyToClipboard()">{{ this.justCopied ? 'Copied!' : 'Copy to clipboard' }}
</button>
<button type="button" class="btn btn-info" (click)="modal.dismiss();">Dismiss</button>
Expand Down
34 changes: 31 additions & 3 deletions src/app/shared/components/toast/toast.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ToastComponent } from './toast.component';
import { ToastService } from '../../services/toast.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
import { Toast } from '../../interfaces/toast';
import { By } from '@angular/platform-browser';

describe('ToastComponent', () => {
let component: ToastComponent;
let fixture: ComponentFixture<ToastComponent>;
let mockToastService: jasmine.SpyObj<ToastService>;
let mockNgbModal: jasmine.SpyObj<NgbModal>;

beforeEach(async () => {
mockToastService = jasmine.createSpyObj('ToastService', ['toastObservable']);
mockToastService.toastObservable = of({
title: 'Test Toast',
message: 'Detailed error message',
detailed: 'Detailed error message',
type: 'danger',
} as Toast);

mockNgbModal = jasmine.createSpyObj('NgbModal', ['open']);

await TestBed.configureTestingModule({
imports: [ToastComponent],
providers: [
{ provide: ToastService, useValue: mockToastService },
{ provide: NgbModal, useValue: mockNgbModal },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
});

Expand All @@ -18,7 +40,13 @@ describe('ToastComponent', () => {
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
it('should open modal when a toast with detailed message is clicked', () => {
const toastDebugElement: DebugElement = fixture.debugElement.query(By.css('ngb-toast'));

// Simulate click on the toast item
toastDebugElement.triggerEventHandler('click', null);

// Assert that the modal opens and the selectedAlert is set correctly
expect(mockNgbModal.open).toHaveBeenCalledWith(component.modal, { size: 'lg' });
});
});
7 changes: 4 additions & 3 deletions src/app/shared/components/toast/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { NgClass } from '@angular/common';
imports: [NgbToast, ClipboardModule, NgClass],
})
export class ToastComponent implements OnInit, OnDestroy {
toastSubscription!: Subscription;
selectedAlert!: Toast;
@ViewChild('modal') modal!: TemplateRef<Element>;
toastSubscription!: Subscription;
selected!: Toast;

toasts: Toast[] = [];
justCopied: boolean = false;

Expand All @@ -42,7 +43,7 @@ export class ToastComponent implements OnInit, OnDestroy {
}

showDetailedErrorMessages(alert: Toast): void {
this.selectedAlert = alert;
this.selected = alert;
this.modalService.open(this.modal, { size: 'lg' });
}

Expand Down

0 comments on commit a4dc655

Please sign in to comment.