Commit 103b2981 authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): spec tests

1 merge request!776Allow users to permanently hide "share" buttons in settings
Pipeline #116918093 running with stages
......@@ -28,6 +28,15 @@ import { AnalyticsService } from '../../../services/analytics';
import { analyticsServiceMock } from '../../../../tests/analytics-service-mock.spec';
import { ActivityService } from '../../../common/services/activity.service';
import { activityServiceMock } from '../../../../tests/activity-service-mock.spec';
import { By } from '@angular/platform-browser';
import { MetaService } from '../../../common/services/meta.service';
import { metaServiceMock } from '../../notifications/notification.service.spec';
import { OverlayModalService } from '../../../services/ux/overlay-modal';
import { overlayModalServiceMock } from '../../../../tests/overlay-modal-service-mock.spec';
import { ClientMetaService } from '../../../common/services/client-meta.service';
import { clientMetaServiceMock } from '../../../../tests/client-meta-service-mock.spec';
import { ConfigsService } from '../../../common/services/configs.service';
import { MockService } from '../../../utils/mock';
describe('Blog view component', () => {
let comp: BlogView;
......@@ -36,7 +45,9 @@ describe('Blog view component', () => {
guid: '1',
title: 'test blog',
description: 'description',
ownerObj: {},
ownerObj: {
hide_share_buttons: false,
},
allow_comments: true,
perma_url: '/perma',
thumbnail: '/thumbnail',
......@@ -54,6 +65,10 @@ describe('Blog view component', () => {
{ provide: ContextService, useValue: contextServiceMock },
{ provide: ScrollService, useValue: scrollServiceMock },
{ provide: Session, useValue: sessionMock },
{ provide: MetaService, useValue: metaServiceMock },
{ provide: OverlayModalService, useValue: overlayModalServiceMock },
{ provide: ClientMetaService, useValue: clientMetaServiceMock },
{ provide: ConfigsService, useValue: MockService(ConfigsService) },
],
schemas: [NO_ERRORS_SCHEMA],
})
......@@ -63,9 +78,31 @@ describe('Blog view component', () => {
// synchronous beforeEach
beforeEach(() => {
jasmine.clock().uninstall();
jasmine.clock().install();
fixture = TestBed.createComponent(BlogView);
comp = fixture.componentInstance;
comp.blog = blog;
fixture.detectChanges();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('should have an instance of m-social-icons if the owner has it enabled', () => {
let socialIcons = fixture.debugElement.query(By.css('m-social-icons'));
expect(socialIcons).not.toBeNull();
const blog = Object.assign({}, comp.blog);
blog.ownerObj.hide_share_buttons = true;
comp.blog = blog;
fixture.detectChanges();
socialIcons = fixture.debugElement.query(By.css('m-social-icons'));
expect(socialIcons).toBeNull();
});
});
......@@ -47,6 +47,6 @@
[url]="siteUrl + 'newsfeed/' + activity?.guid"
[title]="activity?.title || ''"
[embed]="activity"
*ngIf="!activity.ownerObj.hide_share_buttons"
*ngIf="!activity?.ownerObj.hide_share_buttons"
>
</m-social-icons>
......@@ -29,6 +29,7 @@ import { featuresServiceMock } from '../../../../tests/features-service-mock.spe
import { MetaService } from '../../../common/services/meta.service';
import { ConfigsService } from '../../../common/services/configs.service';
import { SocialIcons } from '../../legacy/components/social-icons/social-icons';
import { metaServiceMock } from '../../notifications/notification.service.spec';
@Component({
selector: 'minds-activity',
......@@ -75,7 +76,7 @@ describe('NewsfeedSingleComponent', () => {
},
},
},
{ provide: MetaService, useValue: MockService(MetaService) },
{ provide: MetaService, useValue: metaServiceMock },
{ provide: Router, useValue: routerMock },
{ provide: EntitiesService, useValue: MockService(EntitiesService) },
{ provide: FeaturesService, useValue: featuresServiceMock },
......@@ -192,4 +193,19 @@ describe('NewsfeedSingleComponent', () => {
'If you wish to appeal, please contact us at info@minds.com.'
);
});
it('should have an instance of m-social-icons if the owner has it enabled', () => {
let socialIcons = fixture.debugElement.query(By.css('m-social-icons'));
expect(socialIcons).not.toBeNull();
const activity = Object.assign({}, comp.activity);
activity.ownerObj.hide_share_buttons = true;
comp.activity = activity;
fixture.detectChanges();
socialIcons = fixture.debugElement.query(By.css('m-social-icons'));
expect(socialIcons).toBeNull();
});
});
......@@ -13,7 +13,12 @@ export let siteServiceMock = new (function() {
var isAdmin = () => true;
})();
export let metaServiceMock = new (function() {
this.setCounter = jasmine.createSpy('setCounter').and.callFake(() => {});
this.setCounter = jasmine.createSpy('setCounter').and.returnValue(this);
this.setDescription = jasmine
.createSpy('setDescription')
.and.returnValue(this);
this.setTitle = jasmine.createSpy('setTitle').and.returnValue(this);
this.setOgImage = jasmine.createSpy('setOgImage').and.returnValue(this);
})();
describe('NotificationService', () => {
......
Please register or to comment