[ACS-7368] Fix unit tests for aca-content (#3779)

This commit is contained in:
dominikiwanekhyland
2024-04-10 09:05:22 +02:00
committed by MichalKinas
parent 7013ab0f00
commit 968d25ef49
16 changed files with 21 additions and 156 deletions

View File

@@ -29,21 +29,5 @@ import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
<T>(id: string): T;
keys(): string[];
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().forEach(context);

86
package-lock.json generated
View File

@@ -86,7 +86,6 @@
"karma": "^6.4.3",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "^2.2.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-mocha-reporter": "^2.2.5",
@@ -20713,90 +20712,6 @@
"node": ">=10.0.0"
}
},
"node_modules/karma-coverage-istanbul-reporter": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/karma-coverage-istanbul-reporter/-/karma-coverage-istanbul-reporter-3.0.3.tgz",
"integrity": "sha512-wE4VFhG/QZv2Y4CdAYWDbMmcAHeS926ZIji4z+FkB2aF/EposRb6DP6G5ncT/wXhqUfAb/d7kZrNKPonbvsATw==",
"dev": true,
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-report": "^3.0.0",
"istanbul-lib-source-maps": "^3.0.6",
"istanbul-reports": "^3.0.2",
"minimatch": "^3.0.4"
},
"funding": {
"url": "https://github.com/sponsors/mattlewis92"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/istanbul-lib-source-maps": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.6.tgz",
"integrity": "sha512-R47KzMtDJH6X4/YW9XTx+jrLnZnscW4VpNN+1PViSYTejLVPWv7oov+Duf8YQSPyVRUvueQqz1TcsC6mooZTXw==",
"dev": true,
"dependencies": {
"debug": "^4.1.1",
"istanbul-lib-coverage": "^2.0.5",
"make-dir": "^2.1.0",
"rimraf": "^2.6.3",
"source-map": "^0.6.1"
},
"engines": {
"node": ">=6"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/istanbul-lib-source-maps/node_modules/istanbul-lib-coverage": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz",
"integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/make-dir": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",
"integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==",
"dev": true,
"dependencies": {
"pify": "^4.0.1",
"semver": "^5.6.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/rimraf": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"dev": true,
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
"dev": true,
"bin": {
"semver": "bin/semver"
}
},
"node_modules/karma-coverage-istanbul-reporter/node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/karma-jasmine": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.1.0.tgz",
@@ -25334,6 +25249,7 @@
"resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
"integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==",
"dev": true,
"optional": true,
"engines": {
"node": ">=6"
}

View File

@@ -110,7 +110,6 @@
"karma": "^6.4.3",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "^2.2.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-mocha-reporter": "^2.2.5",

View File

@@ -317,7 +317,7 @@ describe('ManageRulesSmartComponent', () => {
fixture.detectChanges();
const createButton = await loader.getHarness(
MatSlideToggleHarness.with({ selector: `[data-automation-id="manage-rules-inheritance-toggle-button"]` })
MatSlideToggleHarness.with({ selector: `[data-automation-id="manage-rules-inheritance-toggle-button"] button` })
);
expect(createButton).toBeTruthy();

View File

@@ -27,7 +27,7 @@ import { RuleSimpleConditionUiComponent } from './rule-simple-condition.ui-compo
import { CoreTestingModule } from '@alfresco/adf-core';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { tagMock, mimeTypeMock, simpleConditionUnknownFieldMock, categoriesListMock } from '../../mock/conditions.mock';
import { categoriesListMock, mimeTypeMock, simpleConditionUnknownFieldMock, tagMock } from '../../mock/conditions.mock';
import { MimeType } from './rule-mime-types';
import { CategoryService, TagService } from '@alfresco/adf-content-services';
import { of } from 'rxjs';

View File

@@ -12,14 +12,14 @@
data-automation-id="rule-option-form-field-errorScript"
floatLabel="always"
[ngClass]="{ 'aca-hide-error-script-dropdown': hideErrorScriptDropdown }">
<mat-label>{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.ERROR_SCRIPT' | translate }}</mat-label>
<mat-select
formControlName="errorScript"
placeholder="{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.ERROR_SCRIPT' | translate}}"
data-automation-id="rule-option-select-errorScript">
<mat-option value="">{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.NO_SCRIPT' | translate }}</mat-option>
<mat-option class="aca-rule-options__error-script-option" value="">{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.NO_SCRIPT' | translate }}</mat-option>
<mat-option *ngFor="let option of errorScriptOptions"
class="aca-rule-options__error-script-option"
[value]="option.value">
{{ option.label }}
</mat-option>

View File

@@ -43,7 +43,7 @@ describe('RuleOptionsUiComponent', () => {
fixture.debugElement.query(By.css(`[data-automation-id="${dataAutomationId}"]`));
const toggleMatCheckbox = (dataAutomationId: string) => {
((getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).children[0] as HTMLElement).click();
(getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).querySelector('input').click();
};
const testErrorScriptFormFieldVisibility = (isVisible: boolean) => {
@@ -153,7 +153,7 @@ describe('RuleOptionsUiComponent', () => {
expect((await matOptions[2].getText()).trim()).toBe('Script 2');
});
it('should always show a label for the error script dropdown even when MAT_FORM_FIELD_DEFAULT_OPTIONS sets floatLabel to auto', () => {
it('should always show a label for the error script dropdown', () => {
component.writeValue({
isEnabled: true,
isInheritable: false,

View File

@@ -36,7 +36,7 @@ describe('RuleTriggerUiComponent', () => {
fixture.debugElement.query(By.css(`[data-automation-id="${dataAutomationId}"]`));
const toggleMatCheckbox = (dataAutomationId: string) => {
((getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).children[0] as HTMLElement).click();
(getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).querySelector('input').click();
};
beforeEach(() => {

View File

@@ -28,7 +28,10 @@
"main": "projects/aca-content/test.ts",
"tsConfig": "projects/aca-content/tsconfig.spec.json",
"karmaConfig": "projects/aca-content/karma.conf.js",
"styles": ["projects/aca-content/src/lib/ui/application.scss"]
"styles": ["projects/aca-content/src/lib/ui/application.scss"],
"stylePreprocessorOptions": {
"includePaths": ["projects/aca-content/src/lib/ui", "node_modules", "node_modules/@alfresco/adf-core/lib"]
}
},
"configurations": {
"adfprod": {

View File

@@ -3,7 +3,7 @@
<ng-container *ngSwitchCase="'menu'">
<button mat-menu-item [id]="actionRef.id" [matMenuTriggerFor]="childMenu">
<adf-icon [value]="actionRef.icon"></adf-icon>
<span>{{ actionRef.title | translate }}</span>
<span [attr.data-automation-id]="actionRef.id + '-label'">{{ actionRef.title | translate }}</span>
</button>
<mat-menu #childMenu="matMenu">
@@ -24,7 +24,7 @@
<ng-container *ngSwitchDefault>
<button mat-menu-item color="primary" [id]="actionRef.id" (click)="runAction()">
<adf-icon [value]="actionRef.icon"></adf-icon>
<span>{{ actionRef.title | translate }}</span>
<span [attr.data-automation-id]="actionRef.id + '-label'">{{ actionRef.title | translate }}</span>
</button>
</ng-container>
</ng-container>

View File

@@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContextMenuItemComponent } from './context-menu-item.component';
import { AppExtensionService } from '@alfresco/aca-shared';
@@ -62,7 +62,7 @@ describe('ContextMenuComponent', () => {
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector('button');
expect(buttonElement.querySelector('span').innerText.trim()).toBe(contextItem.title);
expect(buttonElement.querySelector('[data-automation-id="action-button-label"]').innerText.trim()).toBe(contextItem.title);
});
it('should not run action when entry has no click attribute defined', () => {

View File

@@ -6,7 +6,7 @@
<ng-container *ngSwitchDefault>
<button mat-menu-item [id]="entry.id" (click)="runAction(entry)">
<adf-icon [value]="entry.icon"></adf-icon>
<span>{{ entry.title | translate }}</span>
<span [attr.data-automation-id]="entry.id + '-label'">{{ entry.title | translate }}</span>
</button>
</ng-container>
@@ -17,7 +17,7 @@
<ng-container *ngSwitchCase="'menu'">
<button mat-menu-item [id]="entry.id" [matMenuTriggerFor]="childMenu">
<adf-icon [value]="entry.icon"></adf-icon>
<span>{{ entry.title | translate }}</span>
<span [attr.data-automation-id]="entry.id + '-label'">{{ entry.title | translate }}</span>
</button>
<mat-menu #childMenu="matMenu">

View File

@@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContextMenuComponent } from './context-menu.component';
import { ContextMenuOverlayRef } from './context-menu-overlay';
@@ -91,7 +91,7 @@ describe('ContextMenuComponent', () => {
const contextMenuElements = document.body.querySelector('.aca-context-menu')?.querySelectorAll('button');
expect(contextMenuElements?.length).toBe(1);
expect(contextMenuElements?.[0].querySelector('span')?.innerText).toBe(contextItem.title);
expect((contextMenuElements?.[0].querySelector('[data-automation-id="action-button-label"]') as HTMLElement)?.innerText).toBe(contextItem.title);
});
it('should run action with provided action id and correct payload', () => {

View File

@@ -29,22 +29,7 @@ import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
});
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().forEach(context);

View File

@@ -29,21 +29,5 @@ import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
<T>(id: string): T;
keys(): string[];
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().forEach(context);

View File

@@ -29,13 +29,7 @@ import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
});
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);