[AAE-9314] Fix preselected user display in completed task (#7688)

* [AAE-9314] Fix preselected user display in completed task

* [AAE-9314] add unit tests

* Trigger travis
This commit is contained in:
Tomasz Gnyp 2022-06-28 12:48:50 +02:00 committed by GitHub
parent e529d3bd74
commit 93c5619e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 8 deletions

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormFieldModel, FormFieldTypes, FormModel, setupTestBed } from '@alfresco/adf-core'; import { FormFieldModel, FormFieldTypes, FormModel, IdentityGroupModel, setupTestBed } from '@alfresco/adf-core';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupCloudWidgetComponent } from './group-cloud.widget'; import { GroupCloudWidgetComponent } from './group-cloud.widget';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
@ -65,7 +65,7 @@ describe('GroupCloudWidgetComponent', () => {
expect(asterisk.textContent).toEqual('*'); expect(asterisk.textContent).toEqual('*');
}); });
it('should be invalid if no default option after interaction', async () => { it('should be invalid if no option is selected after interaction', async () => {
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -81,6 +81,58 @@ describe('GroupCloudWidgetComponent', () => {
}); });
}); });
describe('when is readOnly', () => {
it('should single chip be disabled', async () => {
const mockSpaghetti: IdentityGroupModel[] = [{
id: 'bolognese',
name: 'Bolognese'
}];
widget.field = new FormFieldModel( new FormModel({ taskId: '<id>'}, null, true), {
type: FormFieldTypes.GROUP,
value: mockSpaghetti
});
fixture.detectChanges();
await fixture.whenStable();
const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled');
expect(disabledFormField).toBeTruthy();
fixture.detectChanges();
await fixture.whenStable();
const disabledGroupChip: HTMLElement = element.querySelector('.mat-chip-disabled');
expect(disabledGroupChip).toBeTruthy();
});
it('should multi chips be disabled', async () => {
const mockSpaghetti: IdentityGroupModel[] = [
{ id: 'bolognese', name: 'Bolognese' },
{ id: 'carbonara', name: 'Carbonara' }
];
widget.field = new FormFieldModel( new FormModel({ taskId: '<id>'}, null, true), {
type: FormFieldTypes.GROUP,
value: mockSpaghetti
});
fixture.detectChanges();
await fixture.whenStable();
const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled');
expect(disabledFormField).toBeTruthy();
fixture.detectChanges();
await fixture.whenStable();
const disabledGroupChips = element.querySelectorAll('.mat-chip-disabled');
expect(disabledGroupChips.item(0)).toBeTruthy();
expect(disabledGroupChips.item(1)).toBeTruthy();
});
});
describe('when form model has left labels', () => { describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => { it('should have left labels classes on leftLabels true', async () => {

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserService, setupTestBed } from '@alfresco/adf-core'; import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserModel, IdentityUserService, setupTestBed } from '@alfresco/adf-core';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PeopleCloudWidgetComponent } from './people-cloud.widget'; import { PeopleCloudWidgetComponent } from './people-cloud.widget';
@ -84,7 +84,7 @@ describe('PeopleCloudWidgetComponent', () => {
expect(asterisk.textContent).toEqual('*'); expect(asterisk.textContent).toEqual('*');
}); });
it('should be invalid if no default option after interaction', async () => { it('should be invalid if no option is selected after interaction', async () => {
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -100,6 +100,59 @@ describe('PeopleCloudWidgetComponent', () => {
}); });
}); });
describe('when is readOnly', () => {
it('should single chip be disabled', async () => {
const mockSpaghetti: IdentityUserModel[] = [{
id: 'bolognese',
username: 'Bolognese',
email: 'bolognese@example.com'
}];
widget.field = new FormFieldModel( new FormModel({ taskId: '<id>'}, null, true), {
type: FormFieldTypes.GROUP,
value: mockSpaghetti
});
fixture.detectChanges();
await fixture.whenStable();
const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled');
expect(disabledFormField).toBeTruthy();
fixture.detectChanges();
await fixture.whenStable();
const disabledGroupChip: HTMLElement = element.querySelector('.mat-chip-disabled');
expect(disabledGroupChip).toBeTruthy();
});
it('should multi chips be disabled', async () => {
const mockSpaghetti: IdentityUserModel[] = [
{ id: 'bolognese', username: 'Bolognese', email: 'bolognese@example.com' },
{ id: 'carbonara', username: 'Carbonara', email: 'carbonara@example.com' }
];
widget.field = new FormFieldModel( new FormModel({ taskId: '<id>'}, null, true), {
type: FormFieldTypes.GROUP,
value: mockSpaghetti
});
fixture.detectChanges();
await fixture.whenStable();
const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled');
expect(disabledFormField).toBeTruthy();
fixture.detectChanges();
await fixture.whenStable();
const disabledGroupChips = element.querySelectorAll('.mat-chip-disabled');
expect(disabledGroupChips.item(0)).toBeTruthy();
expect(disabledGroupChips.item(1)).toBeTruthy();
});
});
describe('when form model has left labels', () => { describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => { it('should have left labels classes on leftLabels true', async () => {

View File

@ -27,7 +27,6 @@ import {
SimpleChanges, SimpleChanges,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
ChangeDetectionStrategy,
SimpleChange SimpleChange
} from '@angular/core'; } from '@angular/core';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
@ -50,7 +49,6 @@ import { ComponentSelectionMode } from '../../types';
]) ])
]) ])
], ],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {

View File

@ -26,7 +26,6 @@ import {
SimpleChanges, SimpleChanges,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
ChangeDetectionStrategy,
ViewChild, ElementRef, SimpleChange ViewChild, ElementRef, SimpleChange
} from '@angular/core'; } from '@angular/core';
import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; import { Observable, of, BehaviorSubject, Subject } from 'rxjs';
@ -54,7 +53,6 @@ import { ComponentSelectionMode } from '../../types';
]) ])
], ],
providers: [FullNamePipe], providers: [FullNamePipe],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })