Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Dec 2, 2024
1 parent 050dc6e commit ecba0b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import {
AfterContentChecked,
ChangeDetectorRef,
Component,
OnChanges,
OnDestroy,
OnInit,
SimpleChanges,
ViewChild,
ViewContainerRef,
inject,
input,
output,
viewChild,
} from '@angular/core';
import { AfterContentChecked, ChangeDetectorRef, Component, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef, inject, input, output } from '@angular/core';
import { Post } from 'app/entities/metis/post.model';
import { MetisService } from 'app/shared/metis/metis.service';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
Expand Down Expand Up @@ -49,9 +35,9 @@ export class PostFooterComponent implements OnInit, OnDestroy, AfterContentCheck
userReferenceClicked = output<string>();
channelReferenceClicked = output<number>();

@ViewChild(AnswerPostCreateEditModalComponent) answerPostCreateEditModal?: AnswerPostCreateEditModalComponent;
@ViewChild('createEditAnswerPostContainer', { read: ViewContainerRef }) containerRef!: ViewContainerRef;
answerPostCreateEditModal = viewChild<AnswerPostCreateEditModalComponent>(AnswerPostCreateEditModalComponent);
createAnswerPostModalComponent = viewChild<AnswerPostCreateEditModalComponent>('createAnswerPostModal');
@ViewChild('createAnswerPostModal') createAnswerPostModalComponent!: AnswerPostCreateEditModalComponent;

createdAnswerPost: AnswerPost;
isAtLeastTutorInCourse = false;
Expand All @@ -76,7 +62,7 @@ export class PostFooterComponent implements OnInit, OnDestroy, AfterContentCheck
}

ngOnDestroy(): void {
this.answerPostCreateEditModal()?.createEditAnswerPostContainerRef?.clear();
this.answerPostCreateEditModal?.createEditAnswerPostContainerRef?.clear();
}

/**
Expand Down Expand Up @@ -170,14 +156,14 @@ export class PostFooterComponent implements OnInit, OnDestroy, AfterContentCheck
* Open create answer modal
*/
openCreateAnswerPostModal() {
this.createAnswerPostModalComponent()?.open();
this.createAnswerPostModalComponent?.open();
}

/**
* Close create answer modal
*/
closeCreateAnswerPostModal() {
this.createAnswerPostModalComponent()?.close();
this.createAnswerPostModalComponent?.close();
}

protected postsTrackByFn(index: number, post: Post): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { AnswerPost } from 'app/entities/metis/answer-post.model';
import { User } from 'app/core/user/user.model';
import { Injector, input, runInInjectionContext } from '@angular/core';
import { Posting } from 'app/entities/metis/posting.model';
import { By } from '@angular/platform-browser';

interface PostGroup {
author: User | undefined;
Expand Down Expand Up @@ -96,19 +95,14 @@ describe('PostFooterComponent', () => {
});

it('should clear answerPostCreateEditModal container on destroy', () => {
runInInjectionContext(fixture.debugElement.injector, () => {
const mockAnswerPostCreateEditModalDE = fixture.debugElement.query(By.directive(AnswerPostCreateEditModalComponent));
const mockAnswerPostCreateEditModal = mockAnswerPostCreateEditModalDE.componentInstance as AnswerPostCreateEditModalComponent;

const mockContainerRef = { clear: jest.fn() } as any;
mockAnswerPostCreateEditModal.createEditAnswerPostContainerRef = mockContainerRef;

const clearSpy = jest.spyOn(mockContainerRef, 'clear');

component.ngOnDestroy();

expect(clearSpy).toHaveBeenCalled();
});
const mockContainerRef = { clear: jest.fn() } as any;
component.answerPostCreateEditModal = {
createEditAnswerPostContainerRef: mockContainerRef,
} as AnswerPostCreateEditModalComponent;

const clearSpy = jest.spyOn(mockContainerRef, 'clear');
component.ngOnDestroy();
expect(clearSpy).toHaveBeenCalled();
});

it('should return the ID of the post in trackPostByFn', () => {
Expand Down Expand Up @@ -166,7 +160,7 @@ describe('PostFooterComponent', () => {
component.posting = input<Posting>(metisPostExerciseUser1);
component.ngOnInit();
fixture.detectChanges();
const createAnswerPostModalOpen = jest.spyOn(component.createAnswerPostModalComponent()!, 'open');
const createAnswerPostModalOpen = jest.spyOn(component.createAnswerPostModalComponent, 'open');
component.openCreateAnswerPostModal();
expect(createAnswerPostModalOpen).toHaveBeenCalledOnce();
});
Expand All @@ -177,7 +171,7 @@ describe('PostFooterComponent', () => {
component.posting = input<Posting>(metisPostExerciseUser1);
component.ngOnInit();
fixture.detectChanges();
const createAnswerPostModalClose = jest.spyOn(component.createAnswerPostModalComponent()!, 'close');
const createAnswerPostModalClose = jest.spyOn(component.createAnswerPostModalComponent, 'close');
component.closeCreateAnswerPostModal();
expect(createAnswerPostModalClose).toHaveBeenCalledOnce();
});
Expand Down

0 comments on commit ecba0b5

Please sign in to comment.