Skip to content

Commit

Permalink
test: added and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber committed Aug 11, 2023
1 parent bea4c35 commit 35a1180
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/app/core/utils/cookies/cookies.service.ts
Expand Up @@ -57,8 +57,7 @@ export class CookiesService {
this.deleteAllCookies();
this.put('cookieConsent', JSON.stringify({ enabledOptions: options, version: cookieConsentVersion }), {
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)),
// sameSite: 'None',
secure: true,
sameSite: 'None',
});
window.location.reload();
}
Expand Down
Expand Up @@ -2,9 +2,16 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { TranslateModule } from '@ngx-translate/core';
import { MockComponent } from 'ng-mocks';
import { instance, mock } from 'ts-mockito';
import { of } from 'rxjs';
import { anything, instance, mock, when } from 'ts-mockito';

import { CMSFacade } from 'ish-core/facades/cms.facade';
import { ContentPagelet } from 'ish-core/models/content-pagelet/content-pagelet.model';
import {
ContentPageletEntryPointView,
ContentPageletView,
createContentPageletView,
} from 'ish-core/models/content-view/content-view.model';
import { PreviewService } from 'ish-core/utils/preview/preview.service';

import { ContentDesignViewWrapperComponent } from './content-design-view-wrapper.component';
Expand All @@ -19,6 +26,10 @@ describe('Content Design View Wrapper Component', () => {
beforeEach(async () => {
cmsFacade = mock(CMSFacade);
previewService = mock(PreviewService);
when(cmsFacade.pagelet$(anything())).thenReturn(
of({ id: 'xyz', displayName: 'Pagelet Name xyz' } as ContentPageletView)
);
when(previewService.previewContextId).thenReturn('DESIGNVIEW');

await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
Expand All @@ -41,4 +52,74 @@ describe('Content Design View Wrapper Component', () => {
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should not be rendered if no input parameter is given', () => {
fixture.detectChanges();

expect(element).toMatchInlineSnapshot(`N/A`);
});

it('should be rendered if a pageletId is given', () => {
component.pageletId = 'xyz';
fixture.detectChanges();

expect(component.type).toEqual('pagelet');
expect(element).toMatchInlineSnapshot(`
<div class="designview-wrapper pagelet" ng-reflect-ng-class="pagelet">
<div class="designview-wrapper-actions">
<div class="name">Pagelet Name xyz</div>
<button class="btn" title="designview.edit.link.title">
<fa-icon ng-reflect-icon="fas,pencil-alt"></fa-icon>
</button>
</div>
</div>
`);
});

it('should be rendered if a slotId is given', () => {
component.slotId = 'xyz_slot_id';
component.pagelet = createContentPageletView({
id: 'xyz_pagelet_id',
displayName: 'Pagelet Name xyz_slot',
slots: [
{
definitionQualifiedName: component.slotId,
displayName: 'Slot Name xyz',
},
],
} as ContentPagelet);
fixture.detectChanges();

expect(component.type).toEqual('slot');
expect(element).toMatchInlineSnapshot(`
<div class="designview-wrapper slot" ng-reflect-ng-class="slot">
<div class="designview-wrapper-actions">
<div class="name">Slot Name xyz</div>
<button class="btn" title="designview.add.link.title">
<fa-icon ng-reflect-icon="fas,plus"></fa-icon>
</button>
</div>
</div>
`);
});

it('should be rendered if an include is given', () => {
component.include = {
id: 'xyz_include_id',
displayName: 'Include Name xyz',
} as ContentPageletEntryPointView;
fixture.detectChanges();

expect(component.type).toEqual('include');
expect(element).toMatchInlineSnapshot(`
<div class="designview-wrapper include" ng-reflect-ng-class="include">
<div class="designview-wrapper-actions">
<div class="name">Include Name xyz</div>
<button class="btn" title="designview.add.link.title">
<fa-icon ng-reflect-icon="fas,plus"></fa-icon>
</button>
</div>
</div>
`);
});
});
@@ -1,4 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { anything, instance, mock, when } from 'ts-mockito';

Expand All @@ -7,6 +8,7 @@ import {
ContentPageletEntryPointView,
createContentPageletEntryPointView,
} from 'ish-core/models/content-view/content-view.model';
import { ContentDesignViewWrapperComponent } from 'ish-shared/cms/components/content-design-view-wrapper/content-design-view-wrapper.component';

import { ContentIncludeComponent } from './content-include.component';

Expand All @@ -33,7 +35,7 @@ describe('Content Include Component', () => {
when(cmsFacade.contentInclude$(anything())).thenReturn(of(include));

await TestBed.configureTestingModule({
declarations: [ContentIncludeComponent],
declarations: [ContentIncludeComponent, MockComponent(ContentDesignViewWrapperComponent)],
providers: [{ provide: CMSFacade, useValue: instance(cmsFacade) }],
}).compileComponents();
});
Expand Down
Expand Up @@ -69,7 +69,7 @@ describe('Content Pagelet Component', () => {
expect(() => component.ngOnChanges()).not.toThrow();
expect(() => fixture.detectChanges()).not.toThrow();

expect(element).toMatchInlineSnapshot(`N/A`);
expect(element).toMatchInlineSnapshot(`<ish-content-design-view-wrapper></ish-content-design-view-wrapper>`);
expect(consoleSpy).toHaveBeenCalledWith('did not find mapping for id (fq)');
});

Expand All @@ -80,6 +80,10 @@ describe('Content Pagelet Component', () => {
expect(() => component.ngOnChanges()).not.toThrow();
expect(() => fixture.detectChanges()).not.toThrow();

expect(element).toMatchInlineSnapshot(`<ish-cms-text><span>foo</span></ish-cms-text>`);
expect(element).toMatchInlineSnapshot(`
<ish-content-design-view-wrapper
><ish-cms-text><span>foo</span></ish-cms-text></ish-content-design-view-wrapper
>
`);
});
});
@@ -1,7 +1,9 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockComponent } from 'ng-mocks';

import { ContentPagelet } from 'ish-core/models/content-pagelet/content-pagelet.model';
import { createContentPageletView } from 'ish-core/models/content-view/content-view.model';
import { ContentDesignViewWrapperComponent } from 'ish-shared/cms/components/content-design-view-wrapper/content-design-view-wrapper.component';

import { ContentSlotComponent } from './content-slot.component';

Expand All @@ -12,7 +14,7 @@ describe('Content Slot Component', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ContentSlotComponent],
declarations: [ContentSlotComponent, MockComponent(ContentDesignViewWrapperComponent)],
}).compileComponents();
});

Expand Down

0 comments on commit 35a1180

Please sign in to comment.