<commit_before>// Copyright 2019-2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { PeriodComponent } from './period.component';
import { StorageService } from '../storage.service';
import { FormsModule } from '@angular/forms';
import { BucketComponent } from '../bucket/bucket.component';
import { ObjectiveComponent } from '../objective/objective.component';
import { PeopleComponent } from '../people/people.component';
import { AssignmentsByPersonComponent } from '../assignments-by-person/assignments-by-person.component';
import { MaterialModule } from '../material/material.module';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { Team } from '../team';
import { Period, ImmutablePeriod } from '../period';
import { of } from 'rxjs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommitmentType, ImmutableObjectiveGroup } from '../objective';
import {AngularFireModule} from '@angular/fire';
import {firebaseConfig} from '../../environments/firebaseConfig';
import {AngularFireAuthModule} from '@angular/fire/auth';

describe('PeriodComponent', () => {
  let component: PeriodComponent;
  let fixture: ComponentFixture<PeriodComponent>;
  let storageServiceSpy = jasmine.createSpyObj('StorageService', ['getTeam', 'getPeriod']);
  let TEST_TEAM = new Team('testTeam', 'My test team');
  let TEST_PERIOD: Period = {
    id: 'testPeriod',
    displayName: 'My test period',
    unit: 'person weeks',
    secondaryUnits: [],
    notesURL: '',
    maxCommittedPercentage: 0,
    people: [],
    buckets: [],
    lastUpdateUUID: '',
  };

  beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      declarations: [
        PeriodComponent,
        BucketComponent,
        ObjectiveComponent,
        PeopleComponent,
        AssignmentsByPersonComponent,
      ],
      imports: [
        RouterTestingModule,
        FormsModule,
        MaterialModule,
        BrowserAnimationsModule,
        AngularFireModule.initializeApp(firebaseConfig.firebase, 'firebaseApp'),
        AngularFireAuthModule,
      ],
      providers: [
        {provide: StorageService, useValue: storageServiceSpy},
        {provide: ActivatedRoute, useValue: {
          paramMap: of(convertToParamMap({team: TEST_TEAM.id, period: TEST_PERIOD.id}))
        }},
      ],
    })
    .compileComponents();
    storageServiceSpy.getTeam.and.returnValue(of(TEST_TEAM));
    storageServiceSpy.getPeriod.and.returnValue(of(TEST_PERIOD));
  }));

  beforeEach(waitForAsync(() => {
    fixture = TestBed.createComponent(PeriodComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should only rename groups of the same group type', waitForAsync(() => {
    component.period = ImmutablePeriod.fromPeriod({...TEST_PERIOD, buckets: [
      {
        allocationPercentage: 100,
        displayName: 'Sole bucket',
        objectives: [
          {
            name: 'Sole objective',
            commitmentType: CommitmentType.Aspirational,
            resourceEstimate: 2,
            notes: '',<commit_msg>Mock out updatePeriod method on storageService<commit_after>// Copyright 2019-2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { PeriodComponent } from './period.component';
import { StorageService } from '../storage.service';
import { FormsModule } from '@angular/forms';
import { BucketComponent } from '../bucket/bucket.component';
import { ObjectiveComponent } from '../objective/objective.component';
import { PeopleComponent } from '../people/people.component';
import { AssignmentsByPersonComponent } from '../assignments-by-person/assignments-by-person.component';
import { MaterialModule } from '../material/material.module';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { Team } from '../team';
import { Period, ImmutablePeriod } from '../period';
import { of } from 'rxjs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommitmentType, ImmutableObjectiveGroup } from '../objective';
import {AngularFireModule} from '@angular/fire';
import {firebaseConfig} from '../../environments/firebaseConfig';
import {AngularFireAuthModule} from '@angular/fire/auth';
import { ObjectUpdateResponse } from '../objectupdateresponse';

describe('PeriodComponent', () => {
  let component: PeriodComponent;
  let fixture: ComponentFixture<PeriodComponent>;
  let storageServiceSpy = jasmine.createSpyObj('StorageService', ['getTeam', 'getPeriod', 'updatePeriod']);
  let TEST_TEAM = new Team('testTeam', 'My test team');
  let TEST_PERIOD: Period = {
    id: 'testPeriod',
    displayName: 'My test period',
    unit: 'person weeks',
    secondaryUnits: [],
    notesURL: '',
    maxCommittedPercentage: 0,
    people: [],
    buckets: [],
    lastUpdateUUID: '',
  };
  let UPDATE_RESPONSE: ObjectUpdateResponse = {lastUpdateUUID: 'abcd'};

  beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      declarations: [
        PeriodComponent,
        BucketComponent,
        ObjectiveComponent,
        PeopleComponent,
        AssignmentsByPersonComponent,
      ],
      imports: [
        RouterTestingModule,
        FormsModule,
        MaterialModule,
        BrowserAnimationsModule,
        AngularFireModule.initializeApp(firebaseConfig.firebase, 'firebaseApp'),
        AngularFireAuthModule,
      ],
      providers: [
        {provide: StorageService, useValue: storageServiceSpy},
        {provide: ActivatedRoute, useValue: {
          paramMap: of(convertToParamMap({team: TEST_TEAM.id, period: TEST_PERIOD.id}))
        }},
      ],
    })
    .compileComponents();
    storageServiceSpy.getTeam.and.returnValue(of(TEST_TEAM));
    storageServiceSpy.getPeriod.and.returnValue(of(TEST_PERIOD));
    storageServiceSpy.updatePeriod.and.returnValue(of(UPDATE_RESPONSE));
  }));

  beforeEach(waitForAsync(() => {
    fixture = TestBed.createComponent(PeriodComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should only rename groups of the same group type', waitForAsync(() => {
    component.period = ImmutablePeriod.fromPeriod({...TEST_PERIOD, buckets: [
      {
        allocationPercentage: 100,
        displayName: 'Sole bucket',
        objectives: [
          {
            name: 'Sole objective',
            commitmentType: CommitmentType.Aspirational,
            resourceEstimate: 2,
            notes: '',
{'fraction_non_alphanumeric': 0.1237152168463274, 'fraction_numerical': 0.004261719729255453, 'mean_word_length': 3.6551925320886816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3091985', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2141, 'n_words': 556}