mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Fixing unit test after last rebase + lint
This commit is contained in:
@@ -18,31 +18,26 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
import { ProcessServiceCloudTestingModule } from './../../testing/process-service-cloud.testing.module';
|
||||
import { GroupCloudModule } from '../group-cloud.module';
|
||||
import { GroupCloudComponent } from './group-cloud.component';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { DebugElement, SimpleChange } from '@angular/core';
|
||||
import { IdentityGroupService } from '../services/identity-group.service';
|
||||
import { mockFoodGroups, mockMeatChicken, mockVegetableAubergine } from '../mock/group-cloud.mock';
|
||||
import { TranslationMock, TranslationService } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness, MatChipListHarness } from '@angular/material/chips/testing';
|
||||
import { MatIconHarness } from '@angular/material/icon/testing';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
|
||||
describe('GroupCloudComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
let component: GroupCloudComponent;
|
||||
let fixture: ComponentFixture<GroupCloudComponent>;
|
||||
let element: HTMLElement;
|
||||
let identityGroupService: IdentityGroupService;
|
||||
let findGroupsByNameSpy;
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
/**
|
||||
* get the native element for the selector
|
||||
*
|
||||
* @param selector selector
|
||||
* @returns native element
|
||||
*/
|
||||
function getElement<T = HTMLElement>(selector: string): T {
|
||||
return fixture.nativeElement.querySelector(selector);
|
||||
}
|
||||
let findGroupsByNameSpy: jasmine.Spy;
|
||||
|
||||
/**
|
||||
* search group by value
|
||||
@@ -50,14 +45,9 @@ describe('GroupCloudComponent', () => {
|
||||
* @param value element input value
|
||||
*/
|
||||
async function searchGroup(value: string) {
|
||||
const input = getElement<HTMLInputElement>('input');
|
||||
input.focus();
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event('keyup'));
|
||||
input.dispatchEvent(new Event('input'));
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
const input = await loader.getHarness(MatInputHarness);
|
||||
await input.focus();
|
||||
await input.setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,17 +56,10 @@ describe('GroupCloudComponent', () => {
|
||||
* @param value value
|
||||
*/
|
||||
async function searchGroupsAndBlur(value: string) {
|
||||
const input = getElement<HTMLInputElement>('input');
|
||||
input.focus();
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event('keyup'));
|
||||
input.dispatchEvent(new Event('input'));
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
input.blur();
|
||||
fixture.detectChanges();
|
||||
const input = await loader.getHarness(MatInputHarness);
|
||||
await input.focus();
|
||||
await input.setValue(value);
|
||||
await input.blur();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,20 +73,14 @@ describe('GroupCloudComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
NoopAnimationsModule,
|
||||
GroupCloudModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock }
|
||||
]
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, ProcessServiceCloudTestingModule, GroupCloudModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(GroupCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
|
||||
identityGroupService = TestBed.inject(IdentityGroupService);
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', () => {
|
||||
@@ -116,7 +93,6 @@ describe('GroupCloudComponent', () => {
|
||||
});
|
||||
|
||||
describe('Search group', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
findGroupsByNameSpy = spyOn(identityGroupService, 'search').and.returnValue(of(mockFoodGroups));
|
||||
@@ -209,19 +185,19 @@ describe('GroupCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should not pre-select any group when preSelectGroups is empty - single mode', () => {
|
||||
it('should not pre-select any group when preSelectGroups is empty - single mode', async () => {
|
||||
component.mode = 'single';
|
||||
fixture.detectChanges();
|
||||
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip'));
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should not pre-select any group when preSelectGroups is empty - multiple mode', () => {
|
||||
it('should not pre-select any group when preSelectGroups is empty - multiple mode', async () => {
|
||||
component.mode = 'multiple';
|
||||
fixture.detectChanges();
|
||||
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip'));
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
@@ -236,10 +212,11 @@ describe('GroupCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should show only one mat chip with the first preSelectedGroup', () => {
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip-row'));
|
||||
it('should show only one mat chip with the first preSelectedGroup', async () => {
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(1);
|
||||
expect(chips[0].attributes['data-automation-id']).toEqual(`adf-cloud-group-chip-${mockVegetableAubergine.name}`);
|
||||
const testId = await (await chips[0].host()).getAttribute('data-automation-id');
|
||||
expect(testId).toEqual(`adf-cloud-group-chip-${mockVegetableAubergine.name}`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -253,12 +230,13 @@ describe('GroupCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should render all preselected groups', () => {
|
||||
it('should render all preselected groups', async () => {
|
||||
component.mode = 'multiple';
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges({ preSelectGroups: change });
|
||||
fixture.detectChanges();
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip-row'));
|
||||
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
});
|
||||
|
||||
@@ -267,42 +245,40 @@ describe('GroupCloudComponent', () => {
|
||||
const changedGroupsEmitterSpy = spyOn(component.changedGroups, 'emit');
|
||||
component.mode = 'multiple';
|
||||
|
||||
const removeIcon = fixture.debugElement.query(By.css('mat-chip-row mat-icon'));
|
||||
removeIcon.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
const chip = await loader.getHarness(MatChipHarness);
|
||||
const icon = await chip.getHarness(MatIconHarness);
|
||||
await (await icon.host()).click();
|
||||
|
||||
await fixture.whenStable();
|
||||
expect(removeGroupEmitterSpy).toHaveBeenCalledWith(mockVegetableAubergine);
|
||||
expect(changedGroupsEmitterSpy).toHaveBeenCalledWith([mockMeatChicken]);
|
||||
expect(component.selectedGroups.indexOf({
|
||||
id: mockMeatChicken.id,
|
||||
name: mockMeatChicken.name
|
||||
})).toEqual(-1);
|
||||
expect(
|
||||
component.selectedGroups.indexOf({
|
||||
id: mockMeatChicken.id,
|
||||
name: mockMeatChicken.name
|
||||
})
|
||||
).toEqual(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Multiple Mode with read-only', () => {
|
||||
|
||||
it('Should not show remove icon for pre-selected groups if readonly property set to true', async () => {
|
||||
component.mode = 'multiple';
|
||||
component.preSelectGroups = [
|
||||
{ id: mockVegetableAubergine.id, name: mockVegetableAubergine.name, readonly: true },
|
||||
mockMeatChicken
|
||||
];
|
||||
component.preSelectGroups = [{ id: mockVegetableAubergine.id, name: mockVegetableAubergine.name, readonly: true }, mockMeatChicken];
|
||||
const changes = new SimpleChange(null, [{ name: mockVegetableAubergine.name }], false);
|
||||
component.ngOnChanges({ preSelectGroups: changes });
|
||||
fixture.detectChanges();
|
||||
|
||||
await fixture.whenStable();
|
||||
|
||||
const chipList = fixture.nativeElement.querySelectorAll('mat-chip-grid mat-chip-row');
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
|
||||
expect(chipList.length).toBe(2);
|
||||
const removeIconAubergine = getElement(`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockVegetableAubergine.name}"]`);
|
||||
const removeIconAubergine = element.querySelector(
|
||||
`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockVegetableAubergine.name}"]`
|
||||
);
|
||||
expect(removeIconAubergine).toBeNull();
|
||||
const removeIconPepper = getElement(`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockMeatChicken.name}"]`);
|
||||
const removeIconPepper = element.querySelector(`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockMeatChicken.name}"]`);
|
||||
expect(removeIconPepper).not.toBeNull();
|
||||
|
||||
});
|
||||
|
||||
it('Should be able to remove preselected groups if readonly property set to false', async () => {
|
||||
@@ -315,28 +291,26 @@ describe('GroupCloudComponent', () => {
|
||||
const removeGroupSpy = spyOn(component.removeGroup, 'emit');
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
let chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
|
||||
const chipList = fixture.nativeElement.querySelectorAll('mat-chip-grid mat-chip-row');
|
||||
expect(chipList.length).toBe(2);
|
||||
|
||||
const removeIcon = getElement(`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockMeatChicken.name}"]`);
|
||||
const removeIcon = element.querySelector<HTMLElement>(`[data-automation-id="adf-cloud-group-chip-remove-icon-${mockMeatChicken.name}"]`);
|
||||
removeIcon.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(removeGroupSpy).toHaveBeenCalled();
|
||||
expect(fixture.nativeElement.querySelectorAll('mat-chip-grid mat-chip-row').length).toBe(1);
|
||||
|
||||
chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should removeDuplicatedGroups return only unique groups', () => {
|
||||
const duplicatedGroups = [ mockMeatChicken, mockMeatChicken];
|
||||
const duplicatedGroups = [mockMeatChicken, mockMeatChicken];
|
||||
expect(component.removeDuplicatedGroups(duplicatedGroups)).toEqual([mockMeatChicken]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Preselected groups and validation enabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(identityGroupService, 'search').and.throwError('Invalid group');
|
||||
component.validate = true;
|
||||
@@ -365,7 +339,7 @@ describe('GroupCloudComponent', () => {
|
||||
describe('Component readonly mode', () => {
|
||||
const change = new SimpleChange(null, mockFoodGroups, false);
|
||||
|
||||
it('should chip list be disabled and show one single chip - single mode', () => {
|
||||
it('should chip list be disabled and show one single chip - single mode', async () => {
|
||||
component.mode = 'single';
|
||||
component.readOnly = true;
|
||||
component.preSelectGroups = mockFoodGroups;
|
||||
@@ -373,16 +347,14 @@ describe('GroupCloudComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip-row'));
|
||||
const chipList = getElement('mat-chip-grid');
|
||||
|
||||
expect(chips).toBeDefined();
|
||||
expect(chipList).toBeDefined();
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(1);
|
||||
expect(chipList.attributes['ng-reflect-disabled']?.value).toEqual('true');
|
||||
|
||||
const chipList = await loader.getHarness(MatChipListHarness);
|
||||
expect(await chipList.isDisabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should chip list be disabled and show all the chips - multiple mode', () => {
|
||||
it('should chip list be disabled and show all the chips - multiple mode', async () => {
|
||||
component.mode = 'multiple';
|
||||
component.readOnly = true;
|
||||
component.preSelectGroups = mockFoodGroups;
|
||||
@@ -390,14 +362,11 @@ describe('GroupCloudComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const chips = fixture.debugElement.queryAll(By.css('mat-chip-row'));
|
||||
const chipList = getElement('mat-chip-grid');
|
||||
|
||||
expect(chips).toBeDefined();
|
||||
expect(chipList).toBeDefined();
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
expect(chipList.attributes['ng-reflect-disabled']?.value).toEqual('true');
|
||||
|
||||
const chipList = await loader.getHarness(MatChipListHarness);
|
||||
expect(await chipList.isDisabled()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -25,31 +25,19 @@ import { By } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
import { IdentityUserServiceInterface } from '../services/identity-user.service.interface';
|
||||
import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.token';
|
||||
import {
|
||||
mockFoodUsers,
|
||||
mockKielbasaSausage,
|
||||
mockShepherdsPie,
|
||||
mockYorkshirePudding,
|
||||
mockPreselectedFoodUsers
|
||||
} from '../mock/people-cloud.mock';
|
||||
import { mockFoodUsers, mockKielbasaSausage, mockShepherdsPie, mockYorkshirePudding, mockPreselectedFoodUsers } from '../mock/people-cloud.mock';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness, MatChipListHarness } from '@angular/material/chips/testing';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
|
||||
describe('PeopleCloudComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
let component: PeopleCloudComponent;
|
||||
let fixture: ComponentFixture<PeopleCloudComponent>;
|
||||
let element: HTMLElement;
|
||||
let identityUserService: IdentityUserServiceInterface;
|
||||
let searchSpy;
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
/**
|
||||
* get the native element by selector
|
||||
*
|
||||
* @param selector selector
|
||||
* @returns native element
|
||||
*/
|
||||
function getElement<T = HTMLElement>(selector: string): T {
|
||||
return fixture.nativeElement.querySelector(selector);
|
||||
}
|
||||
let searchSpy: jasmine.Spy;
|
||||
|
||||
/**
|
||||
* Search users by value
|
||||
@@ -57,14 +45,9 @@ describe('PeopleCloudComponent', () => {
|
||||
* @param value value
|
||||
*/
|
||||
async function searchUsers(value: string) {
|
||||
const input = getElement<HTMLInputElement>('input');
|
||||
input.focus();
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event('keyup'));
|
||||
input.dispatchEvent(new Event('input'));
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
const input = await loader.getHarness(MatInputHarness);
|
||||
await input.focus();
|
||||
await input.setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,17 +56,10 @@ describe('PeopleCloudComponent', () => {
|
||||
* @param value value
|
||||
*/
|
||||
async function searchUsersAndBlur(value: string) {
|
||||
const input = getElement<HTMLInputElement>('input');
|
||||
input.focus();
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event('keyup'));
|
||||
input.dispatchEvent(new Event('input'));
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
input.blur();
|
||||
fixture.detectChanges();
|
||||
const input = await loader.getHarness(MatInputHarness);
|
||||
await input.focus();
|
||||
await input.setValue(value);
|
||||
await input.blur();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,15 +71,6 @@ describe('PeopleCloudComponent', () => {
|
||||
return fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users chip list UI
|
||||
*
|
||||
* @returns list of debug elements
|
||||
*/
|
||||
function getUsersChipsUI(): DebugElement[] {
|
||||
return fixture.debugElement.queryAll(By.css('mat-chip-row'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first user from the list
|
||||
*
|
||||
@@ -119,23 +86,25 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
fixture = TestBed.createComponent(PeopleCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
|
||||
identityUserService = TestBed.inject(IDENTITY_USER_SERVICE_TOKEN);
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', () => {
|
||||
component.title = 'TITLE_KEY';
|
||||
fixture.detectChanges();
|
||||
|
||||
const matLabel = getElement<HTMLInputElement>('#adf-people-cloud-title-id');
|
||||
const matLabel = element.querySelector<HTMLInputElement>('#adf-people-cloud-title-id');
|
||||
|
||||
expect(matLabel.textContent).toEqual('TITLE_KEY');
|
||||
});
|
||||
|
||||
it('should not populate placeholder when title is not present', () => {
|
||||
it('should not populate placeholder when title is not present', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const matLabel = getElement<HTMLInputElement>('#adf-people-cloud-title-id');
|
||||
const matLabel = element.querySelector<HTMLInputElement>('#adf-people-cloud-title-id');
|
||||
|
||||
expect(matLabel.textContent).toEqual('');
|
||||
});
|
||||
@@ -190,7 +159,9 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his email matches one of the excluded users email', async () => {
|
||||
component.excludedUsers = [{ email: mockKielbasaSausage.email, username: 'new-username', firstName: 'new-first-name', lastName: 'new-last-name' }];
|
||||
component.excludedUsers = [
|
||||
{ email: mockKielbasaSausage.email, username: 'new-username', firstName: 'new-first-name', lastName: 'new-last-name' }
|
||||
];
|
||||
fixture.detectChanges();
|
||||
|
||||
await searchUsers('first-name');
|
||||
@@ -199,7 +170,15 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his id matches one of the excluded users id', async () => {
|
||||
component.excludedUsers = [{ id: mockKielbasaSausage.id, username: 'new-username', firstName: 'new-first-name', lastName: 'new-last-name', email: 'new-email@food.com' }];
|
||||
component.excludedUsers = [
|
||||
{
|
||||
id: mockKielbasaSausage.id,
|
||||
username: 'new-username',
|
||||
firstName: 'new-first-name',
|
||||
lastName: 'new-last-name',
|
||||
email: 'new-email@food.com'
|
||||
}
|
||||
];
|
||||
fixture.detectChanges();
|
||||
|
||||
await searchUsers('first-name');
|
||||
@@ -208,7 +187,9 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his username matches one of the excluded users username', async () => {
|
||||
component.excludedUsers = [{ username: mockKielbasaSausage.username, firstName: 'new-first-name', lastName: 'new-last-name', email: 'new-email@food.com' }];
|
||||
component.excludedUsers = [
|
||||
{ username: mockKielbasaSausage.username, firstName: 'new-first-name', lastName: 'new-last-name', email: 'new-email@food.com' }
|
||||
];
|
||||
fixture.detectChanges();
|
||||
|
||||
await searchUsers('first-name');
|
||||
@@ -295,17 +276,20 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
describe('No preselected users', () => {
|
||||
|
||||
it('should not pre-select any user when preSelectUsers is empty - single mode', () => {
|
||||
it('should not pre-select any user when preSelectUsers is empty - single mode', async () => {
|
||||
component.mode = 'single';
|
||||
fixture.detectChanges();
|
||||
expect(getUsersChipsUI().length).toEqual(0);
|
||||
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not pre-select any users when preSelectUsers is empty - multiple mode', () => {
|
||||
it('should not pre-select any users when preSelectUsers is empty - multiple mode', async () => {
|
||||
component.mode = 'multiple';
|
||||
fixture.detectChanges();
|
||||
expect(getUsersChipsUI().length).toEqual(0);
|
||||
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -321,14 +305,16 @@ describe('PeopleCloudComponent', () => {
|
||||
element = fixture.nativeElement;
|
||||
});
|
||||
|
||||
it('should show only one mat chip with the first preSelectedUser', () => {
|
||||
expect(getUsersChipsUI().length).toEqual(1);
|
||||
expect(getUsersChipsUI()[0].attributes['data-automation-id']).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[0].username}`);
|
||||
it('should show only one mat chip with the first preSelectedUser', async () => {
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(1);
|
||||
|
||||
const testId = await (await chips[0].host()).getAttribute('data-automation-id');
|
||||
expect(testId).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[0].username}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Multiple Mode with Pre-selected Users', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.mode = 'multiple';
|
||||
});
|
||||
@@ -341,9 +327,15 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
expect(getUsersChipsUI().length).toEqual(2);
|
||||
expect(getUsersChipsUI()[0].attributes['data-automation-id']).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[0].username}`);
|
||||
expect(getUsersChipsUI()[1].attributes['data-automation-id']).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[1].username}`);
|
||||
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toEqual(2);
|
||||
|
||||
const testId1 = await (await chips[0].host()).getAttribute('data-automation-id');
|
||||
const testId2 = await (await chips[1].host()).getAttribute('data-automation-id');
|
||||
|
||||
expect(testId1).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[0].username}`);
|
||||
expect(testId2).toEqual(`adf-people-cloud-chip-${mockPreselectedFoodUsers[1].username}`);
|
||||
});
|
||||
|
||||
it('Should not show remove icon for pre-selected users if readonly property set to true', async () => {
|
||||
@@ -355,12 +347,16 @@ describe('PeopleCloudComponent', () => {
|
||||
const change = new SimpleChange(null, component.preSelectUsers, false);
|
||||
component.ngOnChanges({ preSelectUsers: change });
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const removeIcon = getElement(`[data-automation-id="adf-people-cloud-chip-remove-icon-${mockPreselectedFoodUsers[0].username}"]`);
|
||||
const removeIcon = element.querySelector(
|
||||
`[data-automation-id="adf-people-cloud-chip-remove-icon-${mockPreselectedFoodUsers[0].username}"]`
|
||||
);
|
||||
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
|
||||
expect(getUsersChipsUI().length).toBe(2);
|
||||
expect(component.preSelectUsers[0].readonly).toBeTruthy();
|
||||
expect(component.preSelectUsers[1].readonly).toBeTruthy();
|
||||
expect(removeIcon).toBeNull();
|
||||
@@ -374,27 +370,32 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
const removeUserSpy = spyOn(component.removeUser, 'emit');
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const removeIcon = getElement(`[data-automation-id="adf-people-cloud-chip-remove-icon-${mockPreselectedFoodUsers[0].username}"]`);
|
||||
const removeIcon = element.querySelector<HTMLElement>(
|
||||
`[data-automation-id="adf-people-cloud-chip-remove-icon-${mockPreselectedFoodUsers[0].username}"]`
|
||||
);
|
||||
|
||||
expect(getUsersChipsUI().length).toBe(2);
|
||||
expect(component.preSelectUsers[0].readonly).toBe(false, 'Removable');
|
||||
expect(component.preSelectUsers[1].readonly).toBe(false, 'Removable');
|
||||
let chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
|
||||
expect(component.preSelectUsers[0].readonly).toBe(false);
|
||||
expect(component.preSelectUsers[1].readonly).toBe(false);
|
||||
|
||||
removeIcon.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(removeUserSpy).toHaveBeenCalled();
|
||||
expect(getUsersChipsUI().length).toBe(1);
|
||||
|
||||
chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(1);
|
||||
});
|
||||
|
||||
describe('Component readonly mode', () => {
|
||||
const change = new SimpleChange(null, mockPreselectedFoodUsers, false);
|
||||
|
||||
it('should chip list be disabled and show one single chip - single mode', () => {
|
||||
it('should chip list be disabled and show one single chip - single mode', async () => {
|
||||
component.mode = 'single';
|
||||
component.readOnly = true;
|
||||
component.preSelectUsers = mockPreselectedFoodUsers;
|
||||
@@ -402,15 +403,14 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const chipList = getElement('mat-chip-grid');
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(1);
|
||||
|
||||
expect(getUsersChipsUI()).toBeDefined();
|
||||
expect(chipList).toBeDefined();
|
||||
expect(getUsersChipsUI().length).toBe(1);
|
||||
expect(chipList.attributes['ng-reflect-disabled'].value).toEqual('true');
|
||||
const chipList = await loader.getHarness(MatChipListHarness);
|
||||
expect(await chipList.isDisabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should chip list be disabled and show mat chips for all the preselected users - multiple mode', () => {
|
||||
it('should chip list be disabled and show mat chips for all the preselected users - multiple mode', async () => {
|
||||
component.mode = 'multiple';
|
||||
component.readOnly = true;
|
||||
component.preSelectUsers = mockPreselectedFoodUsers;
|
||||
@@ -418,18 +418,16 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const chipList = getElement('mat-chip-grid');
|
||||
const chips = await loader.getAllHarnesses(MatChipHarness);
|
||||
expect(chips.length).toBe(2);
|
||||
|
||||
expect(getUsersChipsUI()).toBeDefined();
|
||||
expect(chipList).toBeDefined();
|
||||
expect(getUsersChipsUI().length).toBe(2);
|
||||
expect(chipList.attributes['ng-reflect-disabled'].value).toEqual('true');
|
||||
const chipList = await loader.getHarness(MatChipListHarness);
|
||||
expect(await chipList.isDisabled()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Preselected users and validation enabled', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(identityUserService, 'search').and.throwError('Invalid user');
|
||||
component.validate = true;
|
||||
|
Reference in New Issue
Block a user