Skip to content

Commit

Permalink
fix unit tests on uistartup
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasini committed Nov 11, 2024
1 parent d6f4009 commit b841b3d
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions app/core/Performance/UIStartup.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TraceName, trace } from '../../util/trace';
// eslint-disable-next-line import/no-namespace
import * as traceObj from '../../util/trace';

Expand All @@ -7,6 +6,9 @@ jest.mock('../../util/trace', () => ({
TraceName: {
UIStartup: 'UIStartup',
},
TraceOperation: {
UIStartup: 'ui.startup',
},
}));

describe('getUIStartupSpan', () => {
Expand All @@ -22,20 +24,31 @@ describe('getUIStartupSpan', () => {

it('should call trace with correct parameters when UIStartupSpan is not set', () => {
const startTime = 12345;
const mockTraceContext = { name: TraceName.UIStartup, startTime };
jest.spyOn(traceObj, 'trace').mockImplementation(() => mockTraceContext);
const mockTraceContext = {
name: traceObj.TraceName.UIStartup,
startTime,
op: traceObj.TraceOperation.UIStartup,
};
const spyFetch = jest
.spyOn(traceObj, 'trace')
.mockImplementation(() => mockTraceContext);

const result = getUIStartupSpan(startTime);
getUIStartupSpan(startTime);

expect(trace).toHaveBeenCalledWith({
name: TraceName.UIStartup,
expect(spyFetch).toHaveBeenCalledWith({
name: traceObj.TraceName.UIStartup,
startTime,
op: traceObj.TraceOperation.UIStartup,
});
});

it('should return the existing UIStartupSpan if already set', () => {
const startTime = 12345;
const mockTraceContext = { name: TraceName.UIStartup, startTime };
const mockTraceContext = {
name: traceObj.TraceName.UIStartup,
startTime,
op: traceObj.TraceOperation.UIStartup,
};

const spyFetch = jest
.spyOn(traceObj, 'trace')
Expand All @@ -53,7 +66,11 @@ describe('getUIStartupSpan', () => {

it('should not call trace again if UIStartupSpan is already set', () => {
const startTime = 12345;
const mockTraceContext = { name: TraceName.UIStartup, startTime };
const mockTraceContext = {
name: traceObj.TraceName.UIStartup,
startTime,
op: traceObj.TraceOperation.UIStartup,
};
jest.spyOn(traceObj, 'trace').mockImplementation(() => mockTraceContext);

// First call to set the UIStartupSpan
Expand All @@ -62,6 +79,6 @@ describe('getUIStartupSpan', () => {
// Second call should return the same UIStartupSpan without calling trace again
getUIStartupSpan();

expect(trace).toHaveBeenCalledTimes(1);
expect(traceObj.trace).toHaveBeenCalledTimes(1);
});
});

0 comments on commit b841b3d

Please sign in to comment.