Repository: oppia/oppia
File: core/templates/pages/learner-dashboard-page/goals-tab.component.spec.ts (TypeScript)

Code before:
    let topicBelongsTo = component.getTopicClassification('1');
    fixture.detectChanges();

    expect(topicBelongsTo).toEqual(1);
  });

  it('should check if the topicName belongs to learntToPartiallyLearntTopics', () => {
    component.learntToPartiallyLearntTopics = ['topic', 'topic2', 'topic3'];

    let topicBelongsTo =
      component.doesTopicBelongToLearntToPartiallyLearntTopics('topic');
    fixture.detectChanges();

    expect(topicBelongsTo).toEqual(true);
  });

  it('should toggle story', () => {
    component.currentGoalsStoryIsShown = [true];

    component.toggleStory(0);
    fixture.detectChanges();

    expect(component.currentGoalsStoryIsShown[0]).toEqual(false);
  });

    it('should call preventDefault when checkbox is clicked', () => {
    component.editGoalsTopicClassification = [0]
    fixture.detectChanges()

      const checkbox = fixture.nativeElement.querySelector(
    '.e2e-test-remove-topic-from-current-goals-button'
    );

    const eventClick = new Event('click');
    const preventDefaultSpy = spyOn(eventClick, 'preventDefault');

    checkbox.dispatchEvent(eventClick);

    expect(preventDefaultSpy).toHaveBeenCalled();
  })

  it('should add topic to learner goals if not already present', () => {
    component.topicIdsInCurrentGoals.length = 0;
    component.topicIdsInCompletedGoals = ['1', '2'];
    const learnerGoalsSpy = spyOn(
      learnerDashboardActivityBackendApiService,
      'addToLearnerGoals'
    ).and.returnValue(Promise.resolve(true));
    component.untrackedTopics = {math: [component.editGoals[0]]};
    component.addToLearnerGoals(component.editGoals[0], 'sample_topic_id', 1);
    fixture.detectChanges();

Review comment (bug):
A CI test is failing and it shows prettier has not been run on this code. Can you try running `npx prettier --check` followed by `npx prettier --write` and then commit and push the changes. Also just to check, did you push the code without running the pre-commit hook?

Code after:

    let topicBelongsTo = component.getTopicClassification('1');
    fixture.detectChanges();

    expect(topicBelongsTo).toEqual(1);
  });

  it('should check if the topicName belongs to learntToPartiallyLearntTopics', () => {
    component.learntToPartiallyLearntTopics = ['topic', 'topic2', 'topic3'];

    let topicBelongsTo =
      component.doesTopicBelongToLearntToPartiallyLearntTopics('topic');
    fixture.detectChanges();

    expect(topicBelongsTo).toEqual(true);
  });

  it('should toggle story', () => {
    component.currentGoalsStoryIsShown = [true];

    component.toggleStory(0);
    fixture.detectChanges();

    expect(component.currentGoalsStoryIsShown[0]).toEqual(false);
  });

  it('should call preventDefault when checkbox is clicked', () => {
    component.editGoalsTopicClassification = [0];
    fixture.detectChanges();

    const checkbox = fixture.debugElement.query(
      By.css('.e2e-test-remove-topic-from-current-goals-button')
    );
    if (!checkbox) {
      throw new Error('Unable to find the checkbox event');
    }

    const addToLearnerGoalsSpy = spyOn(
      component,
      'addToLearnerGoals'
    ).and.callThrough();

    checkbox.triggerEventHandler('click', {preventDefault: () => {}} as Event);
    fixture.detectChanges();

    expect(addToLearnerGoalsSpy).toHaveBeenCalled();
  });

  it('should add topic to learner goals if not already present', fakeAsync(() => {
    component.topicIdsInCurrentGoals.length = 0;
    component.topicIdsInCompletedGoals = ['1', '2'];