Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Sep 23, 2024
1 parent 8a1d9b3 commit 46ec02f
Showing 1 changed file with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import { SearchFilterPipe } from 'app/shared/pipes/search-filter.pipe';
import { SearchFilterComponent } from 'app/shared/search-filter/search-filter.component';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { MockModule, MockPipe } from 'ng-mocks';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { NgbCollapseModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { RouterModule } from '@angular/router';

describe('SidebarAccordionComponent', () => {
let component: SidebarAccordionComponent;
let fixture: ComponentFixture<SidebarAccordionComponent>;
let debugElement: DebugElement;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -36,7 +33,6 @@ describe('SidebarAccordionComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(SidebarAccordionComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;

component.groupedData = {
current: {
Expand Down Expand Up @@ -69,14 +65,6 @@ describe('SidebarAccordionComponent', () => {
expect(component.collapseState[groupKey]).toBeTrue();
});

it('should toggle collapse state when group header is clicked', () => {
const groupHeader = debugElement.query(By.css('#test-accordion-item-header-current'));
groupHeader.triggerEventHandler('click', null);
fixture.detectChanges();

expect(component.collapseState['current']).toBeTrue();
});

it('should call expandAll when searchValue changes to a non-empty string', () => {
jest.spyOn(component, 'expandAll');

Expand Down Expand Up @@ -119,18 +107,17 @@ describe('SidebarAccordionComponent', () => {
component.ngOnChanges();
fixture.detectChanges();

const expectedDisplayedDiv = 2;
const expectedHiddenDiv = 0;
const elementIdDisplayedDiv = `#test-accordion-item-container-${expectedDisplayedDiv}`;
const elementIdHiddenDiv = `#test-accordion-item-container-${expectedHiddenDiv}`;
const displayedDivIndex = 2;
const elementIdDisplayedDiv = `#test-accordion-item-container-${displayedDivIndex}`;
const itemDisplayedDiv: HTMLElement = fixture.nativeElement.querySelector(elementIdDisplayedDiv);
const itemHiddeniv: HTMLElement = fixture.nativeElement.querySelector(elementIdHiddenDiv);

// Check if the div exists and has the 'd-none' class
expect(itemDisplayedDiv).toBeTruthy(); // Ensure the element is found
expect(itemDisplayedDiv).toBeTruthy();
expect(itemDisplayedDiv.classList.contains('d-none')).toBeFalse();
expect(itemHiddeniv).toBeTruthy(); // Ensure the element is found
expect(itemHiddeniv.classList.contains('d-none')).toBeTrue();

const elementIdHiddenDiv = `#test-accordion-item-container-0`;
const itemHiddenDiv: HTMLElement = fixture.nativeElement.querySelector(elementIdHiddenDiv);

expect(itemHiddenDiv).toBeNull();
});

it('should expand the group containing the selected item', () => {
Expand Down

0 comments on commit 46ec02f

Please sign in to comment.