# Filter Tests Review Hints

## Overview
This document provides guidance for reviewing and implementing filter-related test cases in the Halo QA application. Tests cover date filters, comparison filters, and property filters.

## Test Structure

### Standard Setup
```typescript
import { test, expect } from '@playwright/test';
import { LoginPage } from '../../../../pages/login.page';
import { DashboardMainPage } from '../../../../pages/dashboard-main.page';
import * as dotenv from 'dotenv';

dotenv.config();

test.setTimeout(10 * 60 * 1000);

test('@filters Test description', async ({ page }) => {
  const loginPage = new LoginPage(page);
  const dashboardPage = new DashboardMainPage(page);

  const testEmail = process.env.TEST_EMAIL || 'cdp@hy.ly';
  const testPassword = process.env.TEST_PASSWORD || 'BMy2L1rRXZlkKoTU7';
});
```

## Filter Categories

### 1. Date Range Filters
Available date filters:
- This Week
- Last Week
- This Month
- Last Month
- This Quarter
- Last Quarter
- This Year
- Last Year
- Last 4 Weeks
- Last 13 Weeks

```typescript
// Date filter selection pattern
await test.step('Apply date filter', async () => {
  await dashboardPage.openDateFilter();
  await dashboardPage.selectDateRange('Last 4 Weeks');
  await dashboardPage.waitForFilterApplied();
});
```

### 2. Comparison Filters
Available comparison types:
- None
- Previous Period
- Previous Year

```typescript
// Comparison filter pattern
await test.step('Apply comparison filter', async () => {
  await dashboardPage.openComparisonFilter();
  await dashboardPage.selectComparison('Previous Period');
  await dashboardPage.waitForFilterApplied();
});
```

### 3. Property Filters
Property filter types:
- Single property
- Multiple properties
- Select all properties
- No property
- Nested properties

```typescript
// Property filter patterns
await test.step('Apply property filter', async () => {
  await dashboardPage.openPropertyFilter();
  
  // Single property
  await dashboardPage.selectProperty('Property Name');
  
  // Multiple properties
  await dashboardPage.selectProperties(['Property 1', 'Property 2']);
  
  // Select all
  await dashboardPage.selectAllProperties();
  
  // Nested properties
  await dashboardPage.expandPropertyGroup('Group Name');
  await dashboardPage.selectNestedProperty('Subgroup', 'Property Name');
});
```

## Verification Patterns

### 1. Date Filter Verification
```typescript
await test.step('Verify date filter', async () => {
  const selectedRange = await dashboardPage.getSelectedDateRange();
  expect(selectedRange).toBe('Last 4 Weeks');
  
  const dateRangeText = await dashboardPage.getDateRangeText();
  expect(dateRangeText).toMatch(/\d{2}\/\d{2}\/\d{4} - \d{2}\/\d{2}\/\d{4}/);
});
```

### 2. Comparison Filter Verification
```typescript
await test.step('Verify comparison filter', async () => {
  const selectedComparison = await dashboardPage.getSelectedComparison();
  expect(selectedComparison).toBe('Previous Period');
  
  const hasComparisonData = await dashboardPage.verifyComparisonData();
  expect(hasComparisonData).toBeTruthy();
});
```

### 3. Property Filter Verification
```typescript
await test.step('Verify property filter', async () => {
  const selectedProperties = await dashboardPage.getSelectedProperties();
  expect(selectedProperties).toContain('Property Name');
  
  const propertyCount = await dashboardPage.getSelectedPropertyCount();
  expect(propertyCount).toBeGreaterThan(0);
});
```

## Common Wait Patterns

### Filter Application Waits
```typescript
// Wait for filter dropdown to open
await page.waitForSelector('.filter-dropdown', { state: 'visible' });

// Wait for filter to be applied
await page.waitForSelector('.loading-indicator', { state: 'hidden' });
await page.waitForTimeout(2000); // Stability wait

// Wait for data refresh
await dashboardPage.waitForDataRefresh();
```

## Error Handling

### Filter Error Patterns
```typescript
// Handle filter application errors
try {
  await dashboardPage.applyFilter();
} catch (error) {
  console.error(`Failed to apply filter: ${error}`);
  
  // Check for specific error states
  const errorMessage = await page.locator('.error-message').textContent();
  if (errorMessage?.includes('No data available')) {
    // Handle no data case
  }
  throw error;
}
```

## Test Coverage Checklist

### Required Test Cases
1. ✅ Date Range Filters
   - Each predefined range (This Week, Last Week, etc.)
   - Range calculations accuracy
   - Date display format

2. ✅ Comparison Filters
   - None/Previous Period/Previous Year options
   - Comparison data accuracy
   - Visual indicators for comparison

3. ✅ Property Filters
   - Single/Multiple selection
   - Select All functionality
   - Nested property handling
   - Property count display

4. ✅ Filter Combinations
   - Date + Comparison
   - Date + Properties
   - All three combined

5. ✅ Edge Cases
   - No properties selected
   - Invalid date ranges
   - Large property lists