From a6c83f9c641b24daa53ee423e60ccfdc3ba35fff Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Sun, 2 Apr 2017 13:44:12 +0100 Subject: [PATCH] Notification service test (#1801) --- .../ng2-alfresco-core/karma.conf.js | 2 +- .../src/services/notification.service.spec.ts | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts diff --git a/ng2-components/ng2-alfresco-core/karma.conf.js b/ng2-components/ng2-alfresco-core/karma.conf.js index 54c6fa5d19..dd1f324fb8 100644 --- a/ng2-components/ng2-alfresco-core/karma.conf.js +++ b/ng2-components/ng2-alfresco-core/karma.conf.js @@ -99,7 +99,7 @@ module.exports = function (config) { // Source files that you wanna generate coverage for. // Do not include tests or libraries (these files will be instrumented by Istanbul) preprocessors: { - 'src/**/!(*spec|index|*mock|*model|*event|mdl*).js': 'coverage' + 'src/**/!(*spec|index|*mock|*model|*event|*interface|mdl*).js': 'coverage' }, coverageReporter: { diff --git a/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts new file mode 100644 index 0000000000..cad3b093a9 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts @@ -0,0 +1,94 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component } from '@angular/core'; +import { NotificationService } from './notification.service'; +import { MdSnackBarModule } from '@angular/material'; + +describe('NotificationService', () => { + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [MdSnackBarModule.forRoot()], + declarations: [ComponentThatProvidesNotificationService], + providers: [ + NotificationService + ] + }); + + TestBed.compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ComponentThatProvidesNotificationService); + fixture.detectChanges(); + }); + + describe('openSnackMessage', () => { + + it('should open a message notification bar', (done) => { + let promise = fixture.componentInstance.sendMessage(); + + fixture.detectChanges(); + + expect(document.querySelector('snack-bar-container')).not.toBeNull(); + + promise.afterDismissed().subscribe(() => { + done(); + }); + }); + }); + + describe('openSnackMessageAction', () => { + + it('should open a message notification bar with action', (done) => { + let promise = fixture.componentInstance.sendMessageAction(); + + fixture.detectChanges(); + + expect(document.querySelector('snack-bar-container')).not.toBeNull(); + expect(document.querySelector('.md-simple-snackbar-action')).not.toBeNull(); + + promise.afterDismissed().subscribe(() => { + done(); + }); + }); + }); + +}); + +@Component({ + template: '', + providers: [NotificationService] +}) +class ComponentThatProvidesNotificationService { + constructor(public notificationService: NotificationService) { + + } + + sendMessage() { + let promise = this.notificationService.openSnackMessage('Test notification', 2000); + return promise; + } + + sendMessageAction() { + let promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 2000); + return promise; + } + +}