-
Notifications
You must be signed in to change notification settings - Fork 4
Content copilot UI #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deckdom
wants to merge
5
commits into
dev
Choose a base branch
from
f-content-copilot-ui
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Content copilot UI #793
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
547b1c1
feat(editor-ui): add Content Copilot button + sidebar scaffolding
7065f2f
feat(editor-ui): add Content Copilot button and sidebar scaffolding
a0375ee
feat(editor-ui): add Content Copilot button and sidebar scaffolding
592a276
test(editor-ui): add Playwright e2e coverage for Content Copilot
284c674
refactor(editor-ui): address PR-793 review feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,254 @@ | ||
| import { Page as CmsPage } from '@gentics/cms-models'; | ||
| import { | ||
| EntityImporter, | ||
| loginWithForm, | ||
| navigateToApp, | ||
| NODE_MINIMAL, | ||
| PAGE_ONE, | ||
| TestSize, | ||
| } from '@gentics/e2e-utils'; | ||
| import { expect, Locator, Page, test } from '@playwright/test'; | ||
| import { AUTH } from './common'; | ||
| import { openPageForEditing, selectNode } from './helpers'; | ||
|
|
||
| /* | ||
| * The Content Copilot is feature-flagged via a YAML file the customer drops | ||
| * into `{ui-conf}/config/copilot.yml`. The CI image obviously does not ship | ||
| * one, so every test here intercepts the request and serves a tailored YAML | ||
| * (or a 404 when the test wants the disabled state). | ||
| * | ||
| * Crucial: the route MUST be installed BEFORE `navigateToApp`, because the | ||
| * fetch is kicked off by `AppComponent.ngOnInit()` right after bootstrap. | ||
| * That is why the navigation/login/select-node trio is wrapped in | ||
| * `openEditorWithCopilot()` rather than living in a generic `beforeEach` | ||
| * the way other suites (e.g. page-editing.spec.ts) handle it. | ||
| */ | ||
|
|
||
| const COPILOT_CONFIG_URL_PATTERN = /\/ui-conf\/config\/copilot\.yml/; | ||
|
|
||
| const YAML_DISABLED = 'enabled: false\nactions: []\n'; | ||
| const YAML_ENABLED_NO_ACTIONS = 'enabled: true\nactions: []\n'; | ||
| const YAML_ENABLED_WITH_ACTIONS = `enabled: true | ||
| actions: | ||
| - id: summarize | ||
| label: Zusammenfassen | ||
| icon: summarize | ||
| description: Eine kurze Zusammenfassung der Seite erstellen | ||
| - id: rewrite-tone | ||
| label: Tonalität anpassen | ||
| icon: edit_note | ||
| `; | ||
|
|
||
| /** Stubs the customer copilot.yml endpoint for the lifetime of the page. */ | ||
| async function stubCopilotConfig(page: Page, yaml: string | null): Promise<void> { | ||
| await page.route(COPILOT_CONFIG_URL_PATTERN, (route) => { | ||
| if (yaml === null) { | ||
| return route.fulfill({ status: 404, body: 'Not Found' }); | ||
| } | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'text/yaml', | ||
| body: yaml, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** Navigation + login + node selection — all the steps that other suites do | ||
| * in `beforeEach`, but invoked AFTER the YAML stub so the Copilot bootstrap | ||
| * fetch sees the per-test response. */ | ||
| async function openEditorWithCopilot( | ||
| page: Page, | ||
| importer: EntityImporter, | ||
| yaml: string | null, | ||
| ): Promise<void> { | ||
| await stubCopilotConfig(page, yaml); | ||
| await navigateToApp(page); | ||
| await loginWithForm(page, AUTH.admin); | ||
| await selectNode(page, importer.get(NODE_MINIMAL).id); | ||
| } | ||
|
|
||
| function copilotButton(page: Page): Locator { | ||
| return page.locator('content-frame gtx-editor-toolbar [data-action="copilot"]'); | ||
| } | ||
|
|
||
| function copilotSidebar(page: Page): Locator { | ||
| return page.locator('gtx-copilot-sidebar .copilot-sidebar'); | ||
| } | ||
|
|
||
| function copilotEmptyState(page: Page): Locator { | ||
| return copilotSidebar(page).locator('.copilot-empty-state'); | ||
| } | ||
|
|
||
| function copilotActionItem(page: Page, id: string): Locator { | ||
| return copilotSidebar(page).locator(`.copilot-action-item[data-id="${id}"]`); | ||
| } | ||
|
|
||
| test.describe('Content Copilot', () => { | ||
|
|
||
| const IMPORTER = new EntityImporter(); | ||
|
|
||
| test.beforeAll(async ({ request }) => { | ||
| await test.step('Client Setup', async () => { | ||
| IMPORTER.setApiContext(request); | ||
| await IMPORTER.clearClient(); | ||
| }); | ||
|
|
||
| await test.step('Test Bootstrapping', async () => { | ||
| await IMPORTER.cleanupTest(); | ||
| await IMPORTER.bootstrapSuite(TestSize.MINIMAL); | ||
| }); | ||
| }); | ||
|
|
||
| test.beforeEach(async ({ request, context }) => { | ||
| await test.step('Client Setup', async () => { | ||
| IMPORTER.setApiContext(request); | ||
| await context.clearCookies(); | ||
| await IMPORTER.clearClient(); | ||
| }); | ||
|
|
||
| await test.step('Common Test Setup', async () => { | ||
| await IMPORTER.cleanupTest(); | ||
| await IMPORTER.setupTest(TestSize.MINIMAL); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Toolbar button visibility', () => { | ||
|
|
||
| test('button stays hidden when copilot.yml is missing (404)', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, null); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| // Wait for the toolbar to be present so we don't race against the | ||
| // initial render — toBeHidden / toHaveCount(0) are the defining | ||
| // assertions. | ||
| await expect(page.locator('content-frame gtx-editor-toolbar')).toBeVisible(); | ||
| await expect(copilotButton(page)).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('button stays hidden when copilot.yml has enabled: false', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_DISABLED); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await expect(page.locator('content-frame gtx-editor-toolbar')).toBeVisible(); | ||
| await expect(copilotButton(page)).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('button appears when copilot.yml has enabled: true and a page is in edit mode', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await expect(copilotButton(page)).toBeVisible(); | ||
| }); | ||
|
|
||
| test('button stays hidden as long as no page is opened in edit mode', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| // Deliberately NOT opening a page — we should still be on the | ||
| // folder list, where there is no editor toolbar at all. | ||
| await expect(copilotButton(page)).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('button stays hidden when an invalid copilot.yml is served', async ({ page }) => { | ||
| // Missing required `id` on the action — the parser falls back to | ||
| // the disabled default, so the button must NOT appear. | ||
| const invalid = 'enabled: true\nactions:\n - label: incomplete\n'; | ||
| await openEditorWithCopilot(page, IMPORTER, invalid); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await expect(page.locator('content-frame gtx-editor-toolbar')).toBeVisible(); | ||
| await expect(copilotButton(page)).toHaveCount(0); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Sidebar interaction', () => { | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| // Default scenario for every interaction test: feature enabled, | ||
| // no actions configured. Tests that need actions install their | ||
| // own stub before this navigation by overriding via the helper. | ||
| }); | ||
|
|
||
| test('clicking the toolbar button opens the sidebar', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| // Closed by default — verifying the precondition guards us against | ||
| // a bug where the sidebar mounts in the open state. | ||
| await expect(copilotSidebar(page)).not.toHaveClass(/is-open/); | ||
|
|
||
| await copilotButton(page).click(); | ||
|
|
||
| await expect(copilotSidebar(page)).toHaveClass(/is-open/); | ||
| }); | ||
|
|
||
| test('clicking the close icon collapses the sidebar again', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await copilotButton(page).click(); | ||
| await expect(copilotSidebar(page)).toHaveClass(/is-open/); | ||
|
|
||
| await copilotSidebar(page).locator('[data-action="copilot-close"]').click(); | ||
|
|
||
| await expect(copilotSidebar(page)).not.toHaveClass(/is-open/); | ||
| }); | ||
|
|
||
| test('clicking the toolbar button a second time toggles the sidebar closed', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await copilotButton(page).click(); | ||
| await expect(copilotSidebar(page)).toHaveClass(/is-open/); | ||
|
|
||
| await copilotButton(page).click(); | ||
|
|
||
| await expect(copilotSidebar(page)).not.toHaveClass(/is-open/); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Sidebar contents', () => { | ||
|
|
||
| test('shows the empty-state when actions: []', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await copilotButton(page).click(); | ||
|
|
||
| await expect(copilotEmptyState(page)).toBeVisible(); | ||
| await expect(copilotSidebar(page).locator('.copilot-action-item')).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('renders one card per configured action with id, label, icon, description', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_WITH_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await copilotButton(page).click(); | ||
|
|
||
| // Empty state must NOT be on the page once we have actions. | ||
| await expect(copilotEmptyState(page)).toHaveCount(0); | ||
|
|
||
| const items = copilotSidebar(page).locator('.copilot-action-item'); | ||
| await expect(items).toHaveCount(2); | ||
|
|
||
| const summarize = copilotActionItem(page, 'summarize'); | ||
| await expect(summarize).toBeVisible(); | ||
| await expect(summarize.locator('.copilot-action-label')).toHaveText('Zusammenfassen'); | ||
| await expect(summarize.locator('.copilot-action-description')) | ||
| .toHaveText('Eine kurze Zusammenfassung der Seite erstellen'); | ||
|
|
||
| const rewrite = copilotActionItem(page, 'rewrite-tone'); | ||
| await expect(rewrite).toBeVisible(); | ||
| await expect(rewrite.locator('.copilot-action-label')).toHaveText('Tonalität anpassen'); | ||
| }); | ||
|
|
||
| test('chat input is rendered but disabled in this UI iteration', async ({ page }) => { | ||
| await openEditorWithCopilot(page, IMPORTER, YAML_ENABLED_NO_ACTIONS); | ||
| await openPageForEditing(page, IMPORTER.get(PAGE_ONE) as CmsPage); | ||
|
|
||
| await copilotButton(page).click(); | ||
|
|
||
| const textarea = copilotSidebar(page).locator('.copilot-chat-textarea'); | ||
| await expect(textarea).toBeVisible(); | ||
| await expect(textarea).toBeDisabled(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -140,6 +140,23 @@ | |
| </gtx-button> | ||
| } | ||
|
|
||
| @if (buttons.copilot) { | ||
| <gtx-button | ||
| class="primary-action copilot-button" | ||
| size="small" | ||
| flat | ||
| type="secondary" | ||
| data-action="copilot" | ||
| [class.is-active]="copilotOpen" | ||
| [attr.data-active]="copilotOpen" | ||
| [title]="'copilot.button_tooltip' | gtxI18n" | ||
| (click)="toggleCopilot()" | ||
| > | ||
| <icon left>auto_awesome</icon> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no icon named |
||
| <span class="copilot-button-label">{{ 'copilot.button_label' | gtxI18n }}</span> | ||
| </gtx-button> | ||
| } | ||
|
|
||
| @if (showSave) { | ||
| <gtx-split-button | ||
| class="primary-action save-button" | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for translatable text values is not a good way to test.
While the settings are stubed and therefore the values are known, these texts can't be directly used due to changes for
label->labelI18nanddescription->descriptionI18n.We'd first need to ensure a specific UI language (as it's initially determined by the browser/system language), and therefore translation texts may differ.