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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('DocsService Comments and Suggestions', () => {
it('should return suggestions as type text with JSON-stringified array', async () => {
mockDocsAPI.documents.get.mockResolvedValue({
data: {
title: 'Test Document',
body: {
content: [
{
Expand All @@ -84,7 +85,9 @@ describe('DocsService Comments and Suggestions', () => {
});

expect(result.content[0].type).toBe('text');
const suggestions = JSON.parse(result.content[0].text);
const parsed = JSON.parse(result.content[0].text);
expect(parsed.title).toBe('Test Document');
const { suggestions } = parsed;
expect(suggestions).toHaveLength(1);
expect(suggestions[0]).toEqual({
type: 'insertion',
Expand Down Expand Up @@ -123,7 +126,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].type).toBe('insertion');
expect(suggestions[0].suggestionIds).toEqual(['sug-1', 'sug-2']);
Expand Down Expand Up @@ -157,7 +160,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].type).toBe('deletion');
expect(suggestions[0].text).toBe('deleted text');
Expand Down Expand Up @@ -194,7 +197,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].type).toBe('styleChange');
expect(suggestions[0].suggestionIds).toEqual(['style-1']);
Expand Down Expand Up @@ -234,7 +237,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].type).toBe('paragraphStyleChange');
expect(suggestions[0].suggestionIds).toEqual(['sug-para-1']);
Expand Down Expand Up @@ -284,7 +287,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].type).toBe('insertion');
expect(suggestions[0].text).toBe('cell text');
Expand All @@ -299,8 +302,8 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
expect(suggestions).toEqual([]);
const parsed = JSON.parse(result.content[0].text);
expect(parsed.suggestions).toEqual([]);
});

it('should handle API errors gracefully', async () => {
Expand Down Expand Up @@ -351,7 +354,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(2);
const types = suggestions.map((s: any) => s.type);
expect(types).toEqual(['paragraphStyleChange', 'paragraphStyleChange']);
Expand Down Expand Up @@ -391,7 +394,7 @@ describe('DocsService Comments and Suggestions', () => {
documentId: 'test-doc-id',
});

const suggestions = JSON.parse(result.content[0].text);
const { suggestions } = JSON.parse(result.content[0].text);
expect(suggestions).toHaveLength(1);
expect(suggestions[0].text).toBe('');
});
Expand Down
16 changes: 10 additions & 6 deletions workspace-server/src/__tests__/services/DocsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ describe('DocsService', () => {
it('should return all tabs if no tabId provided and tabs exist', async () => {
const mockDoc = {
data: {
title: 'Multi-Tab Document',
tabs: [
{
tabProperties: { tabId: 'tab-1', title: 'Tab 1' },
Expand Down Expand Up @@ -550,14 +551,15 @@ describe('DocsService', () => {
const result = await docsService.getText({ documentId: 'test-doc-id' });
const parsed = JSON.parse(result.content[0].text);

expect(parsed).toHaveLength(2);
expect(parsed[0]).toEqual({
expect(parsed.title).toBe('Multi-Tab Document');
expect(parsed.tabs).toHaveLength(2);
Comment thread
allenhutchison marked this conversation as resolved.
expect(parsed.tabs[0]).toEqual({
tabId: 'tab-1',
title: 'Tab 1',
content: 'Tab 1 Content',
index: 0,
});
expect(parsed[1]).toEqual({
expect(parsed.tabs[1]).toEqual({
tabId: 'tab-2',
title: 'Tab 2',
content: 'Tab 2 Content',
Expand Down Expand Up @@ -695,6 +697,7 @@ describe('DocsService', () => {
it('should include text from nested child tabs', async () => {
const mockDoc = {
data: {
title: 'Nested Tabs Doc',
tabs: [
{
tabProperties: { tabId: 'parent-tab', title: 'Parent' },
Expand Down Expand Up @@ -736,14 +739,15 @@ describe('DocsService', () => {
const result = await docsService.getText({ documentId: 'test-doc-id' });
const parsed = JSON.parse(result.content[0].text);

expect(parsed).toHaveLength(2);
expect(parsed[0]).toEqual({
expect(parsed.title).toBe('Nested Tabs Doc');
expect(parsed.tabs).toHaveLength(2);
expect(parsed.tabs[0]).toEqual({
tabId: 'parent-tab',
title: 'Parent',
content: 'Parent Content',
index: 0,
});
expect(parsed[1]).toEqual({
expect(parsed.tabs[1]).toEqual({
tabId: 'child-tab',
title: 'Child',
content: 'Child Content',
Expand Down
19 changes: 15 additions & 4 deletions workspace-server/src/services/DocsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DocsService {
const res = await docs.documents.get({
documentId: id,
suggestionsViewMode: 'SUGGESTIONS_INLINE',
fields: 'body',
fields: 'title,body',
});

const suggestions: DocsSuggestion[] = this._extractSuggestions(
Expand All @@ -90,7 +90,11 @@ export class DocsService {
content: [
{
type: 'text' as const,
text: JSON.stringify(suggestions, null, 2),
text: JSON.stringify(
{ title: res.data.title, suggestions },
null,
2,
),
},
],
};
Expand Down Expand Up @@ -539,10 +543,11 @@ export class DocsService {
const docs = await this.getDocsClient();
const res = await docs.documents.get({
documentId: id,
fields: 'tabs', // Request tabs only (body is legacy and mutually exclusive with tabs in mask)
fields: 'title,tabs', // Request title and tabs (body is legacy and mutually exclusive with tabs in mask)
includeTabsContent: true,
});

const docTitle = res.data.title;
const tabs = this._flattenTabs(res.data.tabs || []);

// If tabId is provided, try to find it
Expand All @@ -565,6 +570,9 @@ export class DocsService {
}

let text = '';
if (docTitle) {
text += `Document Title: ${docTitle}\n\n`;
}
content.forEach((element) => {
text += this._readStructuralElement(element);
});
Expand Down Expand Up @@ -595,6 +603,9 @@ export class DocsService {
if (tabs.length === 1) {
const tab = tabs[0];
let text = '';
if (docTitle) {
text += `Document Title: ${docTitle}\n\n`;
}
if (tab.documentTab?.body?.content) {
tab.documentTab.body.content.forEach((element) => {
text += this._readStructuralElement(element);
Expand Down Expand Up @@ -630,7 +641,7 @@ export class DocsService {
content: [
{
type: 'text' as const,
text: JSON.stringify(tabsData, null, 2),
text: JSON.stringify({ title: docTitle, tabs: tabsData }, null, 2),
},
],
};
Expand Down
Loading