Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modules/ui/src/app/pages/certificates/certificates.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,34 @@ describe('CertificatesStore', () => {
});

it('should notify', () => {
const container = document.createElement('DIV');
container.classList.add('certificates-drawer-content');
document.querySelector('body')?.appendChild(container);
certificateStore.uploadCertificate(FILE);

expect(notificationServiceMock.notify).toHaveBeenCalledWith(
'Certificate successfully added.\niot.bms.google.com by Google, Inc. valid until 01 Sep 2024',
0,
'certificate-notification',
10000
10000,
container
);
});
});

describe('with invalid certificate file', () => {
it('should notify about errors', () => {
const container = document.createElement('DIV');
container.classList.add('certificates-drawer-content');
document.querySelector('body')?.appendChild(container);
certificateStore.uploadCertificate(INVALID_FILE);

expect(notificationServiceMock.notify).toHaveBeenCalledWith(
'File "some very long strange n..." is not added.\nThe file name should be alphanumeric, symbols -_. are allowed.\nFile extension must be .cert, .crt, .pem, .cer.\nMax name length is 24 characters.\nFile size should be a max of 4KB',
0,
'certificate-notification',
24000
24000,
container
);
});
});
Expand Down
3 changes: 2 additions & 1 deletion modules/ui/src/app/pages/certificates/certificates.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export class CertificatesStore extends ComponentStore<AppComponentState> {
message,
0,
'certificate-notification',
Math.ceil(message.length / SYMBOLS_PER_SECOND) * 1000
Math.ceil(message.length / SYMBOLS_PER_SECOND) * 1000,
window.document.querySelector('.certificates-drawer-content')
);
}

Expand Down
12 changes: 10 additions & 2 deletions modules/ui/src/app/services/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export class NotificationService {
private zone: NgZone
) {}

notify(message: string, duration = 0, panelClass = '', timeout = TIMEOUT_MS) {
notify(
message: string,
duration = 0,
panelClass = '',
timeout = TIMEOUT_MS,
container?: Document | Element | null
) {
const panelClasses = ['test-run-notification'];
if (panelClass) {
panelClasses.push(panelClass);
Expand All @@ -66,7 +72,9 @@ export class NotificationService {
this.snackBarRef
.afterDismissed()
.pipe(take(1))
.subscribe(() => this.focusManagerService.focusFirstElementInContainer());
.subscribe(() =>
this.focusManagerService.focusFirstElementInContainer(container)
);
}
dismiss() {
this.snackBar.dismiss();
Expand Down