Skip to content

[Query Builder] Refactor, bug fixing and test coverage improved - #17706

Draft
ivanvpetrov wants to merge 13 commits into
masterfrom
ipetrov/query-builder-coverage
Draft

ivanvpetrov wants to merge 13 commits into
masterfrom
ipetrov/query-builder-coverage

Conversation

@ivanvpetrov

@ivanvpetrov ivanvpetrov commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Raises Query Builder unit test coverage from 88.7% to ~98.4% (lines).
  • Fixes several bugs that ware exposed during refactor. Added test for them.
  • Removes dead code.

Fixes

  • Keyboard drag: pressing Space did nothing, because the listener checked for 'Space' while the browser reports ' '. Pressing Space or Enter before choosing a drop location deleted the dragged expression. Both keys now drop only once a drop ghost is shown.
  • During Keyboard drag:, ArrowUp/ArrowDown and the Space/Enter key that drops now call preventDefault() (held keys included), so the page/container no longer scrolls.
  • During Keyboard drag:, Tab and Shift+Tab are ignored while the drop ghost is shown, so focus stays on it until the condition is dropped (Enter/Space) or the drag is cancelled (Escape). Previously they cancelled the drag and focus was lost.
  • Mouse drag + keyboard: while a chip is held with the mouse and its drop ghost is shown, tabbing to another chip's drag indicator let ArrowUp/ArrowDown move the drop ghost without moving the mouse, and Space/Enter drop the mouse-dragged chip there. Added a guard that prevents keyboard drag while a mouse drag is in progress.
  • Time fields: selecting a time field without editorOptions threw an error (editorOptions!.dateTimeFormat, now ?.).

Unreachable code removed (all private/protected/@hidden @internal; IgxQueryBuilderTreeComponent is not exported):

  • Unused getters (editingInputsContainer, currentGroupButtonsContainer), endGroup(), onKeyDown()
  • addRootAndGroupButton @ViewChild, whose template ref no longer exists (setAddButtonFocus keeps its behavior)
  • _expandedExpressions, which was never written to
  • String handling for _selectedReturnFields, which is always an array; the type is narrowed to string[]
  • The unreachable 'wrong key' branch in arrowDrag; the key is typed as 'ArrowUp' | 'ArrowDown'

Tests

  • New specs for: add-menu flows (add group, add-mode transitions, nested query), focus/blur, return fields, time/dateTime/currency/percent/untyped fields, an entity without fields, return-field chip text, commit()/setAddButtonFocus(), the drag service (no-op events, re-targeting, release outside a drop area, focus-out cancel, focus moving to the drop ghost), AND/OR switch before the first commit, and resource strings.
  • Re-enabled the disabled xit drop-ghost spec. Its hard-coded pointer offsets missed the drop target, so it now moves the pointer to the measured "Add condition" button.

Motivation / Context

Improve Query Builder test coverage.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

Query Builder (also used by grid advanced filtering)

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

All query-builder specs and the non-grid suite pass. All specs that open grid advanced filtering pass (390). npm run lint:lib reports no errors.

Test Configuration:

  • Angular version: 22
  • Browser(s): Chrome Headless
  • OS: Windows 11

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

Copilot AI balanced review requested due to automatic review settings October 5, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Space can delete an expression without a valid drop target, and several tests do not verify their claimed behavior.

Review effort: Balanced
Findings: 1 High severity · 2 Low severity

Open (3)
What changed in this PR

Improves Query Builder coverage and adds standard Space-key drop support.

Changes:

  • Adds tests for inputs, templates, resources, and context menus.
  • Supports Space during keyboard drag-and-drop.
File Description
query-builder.component.spec.ts Expands Query Builder tests.
query-builder-drag.service.ts Handles Space-key drops.

Space/Enter before any arrow key deleted the dragged expression.

Also strengthen weak specs flagged in review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Keyboard drag activation still triggers unintended chip behavior and Space may scroll the page.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (3)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Prevent default activation key behavior during reorder

projects/​igniteui-angular/​query-builder/​src/​query-builder/​query-builder-drag.service.ts:405

Cancel the activation key's default action here. When a drop ghost exists, the chip's invokeClick handler deliberately does nothing, so a real Space keydown reaches this branch without any preventDefault() call and can scroll the page while committing the reorder.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The user-visible fixes need a changelog entry, and the new fixture contains redundant Angular metadata.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)

@ivanvpetrov
ivanvpetrov requested a balanced review from Copilot October 6, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Space-triggered drops must prevent the browser’s native scrolling action.

Review effort: Balanced
Findings: None

Resolved since last review (3)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Prevent Space key default scrolling when committing a drop

projects/​igniteui-angular/​query-builder/​src/​query-builder/​query-builder-drag.service.ts:411

The newly supported real Space key (' ') still performs its native browser action because this branch never cancels the keydown. When the drag indicator is focused, the page can scroll at the same time the condition is dropped. Prevent the default action before committing the drop (and make the corresponding test event cancelable if asserting this behavior).

@ivanvpetrov ivanvpetrov changed the title test(query-builder): coverage improved Query Builder: Refactor, bug fixing and test coverage improved Oct 6, 2026
@ivanvpetrov ivanvpetrov changed the title Query Builder: Refactor, bug fixing and test coverage improved [Query Builder] Refactor, bug fixing and test coverage improved Oct 6, 2026
@ivanvpetrov
ivanvpetrov requested a balanced review from Copilot October 6, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Enter and Space can still activate another chip during a mouse drag before the new tree-level guard executes.

Review effort: Balanced
Findings: None

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants