@truenas/ui-components 0.1.32 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,13 +17,13 @@ import { TemplatePortal, PortalModule, ComponentPortal } from '@angular/cdk/port
17
17
  import { CdkMenu, CdkMenuItem, CdkMenuTrigger } from '@angular/cdk/menu';
18
18
  import { trigger, state, transition, style, animate } from '@angular/animations';
19
19
  import { SPACE, ENTER, END, HOME, DOWN_ARROW, UP_ARROW, RIGHT_ARROW, LEFT_ARROW } from '@angular/cdk/keycodes';
20
+ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
20
21
  import { DataSource } from '@angular/cdk/collections';
21
22
  import * as i1$3 from '@angular/cdk/tree';
22
23
  import { CdkTree, CdkTreeModule, CdkTreeNode, CDK_TREE_NODE_OUTLET_NODE, CdkTreeNodeOutlet, CdkNestedTreeNode } from '@angular/cdk/tree';
23
24
  export { FlatTreeControl } from '@angular/cdk/tree';
24
25
  import { map } from 'rxjs/operators';
25
26
  import { DialogRef, DIALOG_DATA, Dialog } from '@angular/cdk/dialog';
26
- import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
27
27
  import { ScrollingModule } from '@angular/cdk/scrolling';
28
28
 
29
29
  let nextId = 0;
@@ -4010,6 +4010,190 @@ class TnTabsHarness extends ComponentHarness {
4010
4010
  }
4011
4011
  }
4012
4012
 
4013
+ /**
4014
+ * Harness for a single menu item (`button.tn-menu-item`).
4015
+ * @internal Used by TnMenuHarness to interact with individual items.
4016
+ */
4017
+ class TnMenuItemHarness extends ComponentHarness {
4018
+ static hostSelector = '.tn-menu-item';
4019
+ _label = this.locatorFor('.tn-menu-item-label');
4020
+ /** Gets the label text of this menu item. */
4021
+ async getLabel() {
4022
+ const label = await this._label();
4023
+ return (await label.text()).trim();
4024
+ }
4025
+ /** Checks whether this menu item is disabled via the native `disabled` attribute. */
4026
+ async isDisabled() {
4027
+ const host = await this.host();
4028
+ const disabled = await host.getProperty('disabled');
4029
+ return !!disabled;
4030
+ }
4031
+ /** Clicks this menu item. */
4032
+ async click() {
4033
+ const host = await this.host();
4034
+ await host.click();
4035
+ }
4036
+ }
4037
+ /**
4038
+ * Harness for interacting with `tn-menu` in tests.
4039
+ *
4040
+ * Menus render in a CDK overlay **outside** the component tree, so a regular
4041
+ * `TestbedHarnessEnvironment.loader(fixture)` won't find them. Use
4042
+ * `TnMenuTesting.rootLoader(fixture)` instead — it searches the entire document.
4043
+ *
4044
+ * ## Test Setup
4045
+ *
4046
+ * ```typescript
4047
+ * import {
4048
+ * TnMenuHarness,
4049
+ * TnMenuTesting,
4050
+ * TnIconButtonHarness,
4051
+ * } from '@truenas/ui-components';
4052
+ *
4053
+ * let loader: HarnessLoader; // for components
4054
+ * let rootLoader: HarnessLoader; // for overlays (menus, dialogs)
4055
+ *
4056
+ * beforeEach(() => {
4057
+ * spectator = createComponent();
4058
+ * loader = TestbedHarnessEnvironment.loader(spectator.fixture);
4059
+ * rootLoader = TnMenuTesting.rootLoader(spectator.fixture);
4060
+ * });
4061
+ * ```
4062
+ *
4063
+ * ## Opening a Menu
4064
+ *
4065
+ * Click the trigger element to open the menu before querying it:
4066
+ *
4067
+ * ```typescript
4068
+ * // Via harness (if trigger is a tn-icon-button)
4069
+ * const trigger = await loader.getHarness(
4070
+ * TnIconButtonHarness.with({ name: 'more_vert' })
4071
+ * );
4072
+ * await trigger.click();
4073
+ *
4074
+ * // Or via DOM
4075
+ * spectator.click('[tnMenuTriggerFor]');
4076
+ * ```
4077
+ *
4078
+ * ## Querying and Clicking Items
4079
+ *
4080
+ * ```typescript
4081
+ * const menu = await rootLoader.getHarness(TnMenuHarness);
4082
+ * expect(await menu.getItemLabels()).toEqual(['Edit', 'Delete']);
4083
+ * await menu.clickItem({ label: 'Edit' });
4084
+ * await menu.clickItem({ label: /del/i }); // regex match
4085
+ * expect(await menu.isItemDisabled({ label: 'Delete' })).toBe(false);
4086
+ * ```
4087
+ */
4088
+ class TnMenuHarness extends ComponentHarness {
4089
+ static hostSelector = '.tn-menu';
4090
+ _items = this.locatorForAll(TnMenuItemHarness);
4091
+ /**
4092
+ * Gets a `HarnessPredicate` that can be used to search for a menu.
4093
+ */
4094
+ static with(options = {}) {
4095
+ return new HarnessPredicate(TnMenuHarness, options);
4096
+ }
4097
+ /**
4098
+ * Gets the labels of all menu items.
4099
+ *
4100
+ * @example
4101
+ * ```typescript
4102
+ * const menu = await rootLoader.getHarness(TnMenuHarness);
4103
+ * expect(await menu.getItemLabels()).toEqual(['Edit', 'Delete']);
4104
+ * ```
4105
+ */
4106
+ async getItemLabels() {
4107
+ const items = await this._items();
4108
+ return Promise.all(items.map(item => item.getLabel()));
4109
+ }
4110
+ /**
4111
+ * Clicks a menu item by its label text.
4112
+ *
4113
+ * @param filter Object with `label` to match (string or RegExp).
4114
+ *
4115
+ * @example
4116
+ * ```typescript
4117
+ * const menu = await rootLoader.getHarness(TnMenuHarness);
4118
+ * await menu.clickItem({ label: 'Delete' });
4119
+ * ```
4120
+ */
4121
+ async clickItem(filter) {
4122
+ const items = await this._items();
4123
+ for (const item of items) {
4124
+ const text = await item.getLabel();
4125
+ const matches = filter.label instanceof RegExp
4126
+ ? filter.label.test(text)
4127
+ : text === filter.label;
4128
+ if (matches) {
4129
+ await item.click();
4130
+ return;
4131
+ }
4132
+ }
4133
+ throw new Error(`Could not find menu item matching label "${String(filter.label)}"`);
4134
+ }
4135
+ /**
4136
+ * Checks if a menu item is disabled.
4137
+ *
4138
+ * @param filter Object with `label` to match (string or RegExp).
4139
+ * @returns Promise resolving to true if the item is disabled.
4140
+ *
4141
+ * @example
4142
+ * ```typescript
4143
+ * const menu = await rootLoader.getHarness(TnMenuHarness);
4144
+ * expect(await menu.isItemDisabled({ label: 'Delete' })).toBe(true);
4145
+ * ```
4146
+ */
4147
+ async isItemDisabled(filter) {
4148
+ const items = await this._items();
4149
+ for (const item of items) {
4150
+ const text = await item.getLabel();
4151
+ const matches = filter.label instanceof RegExp
4152
+ ? filter.label.test(text)
4153
+ : text === filter.label;
4154
+ if (matches) {
4155
+ return item.isDisabled();
4156
+ }
4157
+ }
4158
+ throw new Error(`Could not find menu item with label "${String(filter.label)}"`);
4159
+ }
4160
+ /**
4161
+ * Gets the number of menu items (excluding separators).
4162
+ */
4163
+ async getItemCount() {
4164
+ return (await this._items()).length;
4165
+ }
4166
+ }
4167
+
4168
+ /**
4169
+ * Test utilities for TnMenu.
4170
+ *
4171
+ * Provides a document-root `HarnessLoader` that can find menus rendered
4172
+ * in CDK overlays. Use this alongside `TnDialogTesting.rootLoader()` if
4173
+ * your tests also open dialogs.
4174
+ *
4175
+ * @example
4176
+ * ```typescript
4177
+ * import { TnMenuTesting, TnMenuHarness } from '@truenas/ui-components';
4178
+ *
4179
+ * const rootLoader = TnMenuTesting.rootLoader(spectator.fixture);
4180
+ *
4181
+ * // Open the menu trigger, then query the overlay
4182
+ * spectator.click('[tnMenuTriggerFor]');
4183
+ * const menu = await rootLoader.getHarness(TnMenuHarness);
4184
+ * await menu.clickItem({ label: 'Edit' });
4185
+ * ```
4186
+ */
4187
+ class TnMenuTesting {
4188
+ /**
4189
+ * Creates a `HarnessLoader` that searches the entire document,
4190
+ * including CDK overlays where menus are rendered.
4191
+ */
4192
+ static rootLoader(fixture) {
4193
+ return TestbedHarnessEnvironment.documentRootLoader(fixture);
4194
+ }
4195
+ }
4196
+
4013
4197
  class TnKeyboardShortcutComponent {
4014
4198
  shortcut = input('', ...(ngDevMode ? [{ debugName: "shortcut" }] : []));
4015
4199
  platform = input('auto', ...(ngDevMode ? [{ debugName: "platform" }] : []));
@@ -11361,5 +11545,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImpor
11361
11545
  * Generated bundle index. Do not edit.
11362
11546
  */
11363
11547
 
11364
- export { CommonShortcuts, DEFAULT_THEME, DiskIconComponent, DiskType, FileSizePipe, InputType, LIGHT_THEME, LinuxModifierKeys, LinuxShortcuts, ModifierKeys, QuickShortcuts, ShortcutBuilder, StripMntPrefixPipe, THEME_MAP, THEME_STORAGE_KEY, TN_THEME_DEFINITIONS, TnAutocompleteComponent, TnAutocompleteHarness, TnBannerActionDirective, TnBannerComponent, TnBannerHarness, TnBrandedSpinnerComponent, TnButtonComponent, TnButtonHarness, TnButtonToggleComponent, TnButtonToggleGroupComponent, TnCalendarComponent, TnCalendarHeaderComponent, TnCardComponent, TnCellDefDirective, TnCheckboxComponent, TnCheckboxHarness, TnCheckboxLabelDirective, TnChipComponent, TnConfirmDialogComponent, TnDateInputComponent, TnDateRangeInputComponent, TnDialog, TnDialogHarness, TnDialogShellComponent, TnDialogTesting, TnDividerComponent, TnDividerDirective, TnDrawerComponent, TnDrawerContainerComponent, TnDrawerContainerHarness, TnDrawerContentComponent, TnDrawerHarness, TnEmptyComponent, TnEmptyHarness, TnExpansionPanelComponent, TnFilePickerComponent, TnFilePickerPopupComponent, TnFormFieldComponent, TnFormFieldHarness, TnHeaderCellDefDirective, TnIconButtonComponent, TnIconButtonHarness, TnIconComponent, TnIconHarness, TnIconRegistryService, TnIconTesting, TnInputComponent, TnInputDirective, TnInputHarness, TnKeyboardShortcutComponent, TnKeyboardShortcutService, TnListAvatarDirective, TnListComponent, TnListIconDirective, TnListItemComponent, TnListItemLineDirective, TnListItemPrimaryDirective, TnListItemSecondaryDirective, TnListItemTitleDirective, TnListItemTrailingDirective, TnListOptionComponent, TnListSubheaderComponent, TnMenuActivateHoverDirective, TnMenuComponent, TnMenuTriggerDirective, TnMonthViewComponent, TnMultiYearViewComponent, TnNestedTreeNodeComponent, TnParticleProgressBarComponent, TnProgressBarComponent, TnRadioComponent, TnSelectComponent, TnSelectHarness, TnSelectionListComponent, TnSidePanelActionDirective, TnSidePanelComponent, TnSidePanelHarness, TnSidePanelHeaderActionDirective, TnSlideToggleComponent, TnSliderComponent, TnSliderThumbDirective, TnSliderWithLabelDirective, TnSpinnerComponent, TnSpriteLoaderService, TnStepComponent, TnStepperComponent, TnTabComponent, TnTabHarness, TnTabPanelComponent, TnTabPanelHarness, TnTableColumnDirective, TnTableComponent, TnTabsComponent, TnTabsHarness, TnTheme, TnThemeService, TnTimeInputComponent, TnToastComponent, TnToastMock, TnToastPosition, TnToastRef, TnToastService, TnToastTesting, TnToastType, TnTooltipComponent, TnTooltipDirective, TnTreeComponent, TnTreeFlatDataSource, TnTreeFlattener, TnTreeNodeComponent, TnTreeNodeOutletDirective, TruncatePathPipe, WindowsModifierKeys, WindowsShortcuts, createLucideLibrary, createShortcut, defaultSpriteBasePath, defaultSpriteConfigPath, libIconMarker, registerLucideIcons, setupLucideIntegration, tnIconMarker };
11548
+ export { CommonShortcuts, DEFAULT_THEME, DiskIconComponent, DiskType, FileSizePipe, InputType, LIGHT_THEME, LinuxModifierKeys, LinuxShortcuts, ModifierKeys, QuickShortcuts, ShortcutBuilder, StripMntPrefixPipe, THEME_MAP, THEME_STORAGE_KEY, TN_THEME_DEFINITIONS, TnAutocompleteComponent, TnAutocompleteHarness, TnBannerActionDirective, TnBannerComponent, TnBannerHarness, TnBrandedSpinnerComponent, TnButtonComponent, TnButtonHarness, TnButtonToggleComponent, TnButtonToggleGroupComponent, TnCalendarComponent, TnCalendarHeaderComponent, TnCardComponent, TnCellDefDirective, TnCheckboxComponent, TnCheckboxHarness, TnCheckboxLabelDirective, TnChipComponent, TnConfirmDialogComponent, TnDateInputComponent, TnDateRangeInputComponent, TnDialog, TnDialogHarness, TnDialogShellComponent, TnDialogTesting, TnDividerComponent, TnDividerDirective, TnDrawerComponent, TnDrawerContainerComponent, TnDrawerContainerHarness, TnDrawerContentComponent, TnDrawerHarness, TnEmptyComponent, TnEmptyHarness, TnExpansionPanelComponent, TnFilePickerComponent, TnFilePickerPopupComponent, TnFormFieldComponent, TnFormFieldHarness, TnHeaderCellDefDirective, TnIconButtonComponent, TnIconButtonHarness, TnIconComponent, TnIconHarness, TnIconRegistryService, TnIconTesting, TnInputComponent, TnInputDirective, TnInputHarness, TnKeyboardShortcutComponent, TnKeyboardShortcutService, TnListAvatarDirective, TnListComponent, TnListIconDirective, TnListItemComponent, TnListItemLineDirective, TnListItemPrimaryDirective, TnListItemSecondaryDirective, TnListItemTitleDirective, TnListItemTrailingDirective, TnListOptionComponent, TnListSubheaderComponent, TnMenuActivateHoverDirective, TnMenuComponent, TnMenuHarness, TnMenuTesting, TnMenuTriggerDirective, TnMonthViewComponent, TnMultiYearViewComponent, TnNestedTreeNodeComponent, TnParticleProgressBarComponent, TnProgressBarComponent, TnRadioComponent, TnSelectComponent, TnSelectHarness, TnSelectionListComponent, TnSidePanelActionDirective, TnSidePanelComponent, TnSidePanelHarness, TnSidePanelHeaderActionDirective, TnSlideToggleComponent, TnSliderComponent, TnSliderThumbDirective, TnSliderWithLabelDirective, TnSpinnerComponent, TnSpriteLoaderService, TnStepComponent, TnStepperComponent, TnTabComponent, TnTabHarness, TnTabPanelComponent, TnTabPanelHarness, TnTableColumnDirective, TnTableComponent, TnTabsComponent, TnTabsHarness, TnTheme, TnThemeService, TnTimeInputComponent, TnToastComponent, TnToastMock, TnToastPosition, TnToastRef, TnToastService, TnToastTesting, TnToastType, TnTooltipComponent, TnTooltipDirective, TnTreeComponent, TnTreeFlatDataSource, TnTreeFlattener, TnTreeNodeComponent, TnTreeNodeOutletDirective, TruncatePathPipe, WindowsModifierKeys, WindowsShortcuts, createLucideLibrary, createShortcut, defaultSpriteBasePath, defaultSpriteConfigPath, libIconMarker, registerLucideIcons, setupLucideIntegration, tnIconMarker };
11365
11549
  //# sourceMappingURL=truenas-ui-components.mjs.map