<commit_before>import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
    IgxGridModule
} from './public_api';
import { IgxGridComponent } from './grid.component';
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
import { setupGridScrollDetection } from '../../test-utils/helper-utils.spec';
import { configureTestSuite } from '../../test-utils/configure-suite';
import {
    SelectionWithScrollsComponent,
    MRLTestComponent,
    ColumnGroupsNavigationTestComponent
} from '../../test-utils/grid-samples.spec';
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
import { DebugElement } from '@angular/core';
import { GridSelectionMode, FilterMode } from '../common/enums';
import { IActiveNodeChangeEventArgs } from '../common/events';
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';

const DEBOUNCETIME = 30;

describe('IgxGrid - Headers Keyboard navigation #grid', () => {
    describe('Headers Navigation', () => {
        let fix;
        let grid: IgxGridComponent;
        let gridHeader: DebugElement;
        configureTestSuite();
        beforeAll(waitForAsync(() => {
            TestBed.configureTestingModule({
                declarations: [
                    SelectionWithScrollsComponent
                ],
                imports: [NoopAnimationsModule, IgxGridModule],
            }).compileComponents();
        }));

        beforeEach(fakeAsync(/** height/width setter rAF */() => {
            fix = TestBed.createComponent(SelectionWithScrollsComponent);
            fix.detectChanges();
            grid = fix.componentInstance.grid;
            setupGridScrollDetection(fix, grid);
            fix.detectChanges();
            gridHeader = GridFunctions.getGridHeader(fix);
        }));

        it('when click on a header it should stay in the view', async () => {
            grid.headerContainer.getScroll().scrollLeft = 1000;
            await wait(100);
            fix.detectChanges();

            let header = GridFunctions.getColumnHeader('OnPTO', fix);
            UIInteractions.simulateClickAndSelectEvent(header);
            await wait(200);
            fix.detectChanges();

            header = GridFunctions.getColumnHeader('OnPTO', fix);
            expect(header).toBeDefined();
            GridFunctions.verifyHeaderIsFocused(header.parent);
        });

        it('should focus first header when the grid is scrolled', async () => {
            grid.navigateTo(7, 5);
            await wait(150);
            fix.detectChanges();

            gridHeader.triggerEventHandler('focus', {});
            await wait(250);
            fix.detectChanges();

            const header = GridFunctions.getColumnHeader('ID', fix);
            expect(header).toBeTruthy();
            expect(grid.navigation.activeNode.column).toEqual(0);
            expect(grid.navigation.activeNode.row).toEqual(-1);
            expect(grid.headerContainer.getScroll().scrollLeft).toEqual(0);
            expect(grid.verticalScrollContainer.getScroll().scrollTop).toBeGreaterThanOrEqual(100);
        });

        it('should emit when activeNode ref is changed', () => {
            spyOn(grid.activeNodeChange, 'emit').and.callThrough();

            const args: IActiveNodeChangeEventArgs = {
                row: -1,<commit_msg>test(Grid): update gid test according new activeNode behavior #8677<commit_after>import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
    IgxGridModule
} from './public_api';
import { IgxGridComponent } from './grid.component';
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
import { setupGridScrollDetection } from '../../test-utils/helper-utils.spec';
import { configureTestSuite } from '../../test-utils/configure-suite';
import {
    SelectionWithScrollsComponent,
    MRLTestComponent,
    ColumnGroupsNavigationTestComponent
} from '../../test-utils/grid-samples.spec';
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
import { DebugElement } from '@angular/core';
import { GridSelectionMode, FilterMode } from '../common/enums';
import { IActiveNodeChangeEventArgs } from '../common/events';
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';

const DEBOUNCETIME = 30;

describe('IgxGrid - Headers Keyboard navigation #grid', () => {
    describe('Headers Navigation', () => {
        let fix;
        let grid: IgxGridComponent;
        let gridHeader: DebugElement;
        configureTestSuite();
        beforeAll(waitForAsync(() => {
            TestBed.configureTestingModule({
                declarations: [
                    SelectionWithScrollsComponent
                ],
                imports: [NoopAnimationsModule, IgxGridModule],
            }).compileComponents();
        }));

        beforeEach(fakeAsync(/** height/width setter rAF */() => {
            fix = TestBed.createComponent(SelectionWithScrollsComponent);
            fix.detectChanges();
            grid = fix.componentInstance.grid;
            setupGridScrollDetection(fix, grid);
            fix.detectChanges();
            gridHeader = GridFunctions.getGridHeader(fix);
        }));

        it('when click on a header it should stay in the view', async () => {
            grid.headerContainer.getScroll().scrollLeft = 1000;
            await wait(100);
            fix.detectChanges();

            let header = GridFunctions.getColumnHeader('OnPTO', fix);
            UIInteractions.simulateClickAndSelectEvent(header);
            await wait(200);
            fix.detectChanges();

            header = GridFunctions.getColumnHeader('OnPTO', fix);
            expect(header).toBeDefined();
            GridFunctions.verifyHeaderIsFocused(header.parent);
        });

        it('should focus first header when the grid is scrolled', async () => {
            grid.navigateTo(7, 5);
            await wait(150);
            fix.detectChanges();

            gridHeader.triggerEventHandler('focus', {});
            await wait(250);
            fix.detectChanges();

            const header = GridFunctions.getColumnHeader('ID', fix);
            expect(header).not.toBeDefined();
            expect(grid.navigation.activeNode.column).toEqual(3);
            expect(grid.navigation.activeNode.row).toEqual(-1);
            expect(grid.headerContainer.getScroll().scrollLeft).toBeGreaterThanOrEqual(200);
            expect(grid.verticalScrollContainer.getScroll().scrollTop).toBeGreaterThanOrEqual(100);
        });

        it('should emit when activeNode ref is changed', () => {
            spyOn(grid.activeNodeChange, 'emit').and.callThrough();

            const args: IActiveNodeChangeEventArgs = {
                row: -1,
{'fraction_non_alphanumeric': 0.12781015820149874, 'fraction_numerical': 0.00832639467110741, 'mean_word_length': 2.6509625126646403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '421593', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1828, 'n_words': 361}