Skip to content

Commit

Permalink
NAS-132636: Fix unit tests (Part 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Vasilenko committed Dec 11, 2024
1 parent d957d3f commit 2a9c0b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
15 changes: 6 additions & 9 deletions src/app/directives/ui-search.directive.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<UiSearchableElement>({ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces
readonly canCreateDataset = input(false);
readonly createDatasetProps = input<Omit<DatasetCreate, 'name'>>({});

readonly tree = viewChild<TreeComponent>('tree');
@ViewChild('tree', { static: true }) tree: TreeComponent;

readonly requiredRoles = [Role.DatasetWrite];

Expand All @@ -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<ExplorerNodeData>) => node.data.isMountpoint)
|| !this.tree.treeModel.selectedLeafNodes.every((node: TreeNode<ExplorerNodeData>) => node.data.isMountpoint)
|| this.isDisabled;
}

Expand Down Expand Up @@ -163,7 +163,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces
onNodeSelect(event: { node: TreeNode<ExplorerNodeData> }): void {
if (this.multiple()) {
this.selectTreeNodes([
...Object.keys(this.tree().treeModel.selectedLeafNodeIds),
...Object.keys(this.tree.treeModel.selectedLeafNodeIds),
event.node.id as string,
]);
} else {
Expand All @@ -176,7 +176,7 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces
onNodeDeselect(event: { node: TreeNode<ExplorerNodeData> }): 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([]);
Expand All @@ -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);

Expand Down Expand Up @@ -242,13 +242,13 @@ export class IxExplorerComponent implements OnInit, OnChanges, ControlValueAcces
return;
}

const parentNode = this.tree().treeModel.selectedLeafNodes[0] as TreeNode<ExplorerNodeData>;
const parentNode = this.tree.treeModel.selectedLeafNodes[0] as TreeNode<ExplorerNodeData>;
parentNode?.expand();

this.setInitialNode();
this.writeValue(`${this.root()}/${dataset.name}`);
this.onChange(this.value);
this.tree().treeModel.update();
this.tree.treeModel.update();
});
}

Expand Down Expand Up @@ -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<ExplorerNodeData>): Observable<ExplorerNodeData[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class TargetDetailsComponent {
if (targetId) {
this.getPortByTargetId(targetId);
}
}, { allowSignalWrites: true });
});
}

private getPortByTargetId(id: number): void {
Expand Down

0 comments on commit 2a9c0b1

Please sign in to comment.