Skip to content

Commit

Permalink
Add tests for the LogsTable component
Browse files Browse the repository at this point in the history
  • Loading branch information
SamGreenwood04 committed Oct 18, 2024
1 parent 6d4f9f4 commit f5dc959
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/web/app/components/logs-table/logs-table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { LogDetailsModule } from './log-details/log-details.module';
import { LogLineModule } from './log-line/log-line.module';
import { LogsTableRowModel } from './logs-table-model';
import { LogsTableComponent } from './logs-table.component';
import { LogSeverity, LogEvent, SourceLocation, RequestLogUser } from '../../../types/api-output';

describe('LogsTableComponent', () => {
let component: LogsTableComponent;
Expand All @@ -25,4 +27,77 @@ describe('LogsTableComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should toggle the isDetailsExpanded property of LogsTableRowModel', () => {
const exampleLog: LogsTableRowModel = {
logEntry: {
severity: LogSeverity.INFO,
trace: 'sample-trace',
insertId: '123456',
resourceIdentifier: { key: 'sample-resource' },
sourceLocation: { file: 'file.ts', line: 123, function: 'someFunctionName' },
timestamp: 1697635200000,
message: 'Sample log message',
details: { event: LogEvent.REQUEST_LOG },
},
timestampForDisplay: '2024-10-18T10:00:00Z',
traceIdForDisplay: 'TRACE1234',
isDetailsExpanded: false,
};

// Expand details
component.expandDetails(exampleLog);
expect(exampleLog.isDetailsExpanded).toBe(true);

// Collapse details
component.expandDetails(exampleLog);
expect(exampleLog.isDetailsExpanded).toBe(false);
});

it('should return the correct class for severity levels', () => {
expect(component.getClassForSeverity('INFO')).toBe('info-row');
expect(component.getClassForSeverity('WARNING')).toBe('warning-row');
expect(component.getClassForSeverity('ERROR')).toBe('error-row');
expect(component.getClassForSeverity('DEBUG')).toBe('');
});

it('should emit addTraceEvent when addTraceToFilter is called', () => {
const spy = jest.spyOn(component.addTraceEvent, 'emit');
const trace = 'sample-trace';

component.addTraceToFilter(trace);
expect(spy).toHaveBeenCalledWith(trace);
});

it('should emit addActionClassEvent when addActionClassToFilter is called', () => {
const spy = jest.spyOn(component.addActionClassEvent, 'emit');
const actionClass = 'sample-action-class';

component.addActionClassToFilter(actionClass);
expect(spy).toHaveBeenCalledWith(actionClass);
});

it('should emit addExceptionClassEvent when addExceptionClassToFilter is called', () => {
const spy = jest.spyOn(component.addExceptionClassEvent, 'emit');
const exceptionClass = 'sample-exception-class';

component.addExceptionClassToFilter(exceptionClass);
expect(spy).toHaveBeenCalledWith(exceptionClass);
});

it('should emit addSourceLocationEvent when addSourceLocationToFilter is called', () => {
const spy = jest.spyOn(component.addSourceLocationEvent, 'emit');
const sourceLocation: SourceLocation = { file: 'file.ts', line: 123, function: 'someFunctionName' };

component.addSourceLocationToFilter(sourceLocation);
expect(spy).toHaveBeenCalledWith(sourceLocation);
});

it('should emit addUserInfoEvent when addUserInfoToFilter is called', () => {
const spy = jest.spyOn(component.addUserInfoEvent, 'emit');
const userInfo: RequestLogUser = { regkey: 'reg123', email: '[email protected]', googleId: 'google123' };

component.addUserInfoToFilter(userInfo);
expect(spy).toHaveBeenCalledWith(userInfo);
});
});

0 comments on commit f5dc959

Please sign in to comment.