Files
Samiya Caur 4454ae0a8a feat: add get_css_style tool (#2612)
Add `get_css_styles` tool which exposes matched styles and the CSS
cascade to empower accurate CSS debugging workflows.

It integrates `CssFormatter` into `McpPage` and `McpResponse`, adding
container query resolution and rule pagination support.

Co-authored-by: Samiya Caur <samiyac@chromium.org>
2026-09-11 07:51:16 +00:00

76 lines
1.8 KiB
TypeScript

/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {afterEach, describe, it} from 'node:test';
import sinon from 'sinon';
import {DevTools} from '../../src/third_party/index.js';
import {getCssStyles} from '../../src/tools/css.js';
import {createHandlerMocks} from '../mocks.js';
describe('get_css_styles', () => {
afterEach(() => {
sinon.restore();
});
it('retrieves matched styles for a uid and passes to response', async () => {
const {page, context, response} = createHandlerMocks();
const mockStyles = sinon.createStubInstance(
DevTools.CSSMatchedStyles.CSSMatchedStyles,
);
page.getMatchedStylesForUid.resolves(mockStyles);
await getCssStyles.handler(
{params: {uid: 'element-1'}, page},
response,
context,
);
sinon.assert.calledOnceWithExactly(
page.getMatchedStylesForUid,
'element-1',
);
sinon.assert.calledOnceWithExactly(
response.setIncludeCssStyles,
mockStyles,
{
uid: 'element-1',
pageSize: undefined,
pageIdx: undefined,
},
);
});
it('passes pagination options to response', async () => {
const {page, context, response} = createHandlerMocks();
const mockStyles = sinon.createStubInstance(
DevTools.CSSMatchedStyles.CSSMatchedStyles,
);
page.getMatchedStylesForUid.resolves(mockStyles);
await getCssStyles.handler(
{params: {uid: 'element-1', pageSize: 10, pageIdx: 2}, page},
response,
context,
);
sinon.assert.calledOnceWithExactly(
page.getMatchedStylesForUid,
'element-1',
);
sinon.assert.calledOnceWithExactly(
response.setIncludeCssStyles,
mockStyles,
{
uid: 'element-1',
pageSize: 10,
pageIdx: 2,
},
);
});
});