From 2a9c0b1da518d15c4af594dce776851c4a472ea3 Mon Sep 17 00:00:00 2001 From: Boris Vasilenko Date: Wed, 11 Dec 2024 20:03:18 +0300 Subject: [PATCH] NAS-132636: Fix unit tests (Part 3) --- src/app/directives/ui-search.directive.ts | 15 ++++++-------- .../ix-explorer/ix-explorer.component.ts | 20 +++++++++---------- .../target-details.component.ts | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/app/directives/ui-search.directive.ts b/src/app/directives/ui-search.directive.ts index 18b3e586afe..84f916489cc 100644 --- a/src/app/directives/ui-search.directive.ts +++ b/src/app/directives/ui-search.directive.ts @@ -1,7 +1,6 @@ import { - Directive, ElementRef, Renderer2, OnInit, + Directive, Input, ElementRef, Renderer2, OnInit, OnDestroy, - input, } from '@angular/core'; import { Timeout } from 'app/interfaces/timeout.interface'; import { searchDelayConst } from 'app/modules/global-search/constants/delay.const'; @@ -14,20 +13,18 @@ import { UiSearchDirectivesService } from 'app/modules/global-search/services/ui standalone: true, }) export class UiSearchDirective implements OnInit, OnDestroy { - readonly config = input.required({ alias: 'ixUiSearch' }); + @Input({ required: true, alias: 'ixUiSearch' }) config: UiSearchableElement; get id(): string { - return getSearchableElementId(this.config()); + return getSearchableElementId(this.config); } get ariaLabel(): string { - const config = this.config(); - const hierarchyItem = config.hierarchy?.[config.hierarchy.length - 1] || ''; + const hierarchyItem = this.config.hierarchy?.[this.config.hierarchy.length - 1] || ''; const isSingleWord = hierarchyItem.trim().split(/\s+/).length === 1; - const configValue = this.config(); - if (isSingleWord && configValue.synonyms?.length > 0) { - return configValue.synonyms.reduce((best, synonym) => { + if (isSingleWord && this.config.synonyms?.length > 0) { + return this.config.synonyms.reduce((best, synonym) => { const synonymWordCount = synonym.trim().split(/\s+/).length; const bestWordCount = best.trim().split(/\s+/).length; return synonymWordCount > bestWordCount ? synonym : best; diff --git a/src/app/modules/forms/ix-forms/components/ix-explorer/ix-explorer.component.ts b/src/app/modules/forms/ix-forms/components/ix-explorer/ix-explorer.component.ts index 0fc22f5336b..85b976fed01 100644 --- a/src/app/modules/forms/ix-forms/components/ix-explorer/ix-explorer.component.ts +++ b/src/app/modules/forms/ix-forms/components/ix-explorer/ix-explorer.component.ts @@ -4,7 +4,7 @@ import { Component, input, OnChanges, OnInit, - viewChild, + ViewChild, } from '@angular/core'; import { ControlValueAccessor, NgControl } from '@angular/forms'; import { MatButton } from '@angular/material/button'; @@ -70,7 +70,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces readonly canCreateDataset = input(false); readonly createDatasetProps = input>({}); - readonly tree = viewChild('tree'); + @ViewChild('tree', { static: true }) tree: TreeComponent; readonly requiredRoles = [Role.DatasetWrite]; @@ -87,7 +87,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces get createDatasetDisabled(): boolean { return !this.parentDatasetName(Array.isArray(this.value) ? this.value[0] : this.value).length - || !this.tree().treeModel.selectedLeafNodes.every((node: TreeNode) => node.data.isMountpoint) + || !this.tree.treeModel.selectedLeafNodes.every((node: TreeNode) => node.data.isMountpoint) || this.isDisabled; } @@ -163,7 +163,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces onNodeSelect(event: { node: TreeNode }): void { if (this.multiple()) { this.selectTreeNodes([ - ...Object.keys(this.tree().treeModel.selectedLeafNodeIds), + ...Object.keys(this.tree.treeModel.selectedLeafNodeIds), event.node.id as string, ]); } else { @@ -176,7 +176,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces onNodeDeselect(event: { node: TreeNode }): void { if (this.multiple()) { this.selectTreeNodes( - Object.keys(this.tree().treeModel.selectedLeafNodeIds).filter((node) => node !== event.node.id), + Object.keys(this.tree.treeModel.selectedLeafNodeIds).filter((node) => node !== event.node.id), ); } else { this.selectTreeNodes([]); @@ -197,7 +197,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces } onSelectionChanged(): void { - let newValue: string[] | string = Object.entries(this.tree().treeModel.selectedLeafNodeIds) + let newValue: string[] | string = Object.entries(this.tree.treeModel.selectedLeafNodeIds) .filter(([, isSelected]) => isSelected) .map(([nodeId]) => nodeId); @@ -242,13 +242,13 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces return; } - const parentNode = this.tree().treeModel.selectedLeafNodes[0] as TreeNode; + const parentNode = this.tree.treeModel.selectedLeafNodes[0] as TreeNode; parentNode?.expand(); this.setInitialNode(); this.writeValue(`${this.root()}/${dataset.name}`); this.onChange(this.value); - this.tree().treeModel.update(); + this.tree.treeModel.update(); }); } @@ -277,11 +277,11 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces private selectTreeNodes(nodeIds: string[]): void { const treeState = { - ...this.tree().treeModel.getState(), + ...this.tree.treeModel.getState(), selectedLeafNodeIds: nodeIds.reduce((acc, nodeId) => ({ ...acc, [nodeId]: true }), {}), }; - this.tree().treeModel.setState(treeState); + this.tree.treeModel.setState(treeState); } private loadChildren(node: TreeNode): Observable { diff --git a/src/app/pages/sharing/iscsi/target/all-targets/target-details/target-details.component.ts b/src/app/pages/sharing/iscsi/target/all-targets/target-details/target-details.component.ts index 7d8720b1020..590810ba633 100644 --- a/src/app/pages/sharing/iscsi/target/all-targets/target-details/target-details.component.ts +++ b/src/app/pages/sharing/iscsi/target/all-targets/target-details/target-details.component.ts @@ -51,7 +51,7 @@ export class TargetDetailsComponent { if (targetId) { this.getPortByTargetId(targetId); } - }, { allowSignalWrites: true }); + }); } private getPortByTargetId(id: number): void {