<commit_before>import {Component} from '@angular/core';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {CdkMenuModule} from './menu-module';
import {CdkMenuGroup} from './menu-group';
import {CdkMenuItem} from './menu-item';
import {CdkMenu} from './menu';
import {By} from '@angular/platform-browser';

describe('MenuGroup', () => {
  describe('MenuItem', () => {
    let fixture: ComponentFixture<MenuGroups>;
    let menuItems: Array<CdkMenuItem>;

    beforeEach(async(() => {
      TestBed.configureTestingModule({
        imports: [CdkMenuModule],
        declarations: [MenuGroups],
      }).compileComponents();

      fixture = TestBed.createComponent(MenuGroups);
      fixture.detectChanges();

      menuItems = fixture.debugElement
        .queryAll(By.directive(CdkMenuItem))
        .map((element) => element.injector.get(CdkMenuItem));
    }));

    it('should not change state of sibling menuitemcheckbox', () => {
      menuItems[1].trigger();

      expect(menuItems[0].checked).toBeTrue(); // default state true
    });

    it('should change state of sibling menuitemradio in same group', () => {
      menuItems[3].trigger();

      expect(menuItems[3].checked).toBeTrue();
      expect(menuItems[2].checked).toBeFalse();
    });

    it('should not change state of menuitemradio in sibling group', () => {
      menuItems[4].trigger();

      expect(menuItems[4].checked).toBeTrue();
      expect(menuItems[2].checked).toBeTrue();
    });

    it('should not change radiogroup state with disabled button', () => {
      menuItems[3].disabled = true;

      menuItems[3].trigger();

      expect(menuItems[2].checked).toBeTrue();
      expect(menuItems[3].checked).toBeFalse();
    });
  });

  describe('change events', () => {
    let fixture: ComponentFixture<MenuGroups>;
    let menu: CdkMenu;
    let menuItems: Array<CdkMenuItem>;

    beforeEach(async(() => {
      TestBed.configureTestingModule({
        imports: [CdkMenuModule],
        declarations: [MenuGroups],
      }).compileComponents();

      fixture = TestBed.createComponent(MenuGroups);
      fixture.detectChanges();

      menu = fixture.debugElement.query(By.directive(CdkMenu)).injector.get(CdkMenu);

      menuItems = fixture.debugElement
        .queryAll(By.directive(CdkMenuItem))
        .map((element) => element.injector.get(CdkMenuItem));
    }));

    it('should not emit from root menu with nested groups', () => {
      const spy = jasmine.createSpy('changeSpy for root menu');
      menu.change.subscribe(spy);

      menuItems.forEach((menuItem) => menuItem.trigger());

      expect(spy).toHaveBeenCalledTimes(0);
    });

    it('should emit from groups with clicked menu items', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[2].trigger();
      menuItems[4].trigger();

      expect(spies[1]).toHaveBeenCalledTimes(0);
      expect(spies[2]).toHaveBeenCalledTimes(1);
      expect(spies[2]).toHaveBeenCalledWith(menuItems[2]);
      expect(spies[3]).toHaveBeenCalledTimes(1);
      expect(spies[3]).toHaveBeenCalledWith(menuItems[4]);
    });

    it('should not emit with click on disabled button', () => {
      const spy = jasmine.createSpy('cdkMenuGroup change spy');

      fixture.debugElement
        .queryAll(By.directive(CdkMenuGroup))[3]
        .injector.get(CdkMenuGroup)
        .change.subscribe(spy);
      menuItems[4].disabled = true;

      menuItems[4].trigger();

      expect(spy).toHaveBeenCalledTimes(0);
    });

    it('should not emit from sibling groups', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[0].trigger();

      expect(spies[1]).toHaveBeenCalledTimes(1);
      expect(spies[2]).toHaveBeenCalledTimes(0);
      expect(spies[3]).toHaveBeenCalledTimes(0);
    });

    it('should not emit on menuitem click', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[7].trigger();

      spies.forEach((spy) => expect(spy).toHaveBeenCalledTimes(0));
    });
  });
});

@Component({
  template: `
    <ul cdkMenu><commit_msg>style: Remove parens around single argument arrow function<commit_after>import {Component} from '@angular/core';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {CdkMenuModule} from './menu-module';
import {CdkMenuGroup} from './menu-group';
import {CdkMenuItem} from './menu-item';
import {CdkMenu} from './menu';
import {By} from '@angular/platform-browser';

describe('MenuGroup', () => {
  describe('MenuItem', () => {
    let fixture: ComponentFixture<MenuGroups>;
    let menuItems: Array<CdkMenuItem>;

    beforeEach(async(() => {
      TestBed.configureTestingModule({
        imports: [CdkMenuModule],
        declarations: [MenuGroups],
      }).compileComponents();

      fixture = TestBed.createComponent(MenuGroups);
      fixture.detectChanges();

      menuItems = fixture.debugElement
        .queryAll(By.directive(CdkMenuItem))
        .map(e => e.injector.get(CdkMenuItem));
    }));

    it('should not change state of sibling menuitemcheckbox', () => {
      menuItems[1].trigger();

      expect(menuItems[0].checked).toBeTrue(); // default state true
    });

    it('should change state of sibling menuitemradio in same group', () => {
      menuItems[3].trigger();

      expect(menuItems[3].checked).toBeTrue();
      expect(menuItems[2].checked).toBeFalse();
    });

    it('should not change state of menuitemradio in sibling group', () => {
      menuItems[4].trigger();

      expect(menuItems[4].checked).toBeTrue();
      expect(menuItems[2].checked).toBeTrue();
    });

    it('should not change radiogroup state with disabled button', () => {
      menuItems[3].disabled = true;

      menuItems[3].trigger();

      expect(menuItems[2].checked).toBeTrue();
      expect(menuItems[3].checked).toBeFalse();
    });
  });

  describe('change events', () => {
    let fixture: ComponentFixture<MenuGroups>;
    let menu: CdkMenu;
    let menuItems: Array<CdkMenuItem>;

    beforeEach(async(() => {
      TestBed.configureTestingModule({
        imports: [CdkMenuModule],
        declarations: [MenuGroups],
      }).compileComponents();

      fixture = TestBed.createComponent(MenuGroups);
      fixture.detectChanges();

      menu = fixture.debugElement.query(By.directive(CdkMenu)).injector.get(CdkMenu);

      menuItems = fixture.debugElement
        .queryAll(By.directive(CdkMenuItem))
        .map(element => element.injector.get(CdkMenuItem));
    }));

    it('should not emit from root menu with nested groups', () => {
      const spy = jasmine.createSpy('changeSpy for root menu');
      menu.change.subscribe(spy);

      menuItems.forEach(menuItem => menuItem.trigger());

      expect(spy).toHaveBeenCalledTimes(0);
    });

    it('should emit from groups with clicked menu items', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[2].trigger();
      menuItems[4].trigger();

      expect(spies[1]).toHaveBeenCalledTimes(0);
      expect(spies[2]).toHaveBeenCalledTimes(1);
      expect(spies[2]).toHaveBeenCalledWith(menuItems[2]);
      expect(spies[3]).toHaveBeenCalledTimes(1);
      expect(spies[3]).toHaveBeenCalledWith(menuItems[4]);
    });

    it('should not emit with click on disabled button', () => {
      const spy = jasmine.createSpy('cdkMenuGroup change spy');

      fixture.debugElement
        .queryAll(By.directive(CdkMenuGroup))[3]
        .injector.get(CdkMenuGroup)
        .change.subscribe(spy);
      menuItems[4].disabled = true;

      menuItems[4].trigger();

      expect(spy).toHaveBeenCalledTimes(0);
    });

    it('should not emit from sibling groups', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[0].trigger();

      expect(spies[1]).toHaveBeenCalledTimes(1);
      expect(spies[2]).toHaveBeenCalledTimes(0);
      expect(spies[3]).toHaveBeenCalledTimes(0);
    });

    it('should not emit on menuitem click', () => {
      const spies: Array<jasmine.Spy> = [];

      fixture.debugElement.queryAll(By.directive(CdkMenuGroup)).forEach((group, index) => {
        const spy = jasmine.createSpy(`cdkMenuGroup ${index} change spy`);
        spies.push(spy);
        group.injector.get(CdkMenuGroup).change.subscribe(spy);
      });

      menuItems[7].trigger();

      spies.forEach(spy => expect(spy).toHaveBeenCalledTimes(0));
    });
  });
});

@Component({
  template: `
    <ul cdkMenu>
{'fraction_non_alphanumeric': 0.15749564504559893, 'fraction_numerical': 0.007787683164258633, 'mean_word_length': 3.4083107497741643, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 61, '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': '4617065', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2970, 'n_words': 500}