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
17 changes: 17 additions & 0 deletions modules/ui/src/app/pages/certificates/certificates.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ describe('CertificatesStore', () => {
'uploadCertificate',
'deleteCertificate',
]);
// @ts-expect-error data layer should be defined
window.dataLayer = window.dataLayer || [];

TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
Expand Down Expand Up @@ -152,6 +154,21 @@ describe('CertificatesStore', () => {
container
);
});

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

expect(
// @ts-expect-error data layer should be defined
window.dataLayer.some(
(item: { event: string }) =>
item.event === 'successful_saving_certificate'
)
).toBeTruthy();
});
});

describe('with invalid certificate file', () => {
Expand Down
4 changes: 4 additions & 0 deletions modules/ui/src/app/pages/certificates/certificates.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export class CertificatesStore extends ComponentStore<AppComponentState> {
!certificates.some(cert => cert.name === certificate.name)
)[0];
this.updateCertificates(newCertificates);
// @ts-expect-error data layer is not null
window.dataLayer.push({
event: 'successful_saving_certificate',
});
this.notify(
`Certificate successfully added.\n${uploadedCertificate.name} by ${uploadedCertificate.organisation} valid until ${this.datePipe.transform(uploadedCertificate.expires, 'dd MMM yyyy')}`
);
Expand Down