Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12588] Added unit tests to LogsTable component #13181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading