Skip to content

Commit

Permalink
AAE-20141 Replace adf mat selectors process services (#9514)
Browse files Browse the repository at this point in the history
* AAE-20141 removing mat from unit tests in process-services

* AAE-20141 fix dropdown false-positives

* AAE-20141 dropdown editor remake

* AAE-20141 remove remaining selectors

* AAE-20141 fix radio buttons selector
  • Loading branch information
wojd0 authored Apr 9, 2024
1 parent b081800 commit 3bfadae
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { ProcessTestingModule } from '../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { mockEmittedTaskAttachments, mockTaskAttachments } from '../mock/task/task-attachments.mock';
import { ProcessContentService } from '../form/services/process-content.service';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatMenuItemHarness } from '@angular/material/menu/testing';

describe('TaskAttachmentList', () => {

Expand All @@ -35,6 +38,7 @@ describe('TaskAttachmentList', () => {
let getFileRawContentSpy: jasmine.Spy;
let getContentPreviewSpy: jasmine.Spy;
let disposableSuccess: any;
let loader: HarnessLoader;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -46,6 +50,7 @@ describe('TaskAttachmentList', () => {
});
fixture = TestBed.createComponent(TaskAttachmentListComponent);
component = fixture.componentInstance;
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);

service = TestBed.inject(ProcessContentService);

Expand Down Expand Up @@ -146,11 +151,12 @@ describe('TaskAttachmentList', () => {

fixture.detectChanges();
await fixture.whenStable();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;

const actionMenuItems = await loader.getAllHarnesses(MatMenuItemHarness);
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(actionMenu).toBe(3);
expect(actionMenuItems.length).toBe(3);
});

it('should not display remove action if attachments are read only', async () => {
Expand All @@ -166,11 +172,11 @@ describe('TaskAttachmentList', () => {
fixture.detectChanges();
await fixture.whenStable();

const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
const actionMenuItems = await loader.getAllHarnesses(MatMenuItemHarness);
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).toBeNull();
expect(actionMenu).toBe(2);
expect(actionMenuItems.length).toBe(2);
});

it('should show the empty list component when the attachments list is empty', async () => {
Expand Down
35 changes: 14 additions & 21 deletions lib/process-services/src/lib/form/form.component.visibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ import { TranslateModule } from '@ngx-translate/core';
import { TaskService } from './services/task.service';
import { TaskFormService } from './services/task-form.service';
import { TaskRepresentation } from '@alfresco/js-api';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';

describe('FormComponent UI and visibility', () => {
let component: FormComponent;
let taskService: TaskService;
let taskFormService: TaskFormService;
let fixture: ComponentFixture<FormComponent>;

const openSelect = () => {
const dropdown = fixture.debugElement.nativeElement.querySelector('.mat-select-trigger');
dropdown.click();
};
let loader: HarnessLoader;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -54,6 +53,7 @@ describe('FormComponent UI and visibility', () => {
});
fixture = TestBed.createComponent(FormComponent);
component = fixture.componentInstance;
loader = TestbedHarnessEnvironment.loader(fixture);
taskService = TestBed.inject(TaskService);
taskFormService = TestBed.inject(TaskFormService);
});
Expand Down Expand Up @@ -124,30 +124,23 @@ describe('FormComponent UI and visibility', () => {

const change = new SimpleChange(null, 1, true);
component.ngOnChanges({ taskId: change });
fixture.detectChanges();
await fixture.whenStable();

openSelect();
fixture.detectChanges();
await fixture.whenStable();

const options = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const dropdown = await loader.getHarness(MatSelectHarness);
await dropdown.open();
const options = await dropdown.getOptions();

const optOne = options[1];
const optTwo = options[2];
const optThree = options[3];

expect(optOne.nativeElement.innerText.trim()).toEqual('united kingdom');
expect(optTwo.nativeElement.innerText.trim()).toEqual('italy');
expect(optThree.nativeElement.innerText.trim()).toEqual('france');

optTwo.nativeElement.click();
expect((await optOne.getText()).trim()).toEqual('united kingdom');
expect((await optTwo.getText()).trim()).toEqual('italy');
expect((await optThree.getText()).trim()).toEqual('france');

fixture.detectChanges();
await fixture.whenStable();
await optTwo.click();

const dropdown = fixture.debugElement.queryAll(By.css('#country'));
expect(dropdown[0].nativeElement.innerText.trim()).toEqual('italy');
const dropdownCountries = fixture.debugElement.queryAll(By.css('#country'));
expect(dropdownCountries[0].nativeElement.innerText.trim()).toEqual('italy');
});

describe('Visibility conditions', () => {
Expand Down
40 changes: 21 additions & 19 deletions lib/process-services/src/lib/form/start-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { WidgetVisibilityService, FormModel, FormOutcomeModel } from '@alfresco/
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { ProcessTestingModule } from '../testing/process.testing.module';
import { ProcessService } from '../process-list/services/process.service';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatCardHarness } from '@angular/material/card/testing';
import { MatButtonHarness } from '@angular/material/button/testing';

describe('StartFormComponent', () => {

Expand All @@ -38,6 +43,7 @@ describe('StartFormComponent', () => {
let visibilityService: WidgetVisibilityService;
let translate: TranslateService;
let processService: ProcessService;
let loader: HarnessLoader;

const exampleId1 = 'my:process1';
const exampleId2 = 'my:process2';
Expand All @@ -52,6 +58,7 @@ describe('StartFormComponent', () => {
});
fixture = TestBed.createComponent(StartFormComponent);
component = fixture.componentInstance;
loader = TestbedHarnessEnvironment.loader(fixture);
processService = TestBed.inject(ProcessService);
visibilityService = TestBed.inject(WidgetVisibilityService);
translate = TestBed.inject(TranslateService);
Expand Down Expand Up @@ -243,8 +250,8 @@ describe('StartFormComponent', () => {
const dropdownField = formFields.find((field) => field.id === 'mockTypeDropDown');
const dropdownWidget = fixture.debugElement.nativeElement.querySelector('dropdown-widget');
const dropdownLabel = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget .adf-label');
const selectElement = fixture.debugElement.nativeElement.querySelector('.adf-select .mat-select-trigger');
selectElement.click();
const selectElement = await loader.getHarness(MatSelectHarness);
await selectElement.open();

expect(selectElement).toBeTruthy();
expect(dropdownWidget).toBeTruthy();
Expand Down Expand Up @@ -300,7 +307,7 @@ describe('StartFormComponent', () => {

const formFieldsWidget = fixture.debugElement.nativeElement.querySelector('form-field');
const inputElement = fixture.debugElement.nativeElement.querySelector('.adf-input');
const inputLabelElement = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix > .adf-label');
const inputLabelElement = fixture.debugElement.nativeElement.querySelector('.adf-label');
const dateElement = fixture.debugElement.nativeElement.querySelector('#billdate');
const dateLabelElement = fixture.debugElement.nativeElement.querySelector('#billdate-label');
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
Expand All @@ -322,14 +329,9 @@ describe('StartFormComponent', () => {
component.showOutcomeButtons = true;
component.showRefreshButton = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges();
await fixture.whenStable();

const refreshElement = fixture.debugElement.nativeElement.querySelector('.mat-card-actions>button');
refreshElement.click();

fixture.detectChanges();
await fixture.whenStable();
const refreshElement = await (await loader.getHarness(MatCardHarness)).getHarness(MatButtonHarness);
await refreshElement.click();

/* cspell:disable-next-line */
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
Expand Down Expand Up @@ -370,17 +372,17 @@ describe('StartFormComponent', () => {
fixture.detectChanges();
await fixture.whenStable();

const titleElement = fixture.debugElement.nativeElement.querySelector('mat-card-title>h2');
const actionButtons = fixture.debugElement.nativeElement.querySelectorAll('.mat-button');
const cardTitle = await loader.getHarness(MatCardHarness);
const actionButtons = await loader.getAllHarnesses(MatButtonHarness);

expect(titleElement.innerText.trim()).toEqual('Mock Title');
expect(await cardTitle.getTitleText()).toEqual('Mock Title');
expect(actionButtons.length).toBe(4);
expect(actionButtons[0].innerText.trim()).toBe('SAVE');
expect(actionButtons[0].disabled).toBeFalsy();
expect(actionButtons[1].innerText.trim()).toBe('APPROVE');
expect(actionButtons[1].disabled).toBeTruthy();
expect(actionButtons[2].innerText.trim()).toBe('COMPLETE');
expect(actionButtons[2].disabled).toBeTruthy();
expect(await actionButtons[0].getText()).toBe('SAVE');
expect(await actionButtons[0].isDisabled()).toBeFalsy();
expect(await actionButtons[1].getText()).toBe('APPROVE');
expect(await actionButtons[1].isDisabled()).toBeTruthy();
expect(await actionButtons[2].getText()).toBe('COMPLETE');
expect(await actionButtons[2].isDisabled()).toBeTruthy();
});
});

Expand Down
Loading

0 comments on commit 3bfadae

Please sign in to comment.