diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html index 9bfdf6e968..7cc63454db 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html @@ -1,33 +1,33 @@ -{{ 'TASK_DETAILS.LABELS.CHECKLIST' | translate }} -
add
-
+
add
+
Add a checklist
-
+
{{ 'TASK_DETAILS.CHECKLIST.NONE' | translate }}
- -

New Task

+ +

New Check

- - + +
- - + +
-
\ No newline at end of file +
diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.spec.ts new file mode 100644 index 0000000000..35ff285f11 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.spec.ts @@ -0,0 +1,172 @@ +/*! + * @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 { + CoreModule, + AlfrescoTranslationService +} from 'ng2-alfresco-core'; +import { SimpleChange } from '@angular/core'; +import { ActivitiTaskListService } from '../services/activiti-tasklist.service'; +import { ActivitiChecklist } from './activiti-checklist.component'; +import { TranslationMock } from '../assets/translation.service.mock'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { TaskDetailsModel } from '../models/task-details.model'; + +declare let jasmine: any; + +const fakeTaskDetail = new TaskDetailsModel({ + id: 'fake-check-id', + name: 'fake-check-name' +}); + +describe('Activiti Checklist Component', () => { + + let checklistComponent: ActivitiChecklist; + let fixture: ComponentFixture; + let element: HTMLElement; + let showChecklistDialog, closeCheckDialogButton; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [CoreModule], + declarations: [ActivitiChecklist], + providers: [ + {provide: AlfrescoTranslationService, useClass: TranslationMock}, + ActivitiTaskListService] + }).compileComponents().then(() => { + fixture = TestBed.createComponent(ActivitiChecklist); + checklistComponent = fixture.componentInstance; + element = fixture.nativeElement; + fixture.detectChanges(); + }); + })); + + it('should show people component title', () => { + expect(element.querySelector('#checklist-label')).toBeDefined(); + expect(element.querySelector('#checklist-label')).not.toBeNull(); + }); + + it('should show no checklist message', () => { + expect(element.querySelector('#checklist-none-message')).not.toBeNull(); + expect(element.querySelector('#checklist-none-message').textContent).toContain('TASK_DETAILS.CHECKLIST.NONE'); + }); + + describe('when interact with people dialog', () => { + + beforeEach(() => { + checklistComponent.taskId = 'fake-task-id'; + checklistComponent.checklist = []; + fixture.detectChanges(); + showChecklistDialog = element.querySelector('#add-checklist'); + closeCheckDialogButton = element.querySelector('#close-check-dialog'); + }); + + it('should show dialog when clicked on add', () => { + expect(showChecklistDialog).not.toBeNull(); + showChecklistDialog.click(); + + expect(element.querySelector('#checklist-dialog')).not.toBeNull(); + expect(element.querySelector('#add-checklist-title')).not.toBeNull(); + expect(element.querySelector('#add-checklist-title').textContent).toContain('New Check'); + }); + + it('should close dialog when clicked on cancel', () => { + showChecklistDialog.click(); + expect(element.querySelector('#checklist-dialog').getAttribute('open')).not.toBeNull(); + closeCheckDialogButton.click(); + expect(element.querySelector('#checklist-dialog').getAttribute('open')).toBeNull(); + }); + }); + + describe('when there are task checklist', () => { + + beforeEach(() => { + checklistComponent.taskId = 'fake-task-id'; + checklistComponent.checklist = []; + fixture.detectChanges(); + showChecklistDialog = element.querySelector('#add-checklist'); + }); + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('should show task checklist', () => { + checklistComponent.checklist.push(fakeTaskDetail); + fixture.detectChanges(); + expect(element.querySelector('#check-fake-check-id')).not.toBeNull(); + expect(element.querySelector('#check-fake-check-id').textContent).toContain('fake-check-name'); + }); + + it('should add checklist', async(() => { + showChecklistDialog.click(); + let addButtonDialog = element.querySelector('#add-check'); + addButtonDialog.click(); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: {id: 'fake-check-added-id', name: 'fake-check-added-name'} + }); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#check-fake-check-added-id')).not.toBeNull(); + expect(element.querySelector('#check-fake-check-added-id').textContent).toContain('fake-check-added-name'); + }); + })); + + it('should show load task checklist on change', async(() => { + checklistComponent.taskId = 'new-fake-task-id'; + checklistComponent.checklist.push(fakeTaskDetail); + fixture.detectChanges(); + let change = new SimpleChange(null, 'new-fake-task-id'); + checklistComponent.ngOnChanges({ + taskId: change + }); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: {data: [{id: 'fake-check-changed-id', name: 'fake-check-changed-name'}]} + }); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#check-fake-check-changed-id')).not.toBeNull(); + expect(element.querySelector('#check-fake-check-changed-id').textContent).toContain('fake-check-changed-name'); + }); + })); + + it('should show empty checklist when task id is null', async(() => { + checklistComponent.taskId = 'new-fake-task-id'; + checklistComponent.checklist.push(fakeTaskDetail); + fixture.detectChanges(); + checklistComponent.taskId = null; + let change = new SimpleChange(null, 'new-fake-task-id'); + checklistComponent.ngOnChanges({ + taskId: change + }); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#checklist-none-message')).not.toBeNull(); + expect(element.querySelector('#checklist-none-message').textContent).toContain('TASK_DETAILS.CHECKLIST.NONE'); + }); + })); + }); + +}); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts index dab4a8825b..35894db685 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, OnInit, ViewChild, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslationService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { TaskDetailsModel } from '../models/task-details.model'; import { Observer, Observable } from 'rxjs/Rx'; @@ -48,8 +48,7 @@ export class ActivitiChecklist implements OnInit, OnChanges { * @param auth * @param translate */ - constructor(private auth: AlfrescoAuthenticationService, - private translate: AlfrescoTranslationService, + constructor(private translate: AlfrescoTranslationService, private activitiTaskList: ActivitiTaskListService) { if (translate) { diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts index cd177df72c..d462229df4 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts @@ -23,7 +23,7 @@ import { ActivitiPeopleService } from '../services/activiti-people.service'; import { ActivitiPeople } from './activiti-people.component'; import { ActivitiPeopleSearch } from './activiti-people-search.component'; import { TranslationMock } from '../assets/translation.service.mock'; -import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { User } from '../models/user.model'; declare let jasmine: any; @@ -130,28 +130,26 @@ describe('Activiti People Component', () => { expect(element.querySelector('#user-fake-id').textContent).toContain('fake-last'); }); - it('should remove pepole involved', fakeAsync(() => { + it('should remove pepole involved', async(() => { activitiPeopleComponent.removeInvolvedUser(fakeUser); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - tick(); - fixture.detectChanges(); fixture.whenStable() .then(() => { + fixture.detectChanges(); expect(element.querySelector('#user-fake-id')).toBeNull(); }); })); - it('should involve pepole', fakeAsync(() => { + it('should involve pepole', async(() => { activitiPeopleComponent.involveUser(fakeUserToInvolve); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - tick(); - fixture.detectChanges(); fixture.whenStable() .then(() => { + fixture.detectChanges(); expect(element.querySelector('#user-fake-involve-id')).not.toBeNull(); expect(element.querySelector('#user-fake-involve-id').textContent) .toBe('fake-involve-name fake-involve-last'); @@ -211,43 +209,41 @@ describe('Activiti People Component', () => { jasmine.Ajax.uninstall(); }); - it('should log error message when search fails', fakeAsync(() => { + it('should log error message when search fails', async(() => { console.log = jasmine.createSpy('log'); + activitiPeopleComponent.people$.subscribe(() => { + expect(console.log).toHaveBeenCalledWith('Could not load users'); + }); activitiPeopleComponent.searchUser('fake-search'); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - tick(); - - expect(console.log).toHaveBeenCalledWith('Could not load users'); })); - it('should not remove user if remove involved user fail', fakeAsync(() => { + it('should not remove user if remove involved user fail', async(() => { activitiPeopleComponent.people.push(fakeUser); fixture.detectChanges(); activitiPeopleComponent.removeInvolvedUser(fakeUser); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - tick(); - fixture.detectChanges(); fixture.whenStable() .then(() => { + fixture.detectChanges(); expect(element.querySelector('#user-fake-id')).not.toBeNull(); expect(element.querySelector('#user-fake-id').textContent) .toBe('fake-name fake-last'); }); })); - it('should not involve user if involve user fail', fakeAsync(() => { + it('should not involve user if involve user fail', async(() => { activitiPeopleComponent.involveUser(fakeUserToInvolve); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - tick(); - fixture.detectChanges(); fixture.whenStable() .then(() => { + fixture.detectChanges(); expect(element.querySelector('#user-fake-id')).toBeNull(); expect(element.querySelector('#no-people-label').textContent).toContain('TASK_DETAILS.PEOPLE.NONE'); });