Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 12 additions & 11 deletions renderers/angular/a2ui_explorer/src/app/agent-stub.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { A2uiRendererService } from '@a2ui/angular/v0_9';
import { ActionDispatcher } from './action-dispatcher.service';
import { Subject } from 'rxjs';
import { A2uiMessage } from '@a2ui/web_core/v0_9';
import { vi, describe, it, expect, beforeEach } from 'vitest';

describe('AgentStubService', () => {
let service: AgentStubService;
Expand All @@ -30,10 +29,10 @@ describe('AgentStubService', () => {

beforeEach(() => {
mockSurfaceGroup = {
getSurface: vi.fn(),
getSurface: jasmine.createSpy('getSurface'),
};
mockRendererService = {
processMessages: vi.fn(),
processMessages: jasmine.createSpy('processMessages'),
get surfaceGroup() {
return mockSurfaceGroup;
},
Expand Down Expand Up @@ -69,28 +68,30 @@ describe('AgentStubService', () => {
const messages = [createMsg];

// 1. First call: Surface does not exist
mockSurfaceGroup.getSurface.mockReturnValue(undefined);
mockSurfaceGroup.getSurface.and.returnValue(undefined);
service.initializeDemo(messages);

// Should have called processMessages with initial messages only
expect(mockRendererService.processMessages).toHaveBeenCalledWith(messages);
expect(mockRendererService.processMessages).toHaveBeenCalledTimes(1);
mockRendererService.processMessages.mockClear();
mockRendererService.processMessages.calls.reset();

// 2. Second call: Surface now exists
mockSurfaceGroup.getSurface.mockReturnValue({ id: surfaceId });
mockSurfaceGroup.getSurface.and.returnValue({ id: surfaceId });
service.initializeDemo(messages);

// Should have called processMessages twice:
// First with deleteSurface, then with initial messages
expect(mockRendererService.processMessages).toHaveBeenCalledTimes(2);
expect(mockRendererService.processMessages).toHaveBeenNthCalledWith(1, [
const deleteMessages = [
{
version: 'v0.9',
version: 'v0.9' as const,
deleteSurface: { surfaceId },
},
];
expect(mockRendererService.processMessages.calls.allArgs()).toEqual([
[deleteMessages],
[messages],
]);
expect(mockRendererService.processMessages).toHaveBeenNthCalledWith(2, messages);
});

it('should NOT send deleteSurface if surface does not exist', () => {
Expand All @@ -104,7 +105,7 @@ describe('AgentStubService', () => {
};
const messages = [createMsg];

mockSurfaceGroup.getSurface.mockReturnValue(undefined);
mockSurfaceGroup.getSurface.and.returnValue(undefined);
service.initializeDemo(messages);

expect(mockRendererService.processMessages).toHaveBeenCalledTimes(1);
Expand Down
3 changes: 2 additions & 1 deletion renderers/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"test": {
"builder": "@angular/build:karma",
"options": {
"tsConfig": "./tsconfig.spec.json"
"tsConfig": "./tsconfig.spec.json",
"karmaConfig": "karma.conf.js"
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions renderers/angular/karma-custom.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = function (config) {
config.set({
hostname: '127.0.0.1',
listenAddress: '127.0.0.1',
captureTimeout: 210000, // 3.5 minutes
browserNoActivityTimeout: 210000,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
});
};
56 changes: 56 additions & 0 deletions renderers/angular/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/lib'),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }],
},
reporters: ['progress', 'kjhtml'],
browsers: ['Chrome'],
restartOnFileChange: true,
hostname: '127.0.0.1',
listenAddress: '127.0.0.1',
captureTimeout: 210000,
browserNoActivityTimeout: 210000,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
});
};
Loading
Loading