<commit_before>import { Component, ViewChild, OnInit, ElementRef, ViewChildren, QueryList } from '@angular/core';
import { async, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { IgxToggleModule, IgxToggleDirective } from '../directives/toggle/toggle.directive';
import { IgxDropDownItemComponent } from './drop-down-item.component';
import { IgxDropDownComponent, IgxDropDownModule } from './index';
import { ISelectionEventArgs } from './drop-down.common';
import { IgxTabsComponent, IgxTabsModule } from '../tabs/tabs.component';
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
import { CancelableEventArgs } from '../core/utils';
import { configureTestSuite } from '../test-utils/configure-suite';
import { take } from 'rxjs/operators';
import { IgxDropDownGroupComponent } from './drop-down-group.component';
import { IgxForOfDirective, IgxForOfModule } from '../directives/for-of/for_of.directive';
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
import { DisplayDensity } from '../core/density';
import { IgxSelectionAPIService } from '../core/selection';

const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down';
const CSS_CLASS_LIST = 'igx-drop-down__list';
const CSS_CLASS_SCROLL = 'igx-drop-down__list-scroll';
const CSS_CLASS_ITEM = 'igx-drop-down__item';
const CSS_CLASS_GROUP_ITEM = 'igx-drop-down__group';
const CSS_CLASS_ITEM_COSY = 'igx-drop-down__item--cosy';
const CSS_CLASS_ITEM_COMPACT = 'igx-drop-down__item--compact';
const CSS_CLASS_FOCUSED = 'igx-drop-down__item--focused';
const CSS_CLASS_SELECTED = 'igx-drop-down__item--selected';
const CSS_CLASS_DISABLED = 'igx-drop-down__item--disabled';
const CSS_CLASS_HEADER = 'igx-drop-down__header';
const CSS_CLASS_HEADER_COSY = 'igx-drop-down__header--cosy';
const CSS_CLASS_HEADER_COMPACT = 'igx-drop-down__header--compact';
const CSS_CLASS_TABS = '.igx-tabs__header-menu-item';

describe('IgxDropDown ', () => {
    let fixture;
    let dropdown: IgxDropDownComponent;
    describe('Unit tests', () => {
        const data = [
            { value: 'Item0', index: 0 } as IgxDropDownItemComponent,
            { value: 'Item1', index: 1 } as IgxDropDownItemComponent,
            { value: 'Item2', index: 2 } as IgxDropDownItemComponent,
            { value: 'Item3', index: 3 } as IgxDropDownItemComponent,
            { value: 'Item4', index: 4 } as IgxDropDownItemComponent,
            { value: 'Item5', index: 5 } as IgxDropDownItemComponent];
        const mockSelection: {
            [key: string]: jasmine.Spy
        } = jasmine.createSpyObj('IgxSelectionAPIService', ['get', 'set', 'add_items', 'select_items']);
        const mockCdr = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']);
        mockSelection.get.and.returnValue(new Set([]));
        const mockForOf = jasmine.createSpyObj('IgxForOfDirective', ['totalItemCount']);
        it('should notify when selection has changed', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();

            dropdown.selectItem(data[0]);
            expect(dropdown.selectedItem).toEqual(data[0]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(1);

            dropdown.selectItem(data[4]);
            expect(dropdown.selectedItem).toEqual(data[4]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(2);
        });
        it('should fire onSelection with correct args', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();

            const selectionArgs: ISelectionEventArgs = {
                newSelection: dropdown.items[1],
                oldSelection: null,
                cancel: false
            };
            dropdown.selectItem(data[1]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(selectionArgs);

            const newSelectionArgs: ISelectionEventArgs = {
                newSelection: dropdown.items[4],
                oldSelection: dropdown.items[1],
                cancel: false
            };
            dropdown.selectItem(data[4]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(newSelectionArgs);
        });
        it('should notify when selection is cleared', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();
            spyOn(dropdown.onClosed, 'emit').and.callThrough();

            dropdown.selectItem(data[1]);
            expect(dropdown.selectedItem).toEqual(data[1]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(1);
            let args: ISelectionEventArgs = {
                oldSelection: null,
                newSelection: data[1],
                cancel: false
            };
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(args);

            dropdown.clearSelection();
            expect(dropdown.selectedItem).toBeNull();
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(2);
            args = {
                oldSelection: { value: data[1].value, index: data[1].index, selected: false },
                newSelection: null,
                cancel: false
            };
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(args);
        });
        it('setSelectedItem should return selected item', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();<commit_msg>chore(*): fixing the leftover test<commit_after>import { Component, ViewChild, OnInit, ElementRef, ViewChildren, QueryList } from '@angular/core';
import { async, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { IgxToggleModule, IgxToggleDirective } from '../directives/toggle/toggle.directive';
import { IgxDropDownItemComponent } from './drop-down-item.component';
import { IgxDropDownComponent, IgxDropDownModule } from './index';
import { ISelectionEventArgs } from './drop-down.common';
import { IgxTabsComponent, IgxTabsModule } from '../tabs/tabs.component';
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
import { CancelableEventArgs } from '../core/utils';
import { configureTestSuite } from '../test-utils/configure-suite';
import { take } from 'rxjs/operators';
import { IgxDropDownGroupComponent } from './drop-down-group.component';
import { IgxForOfDirective, IgxForOfModule } from '../directives/for-of/for_of.directive';
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
import { DisplayDensity } from '../core/density';
import { IgxSelectionAPIService } from '../core/selection';

const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down';
const CSS_CLASS_LIST = 'igx-drop-down__list';
const CSS_CLASS_SCROLL = 'igx-drop-down__list-scroll';
const CSS_CLASS_ITEM = 'igx-drop-down__item';
const CSS_CLASS_GROUP_ITEM = 'igx-drop-down__group';
const CSS_CLASS_ITEM_COSY = 'igx-drop-down__item--cosy';
const CSS_CLASS_ITEM_COMPACT = 'igx-drop-down__item--compact';
const CSS_CLASS_FOCUSED = 'igx-drop-down__item--focused';
const CSS_CLASS_SELECTED = 'igx-drop-down__item--selected';
const CSS_CLASS_DISABLED = 'igx-drop-down__item--disabled';
const CSS_CLASS_HEADER = 'igx-drop-down__header';
const CSS_CLASS_HEADER_COSY = 'igx-drop-down__header--cosy';
const CSS_CLASS_HEADER_COMPACT = 'igx-drop-down__header--compact';
const CSS_CLASS_TABS = '.igx-tabs__header-menu-item';

describe('IgxDropDown ', () => {
    let fixture;
    let dropdown: IgxDropDownComponent;
    describe('Unit tests', () => {
        const data = [
            { value: 'Item0', index: 0 } as IgxDropDownItemComponent,
            { value: 'Item1', index: 1 } as IgxDropDownItemComponent,
            { value: 'Item2', index: 2 } as IgxDropDownItemComponent,
            { value: 'Item3', index: 3 } as IgxDropDownItemComponent,
            { value: 'Item4', index: 4 } as IgxDropDownItemComponent,
            { value: 'Item5', index: 5 } as IgxDropDownItemComponent];
        const mockSelection: {
            [key: string]: jasmine.Spy
        } = jasmine.createSpyObj('IgxSelectionAPIService', ['get', 'set', 'add_items', 'select_items']);
        const mockCdr = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']);
        mockSelection.get.and.returnValue(new Set([]));
        const mockForOf = jasmine.createSpyObj('IgxForOfDirective', ['totalItemCount']);
        it('should notify when selection has changed', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();

            dropdown.selectItem(data[0]);
            expect(dropdown.selectedItem).toEqual(data[0]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(1);

            dropdown.selectItem(data[4]);
            expect(dropdown.selectedItem).toEqual(data[4]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(2);
        });
        it('should fire onSelection with correct args', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();

            const selectionArgs: ISelectionEventArgs = {
                newSelection: dropdown.items[1],
                oldSelection: null,
                cancel: false
            };
            dropdown.selectItem(data[1]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(selectionArgs);

            const newSelectionArgs: ISelectionEventArgs = {
                newSelection: dropdown.items[4],
                oldSelection: dropdown.items[1],
                cancel: false
            };
            dropdown.selectItem(data[4]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(newSelectionArgs);
        });
        it('should notify when selection is cleared', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
            (dropdown as any).virtDir = mockForOf;
            spyOnProperty(dropdown, 'items', 'get').and.returnValue(data);
            spyOn(dropdown.onSelection, 'emit').and.callThrough();
            spyOn(dropdown.onClosed, 'emit').and.callThrough();

            dropdown.selectItem(data[1]);
            const selected = dropdown.selectedItem;
            expect(dropdown.selectedItem).toEqual(data[1]);
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(1);
            let args: ISelectionEventArgs = {
                oldSelection: null,
                newSelection: data[1],
                cancel: false
            };
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(args);

            dropdown.clearSelection();
            expect(dropdown.selectedItem).toBeNull();
            expect(dropdown.onSelection.emit).toHaveBeenCalledTimes(2);
            args = {
                oldSelection: selected,
                newSelection: null,
                cancel: false
            };
            expect(dropdown.onSelection.emit).toHaveBeenCalledWith(args);
        });
        it('setSelectedItem should return selected item', () => {
            const selectionService = new IgxSelectionAPIService();
            dropdown = new IgxDropDownComponent({ nativeElement: null }, mockCdr, selectionService, null);
            dropdown.ngOnInit();
{'fraction_non_alphanumeric': 0.12454927884615384, 'fraction_numerical': 0.004356971153846154, 'mean_word_length': 3.0354652925128827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1220479', 'n_tokens_mistral': 3811, 'n_tokens_neox': 3679, 'n_words': 711}