mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Added test for checklist - fixed test for people
This commit is contained in:
parent
207d2206eb
commit
8ea6df0157
@ -1,33 +1,33 @@
|
||||
<span class="activiti-label mdl-badge"
|
||||
<span class="activiti-label mdl-badge" id="checklist-label"
|
||||
[attr.data-badge]="checklist?.length">{{ 'TASK_DETAILS.LABELS.CHECKLIST' | translate }}</span>
|
||||
<div id="addChecklist" (click)="showDialog()" class="icon material-icons">add</div>
|
||||
<div class="mdl-tooltip" for="addChecklist">
|
||||
<div id="addChecklist" (click)="showDialog()" id="add-checklist" class="icon material-icons">add</div>
|
||||
<div class="mdl-tooltip" for="add-checklist">
|
||||
Add a checklist
|
||||
</div>
|
||||
<div class="menu-container" *ngIf="checklist?.length > 0">
|
||||
<ul class='mdl-list'>
|
||||
<li class="mdl-list__item" *ngFor="let check of checklist">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="mdl-list__item-primary-content" id="check-{{check.id}}">
|
||||
<i class="material-icons mdl-list__item-icon">done</i>
|
||||
{{check.name}}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div *ngIf="checklist?.length === 0">
|
||||
<div *ngIf="checklist?.length === 0" id="checklist-none-message">
|
||||
{{ 'TASK_DETAILS.CHECKLIST.NONE' | translate }}
|
||||
</div>
|
||||
|
||||
<dialog class="mdl-dialog" #dialog>
|
||||
<h4 class="mdl-dialog__title">New Task</h4>
|
||||
<dialog class="mdl-dialog" id="checklist-dialog" #dialog>
|
||||
<h4 class="mdl-dialog__title" id="add-checklist-title">New Check</h4>
|
||||
<div class="mdl-dialog__content">
|
||||
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||
<input class="mdl-textfield__input" type="text" [(ngModel)]="taskName" id="task" />
|
||||
<label class="mdl-textfield__label" for="task">Name</label>
|
||||
<input class="mdl-textfield__input" type="text" [(ngModel)]="taskName" id="checklist-name"/>
|
||||
<label class="mdl-textfield__label" for="checklist-name">Name</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mdl-dialog__actions">
|
||||
<button type="button" (click)="add()" class="mdl-button">Add Checklist</button>
|
||||
<button type="button" (click)="cancel()" class="mdl-button close">Cancel</button>
|
||||
<button type="button" id="add-check" (click)="add()" class="mdl-button">Add Checklist</button>
|
||||
<button type="button" id="close-check-dialog" (click)="cancel()" class="mdl-button close">Cancel</button>
|
||||
</div>
|
||||
</dialog>
|
||||
</dialog>
|
||||
|
@ -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<ActivitiChecklist>;
|
||||
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 = <HTMLElement> element.querySelector('#add-checklist');
|
||||
closeCheckDialogButton = <HTMLElement> 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 = <HTMLElement> 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 = <HTMLElement> 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');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
@ -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) {
|
||||
|
@ -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');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user