File size: 2,046 Bytes
1dbc34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Page, Locator } from '@playwright/test';
import { waitForElement, waitForElementHidden } from '../core/waiting';

/**
 * Check if the category autocomplete dropdown is visible
 */
export async function isCategoryAutocompleteListVisible(page: Page): Promise<boolean> {
  const list = page.locator('[data-testid="category-autocomplete-list"]');
  return await list.isVisible();
}

/**
 * Wait for the category autocomplete dropdown to be visible
 */
export async function waitForCategoryAutocompleteList(
  page: Page,
  options?: { timeout?: number }
): Promise<Locator> {
  return await waitForElement(page, 'category-autocomplete-list', options);
}

/**
 * Wait for the category autocomplete dropdown to be hidden
 */
export async function waitForCategoryAutocompleteListHidden(
  page: Page,
  options?: { timeout?: number }
): Promise<void> {
  await waitForElementHidden(page, 'category-autocomplete-list', options);
}

/**
 * Click a category option in the autocomplete dropdown
 */
export async function clickCategoryOption(page: Page, categoryName: string): Promise<void> {
  const optionTestId = `category-option-${categoryName.toLowerCase().replace(/\s+/g, '-')}`;
  const option = page.locator(`[data-testid="${optionTestId}"]`);
  await option.click();
}

/**
 * Get a category option element by name
 */
export async function getCategoryOption(page: Page, categoryName: string): Promise<Locator> {
  const optionTestId = `category-option-${categoryName.toLowerCase().replace(/\s+/g, '-')}`;
  return page.locator(`[data-testid="${optionTestId}"]`);
}

/**
 * Click the "Create new" option for a category that doesn't exist
 */
export async function clickCreateNewCategoryOption(page: Page): Promise<void> {
  const option = page.locator('[data-testid="category-option-create-new"]');
  await option.click();
}

/**
 * Get the "Create new" option element for categories
 */
export async function getCreateNewCategoryOption(page: Page): Promise<Locator> {
  return page.locator('[data-testid="category-option-create-new"]');
}