Skip to content

Commit

Permalink
Add client test to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-glombik committed Oct 12, 2024
1 parent b804c02 commit ad9e2a2
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
import { SwitchEditModeButtonComponent } from '../../../../../../main/webapp/app/exercises/programming/manage/update/switch-edit-mode-button/switch-edit-mode-button.component';
import { ArtemisSharedCommonModule } from '../../../../../../main/webapp/app/shared/shared-common.module';
import { ArtemisSharedComponentModule } from '../../../../../../main/webapp/app/shared/components/shared-component.module';
import { MockTranslateService } from '../../../helpers/mocks/service/mock-translate.service';
import { By } from '@angular/platform-browser';
import { MockModule } from 'ng-mocks';

describe('SwitchEditModeButtonComponent', () => {
let fixture: ComponentFixture<SwitchEditModeButtonComponent>;
let comp: SwitchEditModeButtonComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [SwitchEditModeButtonComponent],
declarations: [MockModule(ArtemisSharedCommonModule), MockModule(ArtemisSharedComponentModule)],
providers: [{ provide: TranslateService, useClass: MockTranslateService }],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SwitchEditModeButtonComponent);
comp = fixture.componentInstance;

fixture.componentRef.setInput('switchEditMode', () => {});
fixture.componentRef.setInput('isSimpleMode', false);
});
});

it('should initialize', fakeAsync(() => {
fixture.detectChanges();
expect(comp).not.toBeNull();
}));

it('should call passed method when button is clicked', () => {
const testMethod = jest.fn();
fixture.componentRef.setInput('switchEditMode', testMethod);

const button = fixture.debugElement.query(By.css('jhi-button'));
button.triggerEventHandler('onClick', null);

expect(testMethod).toHaveBeenCalled();
});
});

0 comments on commit ad9e2a2

Please sign in to comment.