Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
R0tenur committed Oct 20, 2023
1 parent a624799 commit c559073
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions frontend/src/app/components/alert/alert.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BehaviorSubject, Subject } from 'rxjs';
import { Status } from '../../../../../shared/models/status.enum';
Expand All @@ -15,23 +15,28 @@ describe('AlertComponent', () => {
let alertService: AlertService;
let dataStudioService: DataStudioService;
const alertSubject: Subject<ChartError> = new Subject<ChartError>();
const markdownSubject: BehaviorSubject<string> = new BehaviorSubject<string>(undefined as any as string);
const markdownSubject: BehaviorSubject<string> = new BehaviorSubject<string>(
undefined as any as string
);

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AlertComponent],
imports: [AppTestingModule],
})
.compileComponents();
}).compileComponents();
});
afterEach(() => alertSubject.next(undefined));

beforeEach(() => {
alertService = TestBed.inject(AlertService);
spyOnProperty(alertService, 'Alert$').and.returnValue(alertSubject.asObservable());
spyOnProperty(alertService, 'Alert$').and.returnValue(
alertSubject.asObservable()
);

dataStudioService = TestBed.inject(DataStudioService);
spyOnProperty(dataStudioService, 'Markdown$').and.returnValue(markdownSubject.asObservable());
spyOnProperty(dataStudioService, 'Markdown$').and.returnValue(
markdownSubject.asObservable()
);

fixture = TestBed.createComponent(AlertComponent);
component = fixture.componentInstance;
Expand Down Expand Up @@ -60,7 +65,9 @@ describe('AlertComponent', () => {
alertSubject.next(createChartError());
fixture.detectChanges();
// Assert
expect(fixture.debugElement.query(By.css('#textSizeExceededError'))).toBeFalsy();
expect(
fixture.debugElement.query(By.css('#textSizeExceededError'))
).toBeFalsy();
});

it('should show specific message on "Maximum text size in diagram exceeded"', () => {
Expand All @@ -69,7 +76,9 @@ describe('AlertComponent', () => {
alertSubject.next(createChartError(error));
fixture.detectChanges();
// Assert
expect(fixture.debugElement.query(By.css('#textSizeExceededError'))).toBeTruthy();
expect(
fixture.debugElement.query(By.css('#textSizeExceededError'))
).toBeTruthy();
});

it('should show markdown download button for "Maximum text size in diagram exceeded" when markdown present', fakeAsync(() => {
Expand All @@ -79,11 +88,11 @@ describe('AlertComponent', () => {
alertSubject.next(createChartError(error));
fixture.detectChanges();
// Assert
expect(fixture.debugElement.query(By.css('#textSizeExceededErrorBtn'))).toBeTruthy();
expect(
fixture.debugElement.query(By.css('#textSizeExceededErrorBtn'))
).toBeTruthy();
}));



const createChartError = (errorMessage: string = 'err') => {
const errors = [errorMessage];
const rawData = 'rawData';
Expand Down

0 comments on commit c559073

Please sign in to comment.