|
|
@@ -19,7 +19,7 @@ import { Category, CategoryPaging, ResultNode, ResultSetPaging } from '@alfresco
|
|
|
|
import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
|
|
|
|
import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
|
|
|
|
import { Validators } from '@angular/forms';
|
|
|
|
import { Validators } from '@angular/forms';
|
|
|
|
import { MatError } from '@angular/material/form-field';
|
|
|
|
import { MatError } from '@angular/material/form-field';
|
|
|
|
import { MatSelectionList } from '@angular/material/list';
|
|
|
|
import { MatList } from '@angular/material/list';
|
|
|
|
import { By } from '@angular/platform-browser';
|
|
|
|
import { By } from '@angular/platform-browser';
|
|
|
|
import { of, Subject } from 'rxjs';
|
|
|
|
import { of, Subject } from 'rxjs';
|
|
|
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
|
|
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
|
|
@@ -29,7 +29,6 @@ import { CategoriesManagementComponent } from './categories-management.component
|
|
|
|
import { HarnessLoader } from '@angular/cdk/testing';
|
|
|
|
import { HarnessLoader } from '@angular/cdk/testing';
|
|
|
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
|
|
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
|
|
|
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
|
|
|
|
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
|
|
|
|
import { MatListOptionHarness } from '@angular/material/list/testing';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('CategoriesManagementComponent', () => {
|
|
|
|
describe('CategoriesManagementComponent', () => {
|
|
|
|
let loader: HarnessLoader;
|
|
|
|
let loader: HarnessLoader;
|
|
|
@@ -91,8 +90,8 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @returns list of material option element
|
|
|
|
* @returns list of material option element
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getExistingCategoriesList(): Promise<MatListOptionHarness[]> {
|
|
|
|
function getExistingCategoriesList(): HTMLElement[] {
|
|
|
|
return loader.getAllHarnesses(MatListOptionHarness);
|
|
|
|
return fixture.debugElement.queryAll(By.css('.adf-category'))?.map((debugElem) => debugElem.nativeElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -159,7 +158,7 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
* @returns native element
|
|
|
|
* @returns native element
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getCreateCategoryLabel(): HTMLSpanElement {
|
|
|
|
function getCreateCategoryLabel(): HTMLSpanElement {
|
|
|
|
return fixture.debugElement.query(By.css('.adf-existing-categories-panel span.adf-create-category-label'))?.nativeElement;
|
|
|
|
return fixture.debugElement.query(By.css('.adf-create-category-label'))?.nativeElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -321,11 +320,10 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
expect(component.categories).toEqual([]);
|
|
|
|
expect(component.categories).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should not display create category label', fakeAsync(async () => {
|
|
|
|
it('should not display create category label', fakeAsync(() => {
|
|
|
|
typeCategory('test');
|
|
|
|
typeCategory('test');
|
|
|
|
fixture.detectChanges();
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(getCreateCategoryLabel()).toBeUndefined();
|
|
|
|
expect(getCreateCategoryLabel()).toBeUndefined();
|
|
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should not disable existing categories', fakeAsync(() => {
|
|
|
|
it('should not disable existing categories', fakeAsync(() => {
|
|
|
@@ -333,12 +331,13 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
|
|
|
|
|
|
|
|
expect(getSelectionList().disabled).toBeFalse();
|
|
|
|
expect(getSelectionList().disabled).toBeFalse();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
|
|
|
it('should add selected category to categories list and remove from existing categories', fakeAsync(async () => {
|
|
|
|
it('should add selected category to categories list and remove from existing categories', fakeAsync(() => {
|
|
|
|
const categoriesChangeSpy = spyOn(component.categoriesChange, 'emit').and.callThrough();
|
|
|
|
const categoriesChangeSpy = spyOn(component.categoriesChange, 'emit').and.callThrough();
|
|
|
|
typeCategory('test');
|
|
|
|
typeCategory('test');
|
|
|
|
const options = await getExistingCategoriesList();
|
|
|
|
const options = getExistingCategoriesList();
|
|
|
|
await options[0].select();
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
|
|
|
|
options[0].click();
|
|
|
|
|
|
|
|
|
|
|
|
expect(component.categories.length).toBe(3);
|
|
|
|
expect(component.categories.length).toBe(3);
|
|
|
|
expect(component.categories[2].name).toBe('testCat');
|
|
|
|
expect(component.categories[2].name).toBe('testCat');
|
|
|
@@ -348,11 +347,12 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
flush();
|
|
|
|
flush();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should remove selected category from categories list and add it back to existing categories', fakeAsync(async () => {
|
|
|
|
it('should remove selected category from categories list and add it back to existing categories', fakeAsync(() => {
|
|
|
|
typeCategory('test');
|
|
|
|
typeCategory('test');
|
|
|
|
|
|
|
|
const options = getExistingCategoriesList();
|
|
|
|
const options = await getExistingCategoriesList();
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
await options[0].select();
|
|
|
|
options[0].click();
|
|
|
|
|
|
|
|
fixture.detectChanges();
|
|
|
|
|
|
|
|
|
|
|
|
const categoriesChangeSpy = spyOn(component.categoriesChange, 'emit').and.callThrough();
|
|
|
|
const categoriesChangeSpy = spyOn(component.categoriesChange, 'emit').and.callThrough();
|
|
|
|
const removeCategoryButtons = getRemoveCategoryButtons();
|
|
|
|
const removeCategoryButtons = getRemoveCategoryButtons();
|
|
|
@@ -454,9 +454,9 @@ describe('CategoriesManagementComponent', () => {
|
|
|
|
expect(categoriesChangeSpy).toHaveBeenCalledOnceWith(component.categories);
|
|
|
|
expect(categoriesChangeSpy).toHaveBeenCalledOnceWith(component.categories);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should clear input after category is created', fakeAsync(async () => {
|
|
|
|
it('should clear input after category is created', fakeAsync(() => {
|
|
|
|
createCategory('test');
|
|
|
|
createCategory('test');
|
|
|
|
expect(await getExistingCategoriesList()).toEqual([]);
|
|
|
|
expect(getExistingCategoriesList()).toEqual([]);
|
|
|
|
expect(component.categoryNameControl.value).toBe('');
|
|
|
|
expect(component.categoryNameControl.value).toBe('');
|
|
|
|
expect(component.categoryNameControl.untouched).toBeTrue();
|
|
|
|
expect(component.categoryNameControl.untouched).toBeTrue();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|