[ACS-6140] reduce access to internal material classes (#9053)

* cleanup login (demo shell)

* cleanup e2e from useless calls

* [ci:force] cleanup e2e from useless calls

* [ci:force] cleanup e2e from useless calls

* [ci:force] improved uploader selectors

* [ci:force] remove useless selectors when automation id provided

* [ci:force] improved tests and selectors

* [ci:force] improved tests and selectors

* [ci:force] improved tests and selectors

* [ci:force] improved tests and selectors

* [ci:force] improved tests and selectors

* [ci:force] improved tests and selectors

* [ci:force] switch edit task filter to angular harness

* [ci:force] switch edit process filter to angular harness

* [ci:force] switch search chip list to angular harness

* [ci:force] switch search panel to angular harness

* [ci:force] switch search radio to angular harness

* [ci:force] switch search text to angular harness

* [ci:force] search logical filter

* [ci:force] search form component

* [ci:force] search filter container

* [ci:force] fix viewer test

* [ci:force] search facet chip harness

* [ci:force] search facet chip harness

* [ci:force] dropdown breadcrumb

* [ci:force] search check list

* [ci:force] folder dialog

* [ci:force] search filter component

* [ci:force] json cell

* [ci:force] amount widget

* [ci:force] checkbox widget

* [ci:force] multiline-text widget

* [ci:force] number widget

* [ci:force] text widget

* [ci:force] card view array item

* add permission dialog

* permission container component

* permission list component

* card view components

* search widget chip

* search facet chip

* edit service task filter

* card view components

* sites dropdown

* share dialog

* header component

* datetime widget

* remove comments
This commit is contained in:
Denys Vuika
2023-11-03 10:05:34 +00:00
committed by GitHub
parent 9278d9296f
commit 93fd0bec6c
62 changed files with 2335 additions and 2660 deletions

View File

@@ -47,12 +47,12 @@ describe('DataTableWidgetComponent', () => {
const errorIcon: string = 'error_outline';
const getDataVariable = (
variableConfig: VariableConfig,
schemaDefinition: DataColumn[],
processVariables?: TaskVariableCloud[],
variables?: TaskVariableCloud[]
) => new FormFieldModel(
new FormModel({ taskId: 'fake-task-id', processVariables, variables }), {
variableConfig: VariableConfig,
schemaDefinition: DataColumn[],
processVariables?: TaskVariableCloud[],
variables?: TaskVariableCloud[]
) =>
new FormFieldModel(new FormModel({ taskId: 'fake-task-id', processVariables, variables }), {
id: 'fake-datatable-id',
name: 'Data Table',
type: FormFieldTypes.DATA_TABLE,
@@ -71,11 +71,11 @@ describe('DataTableWidgetComponent', () => {
expect(failedErrorMsgElement.nativeElement.textContent.trim()).toBe(errorIcon.concat('FORM.FIELD.DATA_TABLE_LOAD_FAILED'));
};
const getPreview = () => fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget-preview"]');
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
ProcessServiceCloudTestingModule
]
imports: [ProcessServiceCloudTestingModule]
});
fixture = TestBed.createComponent(DataTableWidgetComponent);
widget = fixture.componentInstance;
@@ -83,7 +83,7 @@ describe('DataTableWidgetComponent', () => {
formCloudService = TestBed.inject(FormCloudService);
logService = TestBed.inject(LogService);
widget.field = new FormFieldModel( new FormModel({ taskId: 'fake-task-id' }), {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
type: FormFieldTypes.DATA_TABLE,
name: 'Data Table'
});
@@ -104,7 +104,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const dataTable = fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget"]');
const dataTablePreview = fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget-preview"]');
const dataTablePreview = getPreview();
expect(dataTable).toBeTruthy();
expect(dataTablePreview).toBeNull();
@@ -114,9 +114,7 @@ describe('DataTableWidgetComponent', () => {
widget.field = getDataVariable(mockVariableConfig, mockSchemaDefinition, [], mockJsonFormVariable);
fixture.detectChanges();
widget.dataSource.getColumns().forEach((column, index) =>
expect(column.key).toEqual(mockSchemaDefinition[index].key
));
widget.dataSource.getColumns().forEach((column, index) => expect(column.key).toEqual(mockSchemaDefinition[index].key));
});
it('should properly initialize data source with priority on the field value if process and form variables are provided', () => {
@@ -125,7 +123,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockAmericaCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -136,7 +134,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockAmericaCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -147,7 +145,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -157,7 +155,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -168,17 +166,22 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
it('should properly initialize json response data source based on variable if path is provided', () => {
widget.field = getDataVariable({ ...mockVariableConfig, optionsPath: 'response.my-data' }, mockSchemaDefinition, [], mockJsonNestedResponseFormVariable);
widget.field = getDataVariable(
{ ...mockVariableConfig, optionsPath: 'response.my-data' },
mockSchemaDefinition,
[],
mockJsonNestedResponseFormVariable
);
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -188,7 +191,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -198,7 +201,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const expectedData = new WidgetDataTableAdapter(mockEuropeCountriesData, mockSchemaDefinition);
expectedData.getRows().forEach(row => row.cssClass = '');
expectedData.getRows().forEach((row) => (row.cssClass = ''));
expect(widget.dataSource.getRows()).toEqual(expectedData.getRows());
});
@@ -209,7 +212,7 @@ describe('DataTableWidgetComponent', () => {
fixture.detectChanges();
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-data-table-widget-failed-message'));
const previewDataTable = fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget-preview"]');
const previewDataTable = getPreview();
expect(failedErrorMsgElement).toBeNull();
expect(previewDataTable).toBeTruthy();
@@ -220,7 +223,7 @@ describe('DataTableWidgetComponent', () => {
spyOn(formCloudService, 'getPreviewState').and.returnValue(true);
fixture.detectChanges();
const previewDataTable = fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget-preview"]');
const previewDataTable = getPreview();
const dataTable = fixture.nativeElement.querySelector('[data-automation-id="adf-data-table-widget"]');
expect(previewDataTable).toBeTruthy();
@@ -255,7 +258,12 @@ describe('DataTableWidgetComponent', () => {
});
it('should display and log error if path is incorrect', () => {
widget.field = getDataVariable({ ...mockVariableConfig, optionsPath: 'wrong.path' }, mockSchemaDefinition, mockJsonNestedResponseFormVariable, []);
widget.field = getDataVariable(
{ ...mockVariableConfig, optionsPath: 'wrong.path' },
mockSchemaDefinition,
mockJsonNestedResponseFormVariable,
[]
);
fixture.detectChanges();
checkDataTableErrorMessage();
@@ -264,7 +272,12 @@ describe('DataTableWidgetComponent', () => {
});
it('should display and log error if provided data by path is not an array', () => {
widget.field = getDataVariable({ ...mockVariableConfig, optionsPath: 'response.no-array' }, mockSchemaDefinition, mockJsonNestedResponseFormVariable, []);
widget.field = getDataVariable(
{ ...mockVariableConfig, optionsPath: 'response.no-array' },
mockSchemaDefinition,
mockJsonNestedResponseFormVariable,
[]
);
fixture.detectChanges();
checkDataTableErrorMessage();

View File

@@ -17,14 +17,16 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SimpleChange } from '@angular/core';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { MatDialog } from '@angular/material/dialog';
import { of } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { ProcessFilterDialogCloudComponent } from './process-filter-dialog-cloud.component';
import { EditProcessFilterCloudComponent, PROCESS_FILTER_ACTION_RESTORE, PROCESS_FILTER_ACTION_SAVE_DEFAULT } from './edit-process-filter-cloud.component';
import {
EditProcessFilterCloudComponent,
PROCESS_FILTER_ACTION_RESTORE,
PROCESS_FILTER_ACTION_SAVE_DEFAULT
} from './edit-process-filter-cloud.component';
import { ProcessFiltersCloudModule } from '../process-filters-cloud.module';
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
import { ProcessFilterCloudService } from '../services/process-filter-cloud.service';
@@ -40,8 +42,14 @@ import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud
import { mockAppVersions } from '../mock/process-filters-cloud.mock';
import { fakeEnvironmentList } from '../../../common/mock/environment.mock';
import { endOfDay, format, startOfDay, subYears, isValid } from 'date-fns';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatExpansionPanelHarness } from '@angular/material/expansion/testing';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
describe('EditProcessFilterCloudComponent', () => {
let loader: HarnessLoader;
let component: EditProcessFilterCloudComponent;
let service: ProcessFilterCloudService;
let fixture: ComponentFixture<EditProcessFilterCloudComponent>;
@@ -76,16 +84,8 @@ describe('EditProcessFilterCloudComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ProcessFiltersCloudModule,
ProcessServiceCloudTestingModule,
MatIconTestingModule
],
providers: [
MatDialog,
{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }
]
imports: [TranslateModule.forRoot(), ProcessFiltersCloudModule, ProcessServiceCloudTestingModule, MatIconTestingModule],
providers: [MatDialog, { provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
fixture = TestBed.createComponent(EditProcessFilterCloudComponent);
component = fixture.componentInstance;
@@ -96,45 +96,42 @@ describe('EditProcessFilterCloudComponent', () => {
alfrescoApiService = TestBed.inject(AlfrescoApiService);
dialog = TestBed.inject(MatDialog);
spyOn(dialog, 'open').and.returnValue({
afterClosed: () => of({
action: ProcessFilterDialogCloudComponent.ACTION_SAVE,
icon: 'icon',
name: 'fake-name'
})
afterClosed: () =>
of({
action: ProcessFilterDialogCloudComponent.ACTION_SAVE,
icon: 'icon',
name: 'fake-name'
})
} as any);
getProcessFilterByIdSpy = spyOn(service, 'getFilterById').and.returnValue(of(fakeFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
afterEach(() => {
fixture.destroy();
});
const clickExpansionPanel = async () => {
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
const getFilterActionButton = (action: string) =>
nativeElement.querySelector<HTMLButtonElement>(`[data-automation-id="adf-filter-action-${action}"]`);
fixture.detectChanges();
await fixture.whenStable();
const getSelect = (automationId: string) => loader.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="${automationId}"]` }));
const clickExpansionPanel = async () => {
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
};
const clickDeleteButton = async () => {
const deleteButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
deleteButton.click();
fixture.detectChanges();
await fixture.whenStable();
};
const clickPropertyStatus = () => {
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-status"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
};
it('should not raise filter change events if filter remains the same', () => {
let count = 0;
component.filterChange.subscribe(() => count++);
@@ -190,7 +187,7 @@ describe('EditProcessFilterCloudComponent', () => {
expect(title).toBeNull();
});
it('should not display mat-spinner if isloading set to false', async () => {
it('should not display spinner if isLoading set to false', async () => {
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
@@ -199,29 +196,30 @@ describe('EditProcessFilterCloudComponent', () => {
const title = nativeElement.querySelector<HTMLElement>('#adf-edit-process-filter-title-id');
const subTitle = nativeElement.querySelector<HTMLElement>('#adf-edit-process-filter-sub-title-id');
const matSpinnerElement = nativeElement.querySelector('.adf-cloud-edit-process-filter-loading-margin');
expect(matSpinnerElement).toBeNull();
const hasSpinner = await loader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBe(false);
expect(title).toBeDefined();
expect(subTitle).toBeDefined();
expect(title.innerText).toEqual('FakeRunningProcess');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE');
});
it('should display mat-spinner if isloading set to true', async () => {
it('should display spinner if isLoading set to true', async () => {
component.isLoading = true;
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
await clickExpansionPanel();
const matSpinnerElement = nativeElement.querySelector('.adf-cloud-edit-process-filter-loading-margin');
expect(matSpinnerElement).toBeDefined();
component.isLoading = true;
fixture.detectChanges();
const hasSpinner = await loader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBe(true);
});
describe('EditProcessFilter form', () => {
beforeEach(() => {
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
@@ -251,51 +249,45 @@ describe('EditProcessFilterCloudComponent', () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.disabled).toEqual(false);
});
it('should enable save button if the filter is changed for custom process filters', (done) => {
it('should enable save button if the filter is changed for custom process filters', async () => {
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editProcessFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
done();
});
await clickExpansionPanel();
clickPropertyStatus();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
stateOptions[2].nativeElement.click();
fixture.detectChanges();
const options = await select.getOptions();
await options[2].click();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(false);
});
it('should disable save button if the filter is not changed for custom filter', async () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(true);
});
});
describe('SaveAs Button', () => {
it('should disable saveAs button if the process filter is not changed for default filter', async () => {
getProcessFilterByIdSpy.and.returnValue(of({
id: 'filter-id',
name: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
}));
getProcessFilterByIdSpy.and.returnValue(
of({
id: 'filter-id',
name: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
})
);
const processFilterIdChange = new SimpleChange(null, 'filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
@@ -304,7 +296,7 @@ describe('EditProcessFilterCloudComponent', () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = getFilterActionButton('saveAs');
expect(saveButton.disabled).toEqual(true);
});
@@ -312,64 +304,54 @@ describe('EditProcessFilterCloudComponent', () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = getFilterActionButton('saveAs');
expect(saveButton.disabled).toEqual(true);
});
it('should enable saveAs button if the filter values are changed for default filter', (done) => {
getProcessFilterByIdSpy.and.returnValue(of({
id: 'filter-id',
name: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
}));
it('should enable saveAs button if the filter values are changed for default filter', async () => {
getProcessFilterByIdSpy.and.returnValue(
of({
id: 'filter-id',
name: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
})
);
const processFilterIdChange = new SimpleChange(null, 'filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editProcessFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
clickPropertyStatus();
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
stateOptions[2].nativeElement.click();
await clickExpansionPanel();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
const options = await select.getOptions();
await options[2].click();
const saveButton = getFilterActionButton('saveAs');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
});
it('should enable saveAs button if the filter values are changed for custom filter', (done) => {
it('should enable saveAs button if the filter values are changed for custom filter', async () => {
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editProcessFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
clickPropertyStatus();
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
stateOptions[2].nativeElement.click();
await clickExpansionPanel();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
const options = await select.getOptions();
await options[2].click();
const saveButton = getFilterActionButton('saveAs');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
});
});
@@ -394,43 +376,37 @@ describe('EditProcessFilterCloudComponent', () => {
await fixture.whenStable();
await clickExpansionPanel();
clickPropertyStatus();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const statusOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(statusOptions.length).toEqual(5);
const options = await select.getOptions();
expect(options.length).toEqual(5);
});
it('should display sort drop down', async () => {
fixture.detectChanges();
await fixture.whenStable();
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-sort"] .mat-select-trigger');
sortElement.click();
const select = await getSelect('adf-cloud-edit-process-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortOptions.length).toEqual(4);
const options = await select.getOptions();
expect(options.length).toEqual(4);
});
it('should display order drop down', async () => {
fixture.detectChanges();
await fixture.whenStable();
await clickExpansionPanel();
const orderElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-order"] .mat-select-trigger');
orderElement.click();
const select = await getSelect('adf-cloud-edit-process-property-order');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(orderOptions.length).toEqual(2);
const options = await select.getOptions();
expect(options.length).toEqual(2);
});
});
@@ -484,7 +460,7 @@ describe('EditProcessFilterCloudComponent', () => {
});
const oneYearAgoDate = format(subYears(new Date(), 1), 'yyyy-MM-dd');
const todayDate = format(new Date(),'yyyy-MM-dd');
const todayDate = format(new Date(), 'yyyy-MM-dd');
filter.suspendedFrom = oneYearAgoDate.toString();
filter.suspendedTo = todayDate.toString();
getProcessFilterByIdSpy.and.returnValue(of(filter));
@@ -584,7 +560,6 @@ describe('EditProcessFilterCloudComponent', () => {
});
it('should fetch appVersionMultiple options when appVersionMultiple filter property is set', async () => {
const applicationVersionsSpy = spyOn(processService, 'getApplicationVersions').and.returnValue(of(mockAppVersions));
fixture.detectChanges();
@@ -596,23 +571,23 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
const controller = component.editProcessFilterForm.get('appVersionMultiple');
const appVersionMultiple = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-appVersionMultiple"]');
appVersionMultiple.click();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-process-property-appVersionMultiple');
await select.open();
const appVersionOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const options = await select.getOptions();
expect(applicationVersionsSpy).toHaveBeenCalled();
expect(controller).toBeDefined();
expect(appVersionOptions.length).toEqual(2);
expect(appVersionOptions[0].nativeElement.innerText).toEqual('1');
expect(appVersionOptions[1].nativeElement.innerText).toEqual('2');
expect(options.length).toEqual(2);
expect(await options[0].getText()).toEqual('1');
expect(await options[1].getText()).toEqual('2');
});
it('should fetch process definitions when processDefinitionName filter property is set', async () => {
const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(
of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])
);
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -625,17 +600,15 @@ describe('EditProcessFilterCloudComponent', () => {
await fixture.whenStable();
const controller = component.editProcessFilterForm.get('processDefinitionName');
const processDefinitionNamesElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-processDefinitionName"]');
processDefinitionNamesElement.click();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-process-property-processDefinitionName');
await select.open();
const options = await select.getOptions();
expect(processSpy).toHaveBeenCalled();
expect(controller).toBeDefined();
const processDefinitionNamesOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(processDefinitionNamesOptions[0].nativeElement.value).toBeUndefined();
expect(processDefinitionNamesOptions[0].nativeElement.innerText).toEqual(component.allProcessDefinitionNamesOption.label);
expect(await options[0].getText()).toEqual(component.allProcessDefinitionNamesOption.label);
});
it('should display default sort properties', async () => {
@@ -647,27 +620,27 @@ describe('EditProcessFilterCloudComponent', () => {
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-sort"]');
sortElement.click();
const select = await getSelect('adf-cloud-edit-process-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const options = await select.getOptions();
const sortController = component.editProcessFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController).toBeDefined();
expect(sortController.value).toEqual('id');
expect(sortOptions.length).toEqual(4);
expect(options.length).toEqual(4);
});
it('should display sort properties when sort properties are specified', async () => {
getProcessFilterByIdSpy.and.returnValue(of({
id: 'filter-id',
processName: 'process-name',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
}));
getProcessFilterByIdSpy.and.returnValue(
of({
id: 'filter-id',
processName: 'process-name',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
})
);
component.sortProperties = ['id', 'name', 'processDefinitionId'];
fixture.detectChanges();
@@ -681,29 +654,29 @@ describe('EditProcessFilterCloudComponent', () => {
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-sort"]');
sortElement.click();
const select = await getSelect('adf-cloud-edit-process-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const options = await select.getOptions();
const sortController = component.editProcessFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController).toBeDefined();
expect(component.sortProperties).toBeDefined();
expect(component.sortProperties.length).toBe(3);
expect(sortController.value).toBe('my-custom-sort');
expect(sortOptions.length).toEqual(3);
expect(options.length).toEqual(3);
});
it('should display the process name label for the name property', async () => {
getProcessFilterByIdSpy.and.returnValue(of({
id: 'filter-id',
processName: 'process-name',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
}));
getProcessFilterByIdSpy.and.returnValue(
of({
id: 'filter-id',
processName: 'process-name',
sort: 'my-custom-sort',
processDefinitionId: 'process-definition-id',
priority: '12'
})
);
component.sortProperties = ['name'];
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
@@ -713,18 +686,14 @@ describe('EditProcessFilterCloudComponent', () => {
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-sort"]');
sortElement.click();
const select = await getSelect('adf-cloud-edit-process-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortOptions[0].nativeElement.textContent).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_NAME');
const options = await select.getOptions();
expect(await options[0].getText()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_NAME');
});
describe('edit filter actions', () => {
beforeEach(() => {
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
getProcessFilterByIdSpy.and.returnValue(of(fakeFilter));
@@ -737,31 +706,25 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.destroy();
});
it('should emit save event and save the filter on click save button', (done) => {
it('should emit save event and save the filter on click save button', async () => {
component.toggleFilterActions = true;
const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(of([fakeFilter]));
const saveSpy: jasmine.Spy = spyOn(component.action, 'emit');
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editProcessFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
saveButton.click();
expect(saveFilterSpy).toHaveBeenCalled();
expect(saveSpy).toHaveBeenCalled();
done();
});
clickPropertyStatus();
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
stateOptions[2].nativeElement.click();
await clickExpansionPanel();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
const options = await select.getOptions();
await options[2].click();
const saveButton = getFilterActionButton('save');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
saveButton.click();
expect(saveFilterSpy).toHaveBeenCalled();
expect(saveSpy).toHaveBeenCalled();
});
it('should emit delete event and delete the filter on click of delete button', async () => {
@@ -773,52 +736,41 @@ describe('EditProcessFilterCloudComponent', () => {
await fixture.whenStable();
await clickExpansionPanel();
clickPropertyStatus();
fixture.detectChanges();
await fixture.whenStable();
await clickDeleteButton();
expect(deleteFilterSpy).toHaveBeenCalled();
expect(deleteSpy).toHaveBeenCalled();
});
it('should emit saveAs event and add filter on click saveAs button', (done) => {
it('should emit saveAs event and add filter on click saveAs button', async () => {
component.toggleFilterActions = true;
const saveAsFilterSpy = spyOn(service, 'addFilter').and.callThrough();
const saveAsSpy = spyOn(component.action, 'emit');
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editProcessFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
saveButton.click();
expect(saveAsFilterSpy).toHaveBeenCalled();
expect(saveAsSpy).toHaveBeenCalled();
expect(dialog.open).toHaveBeenCalled();
done();
});
clickPropertyStatus();
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
stateOptions[2].nativeElement.click();
await clickExpansionPanel();
const select = await getSelect('adf-cloud-edit-process-property-status');
await select.open();
const options = await select.getOptions();
await options[2].click();
const saveButton = getFilterActionButton('saveAs');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
saveButton.click();
expect(saveAsFilterSpy).toHaveBeenCalled();
expect(saveAsSpy).toHaveBeenCalled();
expect(dialog.open).toHaveBeenCalled();
});
it('should display default filter actions', async () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveAsButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-save"]');
const deleteButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-delete"]');
const saveAsButton = getFilterActionButton('saveAs');
const saveButton = getFilterActionButton('save');
const deleteButton = getFilterActionButton('delete');
expect(component.processFilterActions).toBeDefined();
expect(component.processFilterActions.length).toEqual(3);
expect(saveButton).toBeDefined();
@@ -867,7 +819,9 @@ describe('EditProcessFilterCloudComponent', () => {
const saveDefaultFilterEmitSpy = spyOn(component.action, 'emit');
await clickExpansionPanel();
const saveDefaultFilterButton = nativeElement.querySelector<HTMLButtonElement>(`[data-automation-id="adf-filter-action-${PROCESS_FILTER_ACTION_SAVE_DEFAULT}"]`);
const saveDefaultFilterButton = nativeElement.querySelector<HTMLButtonElement>(
`[data-automation-id="adf-filter-action-${PROCESS_FILTER_ACTION_SAVE_DEFAULT}"]`
);
fixture.detectChanges();
expect(saveDefaultFilterButton.disabled).toBe(false);
saveDefaultFilterButton.click();
@@ -904,7 +858,9 @@ describe('EditProcessFilterCloudComponent', () => {
const resetDefaultsEmitSpy: jasmine.Spy = spyOn(component.action, 'emit');
await clickExpansionPanel();
const resetButton = nativeElement.querySelector<HTMLButtonElement>(`[data-automation-id="adf-filter-action-${PROCESS_FILTER_ACTION_RESTORE}"]`);
const resetButton = nativeElement.querySelector<HTMLButtonElement>(
`[data-automation-id="adf-filter-action-${PROCESS_FILTER_ACTION_RESTORE}"]`
);
fixture.detectChanges();
expect(resetButton.disabled).toBe(false);
resetButton.click();
@@ -926,9 +882,9 @@ describe('EditProcessFilterCloudComponent', () => {
await fixture.whenStable();
await clickExpansionPanel();
const saveAsButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-save"]');
const deleteButton = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-filter-action-delete"]');
const saveAsButton = getFilterActionButton('saveAs');
const saveButton = getFilterActionButton('save');
const deleteButton = getFilterActionButton('delete');
expect(component.processFilterActions).toBeDefined();
expect(component.processFilterActions.length).toEqual(3);
expect(saveButton).toBeDefined();
@@ -987,7 +943,7 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
component.onDateChanged('20/03/2023', { key: 'lastModifiedTo' } as any );
component.onDateChanged('20/03/2023', { key: 'lastModifiedTo' } as any);
expect(component.lastModifiedTo.value).toEqual(new Date('2023-03-20'));
expect(component.lastModifiedTo.valid).toBeTrue();
@@ -1005,7 +961,7 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
component.onDateChanged('20/03/2023', { key: 'lastModifiedFrom' } as any );
component.onDateChanged('20/03/2023', { key: 'lastModifiedFrom' } as any);
expect(component.lastModifiedFrom.value).toEqual(new Date('2023-03-20'));
expect(component.lastModifiedFrom.valid).toBeTrue();
@@ -1042,7 +998,9 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
const dateInput = nativeElement.querySelector<HTMLInputElement>(`[data-automation-id="adf-cloud-edit-process-property-lastModifiedFrom"]`);
const dateInput = nativeElement.querySelector<HTMLInputElement>(
`[data-automation-id="adf-cloud-edit-process-property-lastModifiedFrom"]`
);
expect(dateInput).not.toBeNull();
dateInput.value = '20/03/2023';
@@ -1061,7 +1019,9 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
const dateInput = nativeElement.querySelector<HTMLInputElement>(`[data-automation-id="adf-cloud-edit-process-property-lastModifiedFrom"]`);
const dateInput = nativeElement.querySelector<HTMLInputElement>(
`[data-automation-id="adf-cloud-edit-process-property-lastModifiedFrom"]`
);
expect(dateInput).not.toBeNull();
dateInput.value = 'invalid';
@@ -1165,7 +1125,7 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await clickExpansionPanel();
clickPropertyStatus();
await clickDeleteButton();
expect(deleteFilterSpy).toHaveBeenCalled();
@@ -1185,9 +1145,6 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await clickExpansionPanel();
clickPropertyStatus();
fixture.detectChanges();
await clickDeleteButton();
expect(deleteFilterSpy).toHaveBeenCalled();

View File

@@ -22,7 +22,7 @@
</ng-container>
<ng-template #loadingTemplate>
<div class="adf-cloud-edit-task-filter-loading-margin">
<mat-spinner [diameter]="30"></mat-spinner>
<mat-progress-spinner mode="indeterminate" [diameter]="30"></mat-progress-spinner>
</div>
</ng-template>
</mat-expansion-panel-header>

View File

@@ -17,10 +17,8 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SimpleChange } from '@angular/core';
import { By } from '@angular/platform-browser';
import { MatDialog } from '@angular/material/dialog';
import { of, Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
import { LocalPreferenceCloudService } from '../../../../services/local-preference-cloud.service';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
@@ -37,8 +35,14 @@ import { ProcessDefinitionCloud } from '../../../../models/process-definition-cl
import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component';
import { fakeEnvironmentList } from '../../../../common/mock/environment.mock';
import { mockApplicationTaskFilterProperties } from '../../mock/edit-task-filter-cloud.mock';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatExpansionPanelHarness } from '@angular/material/expansion/testing';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
describe('EditServiceTaskFilterCloudComponent', () => {
let loader: HarnessLoader;
let component: EditServiceTaskFilterCloudComponent;
let service: ServiceTaskFilterCloudService;
let appsService: AppsProcessCloudService;
@@ -51,16 +55,8 @@ describe('EditServiceTaskFilterCloudComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ProcessServiceCloudTestingModule,
TaskFiltersCloudModule,
MatIconTestingModule
],
providers: [
MatDialog,
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }
]
imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, TaskFiltersCloudModule, MatIconTestingModule],
providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
fixture = TestBed.createComponent(EditServiceTaskFilterCloudComponent);
component = fixture.componentInstance;
@@ -69,16 +65,19 @@ describe('EditServiceTaskFilterCloudComponent', () => {
taskService = TestBed.inject(TaskCloudService);
dialog = TestBed.inject(MatDialog);
const dialogRefMock: any = {
afterClosed: () => afterClosedSubject
afterClosed: () => afterClosedSubject
};
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeServiceFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
afterEach(() => fixture.destroy());
const getSelect = (automationId: string) => loader.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="${automationId}"]` }));
it('should fetch task filter by taskId', async () => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
@@ -93,9 +92,9 @@ describe('EditServiceTaskFilterCloudComponent', () => {
});
it('should fetch process definitions when processDefinitionName filter property is set', async () => {
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([
new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })
]));
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(
of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])
);
fixture.detectChanges();
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -136,7 +135,7 @@ describe('EditServiceTaskFilterCloudComponent', () => {
expect(title).toBeNull();
});
it('should not display mat-spinner if isloading set to false', async () => {
it('should not display spinner if isLoading set to false', async () => {
const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
@@ -145,27 +144,28 @@ describe('EditServiceTaskFilterCloudComponent', () => {
const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id');
const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id');
const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin');
expect(matSpinnerElement).toBeNull();
expect(await loader.hasHarness(MatProgressSpinnerHarness)).toBe(false);
expect(title.innerText).toEqual('FakeInvolvedTasks');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE');
});
it('should display mat-spinner if isloading set to true', async () => {
it('should display spinner if isLoading set to true', async () => {
component.isLoading = true;
const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin');
expect(matSpinnerElement).toBeDefined();
component.isLoading = true;
fixture.detectChanges();
expect(await loader.hasHarness(MatProgressSpinnerHarness)).toBe(true);
});
describe('EditServiceTaskFilter form', () => {
beforeEach(() => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
@@ -191,26 +191,25 @@ describe('EditServiceTaskFilterCloudComponent', () => {
describe('Save & Delete buttons', () => {
it('should disable save and delete button for default task filters', async () => {
getTaskFilterSpy.and.returnValue(of({
name: 'ADF_CLOUD_SERVICE_TASK_FILTERS.ALL_SERVICE_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
}));
getTaskFilterSpy.and.returnValue(
of({
name: 'ADF_CLOUD_SERVICE_TASK_FILTERS.ALL_SERVICE_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
})
);
const taskFilterIdChange = new SimpleChange(null, 'filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
expect(saveButton.disabled).toBe(true);
@@ -224,11 +223,8 @@ describe('EditServiceTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
expect(saveButton.disabled).toBe(true);
@@ -236,40 +232,34 @@ describe('EditServiceTaskFilterCloudComponent', () => {
expect(deleteButton.disabled).toBe(false);
});
it('should enable save button if the filter is changed for custom task filters', (done) => {
it('should enable save button if the filter is changed for custom task filters', async () => {
const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
const select = await loader.getHarness(
MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` })
);
await select.open();
const options = await select.getOptions();
await options[3].click();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
});
it('should disable save button if the filter is not changed for custom filter', async () => {
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
expect(saveButton.disabled).toBe(true);
@@ -278,26 +268,25 @@ describe('EditServiceTaskFilterCloudComponent', () => {
describe('SaveAs button', () => {
it('should disable saveAs button if the process filter is not changed for default filter', async () => {
getTaskFilterSpy.and.returnValue(of({
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
}));
getTaskFilterSpy.and.returnValue(
of({
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
})
);
const taskFilterIdChange = new SimpleChange(null, 'filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
expect(saveButton.disabled).toEqual(true);
@@ -305,88 +294,67 @@ describe('EditServiceTaskFilterCloudComponent', () => {
it('should disable saveAs button if the process filter is not changed for custom filter', async () => {
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
expect(saveButton.disabled).toEqual(true);
});
it('should enable saveAs button if the filter values are changed for default filter', (done) => {
getTaskFilterSpy.and.returnValue(of({
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
}));
it('should enable saveAs button if the filter values are changed for default filter', async () => {
getTaskFilterSpy.and.returnValue(
of({
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
id: 'filter-id',
key: 'all-fake-task',
icon: 'adjust',
sort: 'startDate',
status: 'ALL',
order: 'DESC'
})
);
const taskFilterIdChange = new SimpleChange(null, 'filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
const options = await select.getOptions();
await options[3].click();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
});
it('should enable saveAs button if the filter values are changed for custom filter', (done) => {
it('should enable saveAs button if the filter values are changed for custom filter', async () => {
component.toggleFilterActions = true;
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
const options = await select.getOptions();
await options[3].click();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
});
});
it('should display current task filter details', async () => {
fixture.detectChanges();
await fixture.whenStable();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]');
const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]');
@@ -399,75 +367,41 @@ describe('EditServiceTaskFilterCloudComponent', () => {
});
it('should display all the statuses that are defined in the task filter', async () => {
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-task-property-status');
await select.open();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]');
stateElement.click();
const options = await select.getOptions();
fixture.detectChanges();
await fixture.whenStable();
const statusOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-status"]'));
expect(statusOptions[0].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.ALL');
expect(statusOptions[1].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.STARTED');
expect(statusOptions[2].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.COMPLETED');
expect(statusOptions[3].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.CANCELLED');
expect(statusOptions[4].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.ERROR');
expect(await options[0].getText()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.ALL');
expect(await options[1].getText()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.STARTED');
expect(await options[2].getText()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.COMPLETED');
expect(await options[3].getText()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.CANCELLED');
expect(await options[4].getText()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.ERROR');
});
it('should display sort drop down', async () => {
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortOptions.length).toEqual(4);
const options = await select.getOptions();
expect(options.length).toEqual(4);
});
it('should display order drop down', async () => {
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-order"]` }));
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]');
orderElement.click();
fixture.detectChanges();
await fixture.whenStable();
const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(orderOptions.length).toEqual(2);
});
it('should have floating labels when values are present', async () => {
fixture.detectChanges();
await fixture.whenStable();
const inputLabelsNodes = document.querySelectorAll('mat-form-field');
inputLabelsNodes.forEach(labelNode => {
expect(labelNode.getAttribute('ng-reflect-float-label')).toBe('auto');
});
const options = await select.getOptions();
expect(options.length).toBe(2);
});
it('should able to build a editTaskFilter form with default properties if input is empty', async () => {
@@ -508,51 +442,50 @@ describe('EditServiceTaskFilterCloudComponent', () => {
});
describe('sort properties', () => {
it('should display default sort properties', async () => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const options = await select.getOptions();
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
expect(options.length).toBe(4);
});
it('should display sort properties when sort properties are specified', async () => {
component.sortProperties = ['id', 'name', 'processInstanceId'];
getTaskFilterSpy.and.returnValue(of({
sort: 'my-custom-sort',
processInstanceId: 'process-instance-id',
priority: '12'
}));
getTaskFilterSpy.and.returnValue(
of({
sort: 'my-custom-sort',
processInstanceId: 'process-instance-id',
priority: '12'
})
);
fixture.detectChanges();
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const options = await select.getOptions();
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(component.sortProperties.length).toBe(3);
expect(sortController.value).toBe('my-custom-sort');
expect(sortOptions.length).toEqual(3);
expect(options.length).toBe(3);
});
it('should display default sort properties if input is empty', async () => {
@@ -561,39 +494,35 @@ describe('EditServiceTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.sortProperties = [];
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const options = await select.getOptions();
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
expect(options.length).toBe(4);
});
});
describe('filter actions', () => {
it('should display default filter actions', async () => {
component.toggleFilterActions = true;
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']);
expect(component.taskFilterActions.map((action) => action.actionType)).toEqual(['save', 'saveAs', 'delete']);
expect(component.taskFilterActions.length).toBe(3);
expect(saveButton.disabled).toBe(true);
expect(saveAsButton.disabled).toBe(true);
@@ -608,14 +537,12 @@ describe('EditServiceTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.toggleFilterActions = true;
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']);
expect(component.taskFilterActions.map((action) => action.actionType)).toEqual(['save']);
expect(component.taskFilterActions.length).toBe(1);
expect(saveButton.disabled).toBeTruthy();
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
@@ -626,7 +553,6 @@ describe('EditServiceTaskFilterCloudComponent', () => {
});
describe('edit filter actions', () => {
beforeEach(() => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ id: taskFilterIdChange });
@@ -638,15 +564,16 @@ describe('EditServiceTaskFilterCloudComponent', () => {
component.toggleFilterActions = true;
spyOn(service, 'updateFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const options = await select.getOptions();
await options[3].click();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
await fixture.whenStable();
fixture.detectChanges();
@@ -660,12 +587,13 @@ describe('EditServiceTaskFilterCloudComponent', () => {
component.toggleFilterActions = true;
spyOn(service, 'deleteFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
await fixture.whenStable();
fixture.detectChanges();
@@ -680,18 +608,14 @@ describe('EditServiceTaskFilterCloudComponent', () => {
spyOn(service, 'addFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-sort"] .mat-option-ripple'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
const options = await select.getOptions();
await options[3].click();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
saveButton.dispatchEvent(new Event('click'));
@@ -713,12 +637,13 @@ describe('EditServiceTaskFilterCloudComponent', () => {
spyOn(service, 'deleteFilter').and.returnValue(of([]));
const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([]));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
await fixture.whenStable();
fixture.detectChanges();
@@ -734,12 +659,13 @@ describe('EditServiceTaskFilterCloudComponent', () => {
spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name' }]));
const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([]));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await panel.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` }));
await select.open();
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
await fixture.whenStable();
fixture.detectChanges();

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material/dialog';
import { of, Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
import { LocalPreferenceCloudService } from '../../../../services/local-preference-cloud.service';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
@@ -31,7 +30,6 @@ import { EditTaskFilterCloudComponent } from './edit-task-filter-cloud.component
import { TaskFilterCloudService } from '../../services/task-filter-cloud.service';
import { TaskCloudService } from '../../../services/task-cloud.service';
import { fakeFilter } from '../../mock/task-filters-cloud.mock';
import { AbstractControl } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { DateCloudFilterType } from '../../../../models/date-cloud-filter.model';
import { AssignmentType, TaskFilterCloudModel, TaskStatusFilter } from '../../models/filter-cloud.model';
@@ -55,8 +53,14 @@ import { mockFoodGroups } from '../../../../group/mock/group-cloud.mock';
import { SimpleChanges } from '@angular/core';
import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component';
import { set } from 'date-fns';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatExpansionPanelHarness } from '@angular/material/expansion/testing';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
describe('EditTaskFilterCloudComponent', () => {
let loader: HarnessLoader;
let component: EditTaskFilterCloudComponent;
let service: TaskFilterCloudService;
let appsService: AppsProcessCloudService;
@@ -71,17 +75,8 @@ describe('EditTaskFilterCloudComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ProcessServiceCloudTestingModule,
TaskFiltersCloudModule,
PeopleCloudModule,
MatIconTestingModule
],
providers: [
MatDialog,
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }
]
imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, TaskFiltersCloudModule, PeopleCloudModule, MatIconTestingModule],
providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
fixture = TestBed.createComponent(EditTaskFilterCloudComponent);
component = fixture.componentInstance;
@@ -92,24 +87,22 @@ describe('EditTaskFilterCloudComponent', () => {
alfrescoApiService = TestBed.inject(AlfrescoApiService);
dialog = TestBed.inject(MatDialog);
const dialogRefMock: any = {
afterClosed: () => afterClosedSubject
afterClosed: () => afterClosedSubject
};
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mockAlfrescoApi);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
afterEach(() => fixture.destroy());
const clickExpansionPanel = async () => {
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
const getFilterActionButton = (action: string) =>
nativeElement.querySelector<HTMLButtonElement>(`[data-automation-id="adf-filter-action-${action}"]`);
fixture.detectChanges();
await fixture.whenStable();
};
const getSelect = (automationId: string) => loader.getHarness(MatSelectHarness.with({ selector: `[data-automation-id="${automationId}"]` }));
it('should fetch task filter by taskId', async () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
@@ -125,93 +118,99 @@ describe('EditTaskFilterCloudComponent', () => {
});
describe('processInstanceId filter', () => {
const cssSelector = {
processInstanceIdInput: '[data-automation-id="adf-cloud-edit-task-property-processInstanceId"]'
};
/**
* expand filter panel
*/
function expandFilterPanel(){
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
}
/**
* resolve filter instance input element
*
* @returns native element
*/
function getProcessInstanceIdInputElement(){
function getProcessInstanceIdInputElement() {
return fixture.debugElement.query(By.css(cssSelector.processInstanceIdInput)).nativeElement;
}
it('should set processInstanceId filter when id changes', async () => {
getTaskFilterSpy.and.returnValue(of(mockTaskFilterResponse));
component.processInstanceId = 'fakeProcessInstanceId';
component.filterProperties = [ 'appName', 'processInstanceId', 'sort', 'order'];
component.filterProperties = ['appName', 'processInstanceId', 'sort', 'order'];
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
expandFilterPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(getProcessInstanceIdInputElement().value).toEqual('fakeProcessInstanceId');
});
it('should processInstanceId filter be empty string if processInstanceId is null', async () => {
getTaskFilterSpy.and.returnValue(of(mockTaskFilterResponseWithProcessInstanceIdNull));
component.processInstanceId = null;
component.filterProperties = [ 'appName', 'processInstanceId', 'sort', 'order'];
component.filterProperties = ['appName', 'processInstanceId', 'sort', 'order'];
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
expandFilterPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(getProcessInstanceIdInputElement().value).toEqual('');
});
it('should processInstanceId filter be empty string if processInstanceId is undefined', async () => {
getTaskFilterSpy.and.returnValue(of(mockTaskFilterResponseWithProcessInstanceIdNull));
component.processInstanceId = undefined;
component.filterProperties = [ 'appName', 'processInstanceId', 'sort', 'order'];
component.filterProperties = ['appName', 'processInstanceId', 'sort', 'order'];
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
expandFilterPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(getProcessInstanceIdInputElement().value).toEqual('');
});
it('should processInstanceId filter be set with the processInstanceId from response if processInstanceId input is null', async () => {
getTaskFilterSpy.and.returnValue(of(mockTaskFilterResponse));
component.processInstanceId = null;
component.filterProperties = [ 'appName', 'processInstanceId', 'sort', 'order'];
component.filterProperties = ['appName', 'processInstanceId', 'sort', 'order'];
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
expandFilterPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(getProcessInstanceIdInputElement().value).toEqual('fakeProcessInstanceIdFromResponse');
});
it('should processInstanceId filter be set with the processInstanceId from response if processInstanceId input is undefined', async () => {
getTaskFilterSpy.and.returnValue(of(mockTaskFilterResponse));
component.processInstanceId = undefined;
component.filterProperties = [ 'appName', 'processInstanceId', 'sort', 'order'];
component.filterProperties = ['appName', 'processInstanceId', 'sort', 'order'];
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
expandFilterPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(getProcessInstanceIdInputElement().value).toEqual('fakeProcessInstanceIdFromResponse');
});
});
it('should fetch process definitions when processDefinitionName filter property is set', async () => {
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(
of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])
);
fixture.detectChanges();
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -249,7 +248,7 @@ describe('EditTaskFilterCloudComponent', () => {
expect(title).toBeNull();
});
it('should not display mat-spinner if isloading set to false', async () => {
it('should not display spinner if isLoading set to false', async () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
@@ -257,26 +256,28 @@ describe('EditTaskFilterCloudComponent', () => {
const title = nativeElement.querySelector<HTMLElement>('#adf-edit-task-filter-title-id');
const subTitle = nativeElement.querySelector<HTMLElement>('#adf-edit-task-filter-sub-title-id');
const matSpinnerElement = nativeElement.querySelector<HTMLElement>('.adf-cloud-edit-task-filter-loading-margin');
expect(matSpinnerElement).toBeNull();
const hasSpinner = await loader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBe(false);
expect(title.innerText).toEqual('FakeInvolvedTasks');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE');
});
it('should display mat-spinner if isloading set to true', async () => {
it('should display spinner if isLoading set to true', async () => {
component.isLoading = true;
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const matSpinnerElement = nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin');
expect(matSpinnerElement).toBeDefined();
component.isLoading = true;
fixture.detectChanges();
const hasSpinner = await loader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBe(true);
});
describe('EditTaskFilter form', () => {
beforeEach(() => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
@@ -306,11 +307,13 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(true);
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.disabled).toBe(true);
});
@@ -319,45 +322,42 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(true);
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.disabled).toBe(false);
});
it('should enable save button if the filter is changed for custom task filters', (done) => {
it('should enable save button if the filter is changed for custom task filters', async () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const options = await select.getOptions();
await options[3].click();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(false);
});
it('should disable save button if the filter is not changed for custom filter', async () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toBe(true);
});
});
@@ -369,71 +369,63 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('save');
expect(saveButton.disabled).toEqual(true);
});
it('should disable saveAs button if the process filter is not changed for custom filter', async () => {
component.toggleFilterActions = true;
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('saveAs');
expect(saveButton.disabled).toEqual(true);
});
it('should enable saveAs button if the filter values are changed for default filter', (done) => {
it('should enable saveAs button if the filter values are changed for default filter', async () => {
getTaskFilterSpy.and.returnValue(of(mockDefaultTaskFilter));
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await loader.getHarness(
MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` })
);
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
const options = await select.getOptions();
await options[3].click();
const saveButton = getFilterActionButton('saveAs');
expect(saveButton.disabled).toEqual(false);
});
it('should enable saveAs button if the filter values are changed for custom filter', (done) => {
it('should enable saveAs button if the filter values are changed for custom filter', async () => {
component.toggleFilterActions = true;
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
component.editTaskFilterForm.valueChanges
.pipe(debounceTime(500))
.subscribe(() => {
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
fixture.detectChanges();
expect(saveButton.disabled).toEqual(false);
done();
});
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await loader.getHarness(
MatSelectHarness.with({ selector: `[data-automation-id="adf-cloud-edit-task-property-sort"]` })
);
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
const options = await select.getOptions();
await options[3].click();
const saveButton = getFilterActionButton('saveAs');
expect(saveButton.disabled).toEqual(false);
});
});
@@ -441,62 +433,61 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
await clickExpansionPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-status"]');
const assigneeElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-assignee"]');
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"]');
const orderElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-order"]');
expect(assigneeElement).toBeDefined();
expect(stateElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED');
expect(sortElement.textContent.trim()).toBe('id');
expect(orderElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING');
const status = await getSelect('adf-cloud-edit-task-property-status');
expect(await status.getValueText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED');
const assignee = nativeElement.querySelector(`[data-automation-id="adf-cloud-edit-task-property-assignee"]`);
expect(assignee).toBeDefined();
const sort = await getSelect('adf-cloud-edit-task-property-sort');
expect(await sort.getValueText()).toBe('id');
const order = await getSelect('adf-cloud-edit-task-property-order');
expect(await order.getValueText()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING');
});
it('should display all the statuses that are defined in the task filter', async () => {
await clickExpansionPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-status"]');
stateElement.click();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-task-property-status');
await select.open();
const statusOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-status"]'));
const options = await select.getOptions();
expect(statusOptions[0].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.ALL');
expect(statusOptions[1].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED');
expect(statusOptions[2].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.ASSIGNED');
expect(statusOptions[3].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.SUSPENDED');
expect(statusOptions[4].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CANCELLED');
expect(statusOptions[5].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.COMPLETED');
expect(await options[0].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.ALL');
expect(await options[1].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED');
expect(await options[2].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.ASSIGNED');
expect(await options[3].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.SUSPENDED');
expect(await options[4].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CANCELLED');
expect(await options[5].getText()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.COMPLETED');
});
it('should display sort drop down', async () => {
fixture.detectChanges();
await clickExpansionPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortOptions.length).toEqual(4);
const options = await select.getOptions();
expect(options.length).toBe(4);
});
it('should display order drop down', async () => {
fixture.detectChanges();
await clickExpansionPanel();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const orderElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-order"]');
orderElement.click();
const select = await getSelect('adf-cloud-edit-task-property-order');
await select.open();
fixture.detectChanges();
await fixture.whenStable();
const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(orderOptions.length).toEqual(2);
const options = await select.getOptions();
expect(options.length).toBe(2);
});
it('should able to build a editTaskFilter form with default properties if input is empty', async () => {
@@ -540,10 +531,12 @@ describe('EditTaskFilterCloudComponent', () => {
await fixture.whenStable();
expect(appController).toBeDefined();
expect(JSON.stringify(appController.value)).toBe(JSON.stringify({
id: 'mock-id',
username: 'testCompletedByUser'
}));
expect(JSON.stringify(appController.value)).toBe(
JSON.stringify({
id: 'mock-id',
username: 'testCompletedByUser'
})
);
});
it('should show completedBy filter', async () => {
@@ -564,7 +557,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('completedBy');
const startedDateTypeControl = component.editTaskFilterForm.get('completedBy');
startedDateTypeControl.setValue('hruser');
component.onChangedUser(mockFoodUsers, {
@@ -589,7 +582,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('dueDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('dueDateType');
startedDateTypeControl.setValue(DateCloudFilterType.TODAY);
component.filterChange.subscribe(() => {
@@ -600,22 +593,17 @@ describe('EditTaskFilterCloudComponent', () => {
component.onFilterChange();
});
it('should have correct options on dueDate filters', () => {
it('should have correct options on dueDate filters', async () => {
component.appName = 'fake';
component.filterProperties = ['appName', 'processInstanceId', 'priority', 'dueDateRange'];
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-process-property-dueDateRange"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const select = await getSelect('adf-cloud-edit-process-property-dueDateRange');
await select.open();
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortOptions.length).toEqual(5);
sortOptions[1].nativeElement.click('TODAY');
sortOptions[2].nativeElement.click('TOMOROW');
sortOptions[3].nativeElement.click('NEXT_7_DAYS');
sortOptions[4].nativeElement.click('RANGE');
const options = await select.getOptions();
expect(options.length).toEqual(5);
});
it('should update form on date range value is updated', (done) => {
@@ -624,7 +612,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('dueDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('dueDateType');
startedDateTypeControl.setValue(DateCloudFilterType.RANGE);
component.onDateRangeFilterChanged(mockDateFilterStartEnd, mockDueDateFilter);
@@ -645,7 +633,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('completedDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('completedDateType');
startedDateTypeControl.setValue(DateCloudFilterType.TODAY);
component.filterChange.subscribe(() => {
@@ -662,7 +650,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('completedDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('completedDateType');
startedDateTypeControl.setValue(DateCloudFilterType.RANGE);
component.onDateRangeFilterChanged(mockDateFilterStartEnd, mockCompletedDateFilter);
@@ -682,7 +670,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('createdDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('createdDateType');
startedDateTypeControl.setValue(DateCloudFilterType.TODAY);
component.filterChange.subscribe(() => {
@@ -699,7 +687,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.filterProperties = ['assignment'];
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const assignmentComponent = nativeElement.querySelector<HTMLElement>('adf-cloud-task-assignment-filter');
const assignmentComponent = nativeElement.querySelector('adf-cloud-task-assignment-filter');
expect(assignmentComponent).toBeTruthy();
});
@@ -723,7 +711,7 @@ describe('EditTaskFilterCloudComponent', () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('createdDateType');
const startedDateTypeControl = component.editTaskFilterForm.get('createdDateType');
startedDateTypeControl.setValue(DateCloudFilterType.RANGE);
component.onDateRangeFilterChanged(mockDateFilterStartEnd, mockCreatedDateFilter);
@@ -755,7 +743,6 @@ describe('EditTaskFilterCloudComponent', () => {
});
describe('assignment type change', () => {
beforeEach(() => {
component.appName = 'fake';
component.filterProperties = ['assignment', 'status'];
@@ -800,47 +787,49 @@ describe('EditTaskFilterCloudComponent', () => {
});
describe('sort properties', () => {
it('should display default sort properties', async () => {
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const options = await select.getOptions();
expect(options.length).toBe(4);
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
});
it('should display sort properties when sort properties are specified', async () => {
component.sortProperties = ['id', 'name', 'processInstanceId'];
getTaskFilterSpy.and.returnValue(of({
sort: 'my-custom-sort',
processInstanceId: 'process-instance-id',
priority: '12'
}));
getTaskFilterSpy.and.returnValue(
of({
sort: 'my-custom-sort',
processInstanceId: 'process-instance-id',
priority: '12'
})
);
fixture.detectChanges();
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const options = await select.getOptions();
expect(options.length).toBe(3);
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(component.sortProperties.length).toBe(3);
expect(sortController.value).toBe('my-custom-sort');
expect(sortOptions.length).toEqual(3);
});
it('should display default sort properties if input is empty', async () => {
@@ -848,32 +837,34 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
component.sortProperties = [];
fixture.detectChanges();
await clickExpansionPanel();
const sortElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"]');
sortElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const options = await select.getOptions();
expect(options.length).toBe(4);
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
});
});
describe('filter actions', () => {
it('should display default filter actions', async () => {
component.toggleFilterActions = true;
component.ngOnChanges({ id: mockTaskFilterIdChange });
fixture.detectChanges();
await clickExpansionPanel();
const saveAsButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']);
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveAsButton = getFilterActionButton('saveAs');
const saveButton = getFilterActionButton('save');
const deleteButton = getFilterActionButton('delete');
expect(component.taskFilterActions.map((action) => action.actionType)).toEqual(['save', 'saveAs', 'delete']);
expect(component.taskFilterActions.length).toBe(3);
expect(saveButton.disabled).toBe(true);
expect(saveAsButton.disabled).toBe(true);
@@ -889,14 +880,16 @@ describe('EditTaskFilterCloudComponent', () => {
component.toggleFilterActions = true;
fixture.detectChanges();
await clickExpansionPanel();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']);
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = getFilterActionButton('save');
expect(component.taskFilterActions.map((action) => action.actionType)).toEqual(['save']);
expect(component.taskFilterActions.length).toBe(1);
expect(saveButton.disabled).toBeTruthy();
const saveAsButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const saveAsButton = getFilterActionButton('saveAs');
const deleteButton = getFilterActionButton('delete');
expect(saveAsButton).toBeFalsy();
expect(deleteButton).toBeFalsy();
});
@@ -928,7 +921,6 @@ describe('EditTaskFilterCloudComponent', () => {
});
describe('edit filter actions', () => {
beforeEach(() => {
component.changedTaskFilter = { name: 'mock-filter-name' } as TaskFilterCloudModel;
component.ngOnChanges({ id: mockTaskFilterIdChange } as SimpleChanges);
@@ -936,43 +928,35 @@ describe('EditTaskFilterCloudComponent', () => {
component.toggleFilterActions = true;
});
it('should emit save event and save the filter on click save button', fakeAsync(() => {
it('should emit save event and save the filter on click save button', async () => {
spyOn(service, 'updateFilter').and.returnValue(of([new TaskFilterCloudModel({ name: 'mock-filter-name' })]));
fixture.detectChanges();
const expansionPanel = nativeElement.querySelector<HTMLElement>('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
tick();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
tick();
const sortOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-sort"] .mat-option-ripple'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
tick(550);
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-save"]');
saveButton.dispatchEvent(new Event('click'));
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const options = await select.getOptions();
await options[3].click();
const saveButton = getFilterActionButton('save');
saveButton.click();
fixture.detectChanges();
tick();
expect(service.updateFilter).toHaveBeenCalled();
expect(component.action.emit).toHaveBeenCalled();
}));
});
it('should emit delete event and delete the filter on click of delete button', async () => {
spyOn(service, 'deleteFilter').and.returnValue(of(null));
fixture.detectChanges();
await clickExpansionPanel();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.getAttribute('disabled')).toBeNull();
deleteButton.click();
expect(service.deleteFilter).toHaveBeenCalled();
@@ -982,19 +966,18 @@ describe('EditTaskFilterCloudComponent', () => {
it('should emit saveAs event and add filter on click saveAs button', async () => {
spyOn(service, 'addFilter').and.returnValue(of(null));
fixture.detectChanges();
await clickExpansionPanel();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const sortOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-sort"] .mat-option-ripple'));
sortOptions[3].nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
const select = await getSelect('adf-cloud-edit-task-property-sort');
await select.open();
const saveButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-saveAs"]');
saveButton.dispatchEvent(new Event('click'));
const options = await select.getOptions();
await options[3].click();
const saveButton = getFilterActionButton('saveAs');
saveButton.click();
fixture.detectChanges();
afterClosedSubject.next({
action: TaskFilterDialogCloudComponent.ACTION_SAVE,
@@ -1012,14 +995,11 @@ describe('EditTaskFilterCloudComponent', () => {
spyOn(service, 'deleteFilter').and.returnValue(of([]));
const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([]));
fixture.detectChanges();
await clickExpansionPanel();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.disabled).toBe(false);
deleteButton.click();
expect(service.deleteFilter).toHaveBeenCalled();
@@ -1031,14 +1011,11 @@ describe('EditTaskFilterCloudComponent', () => {
spyOn(service, 'deleteFilter').and.returnValue(of([new TaskFilterCloudModel({ name: 'mock-filter-name' })]));
const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([]));
fixture.detectChanges();
await clickExpansionPanel();
const stateElement = nativeElement.querySelector<HTMLElement>('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
await fixture.whenStable();
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
const deleteButton = nativeElement.querySelector<HTMLButtonElement>('[data-automation-id="adf-filter-action-delete"]');
const deleteButton = getFilterActionButton('delete');
expect(deleteButton.disabled).toBe(false);
deleteButton.click();
expect(service.deleteFilter).toHaveBeenCalled();

View File

@@ -31,6 +31,7 @@ import { TaskFilterDialogCloudComponent } from './components/task-filter-dialog/
import { ServiceTaskFiltersCloudComponent } from './components/service-task-filters-cloud.component';
import { TaskAssignmentFilterCloudComponent } from './components/task-assignment-filter/task-assignment-filter.component';
import { GroupCloudModule } from '../../group/group-cloud.module';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
@NgModule({
imports: [
@@ -43,7 +44,8 @@ import { GroupCloudModule } from '../../group/group-cloud.module';
CoreModule,
GroupCloudModule,
ProcessCommonModule,
PeopleCloudModule
PeopleCloudModule,
MatProgressSpinnerModule
],
declarations: [
TaskFiltersCloudComponent,
@@ -53,11 +55,6 @@ import { GroupCloudModule } from '../../group/group-cloud.module';
TaskFilterDialogCloudComponent,
TaskAssignmentFilterCloudComponent
],
exports: [
TaskFiltersCloudComponent,
ServiceTaskFiltersCloudComponent,
EditTaskFilterCloudComponent,
EditServiceTaskFilterCloudComponent
]
exports: [TaskFiltersCloudComponent, ServiceTaskFiltersCloudComponent, EditTaskFilterCloudComponent, EditServiceTaskFilterCloudComponent]
})
export class TaskFiltersCloudModule { }
export class TaskFiltersCloudModule {}