forked from TEAMMATES/teammates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the LogsTable component
- Loading branch information
1 parent
6d4f9f4
commit f5dc959
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
}); | ||
}); |