Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
63 changes: 1 addition & 62 deletions routes/ai-home/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
* WordPress dependencies
*/
import { Page } from '@wordpress/admin-ui';
import {
Button,
Card,
Icon,
Link,
Notice,
Popover,
Stack,
VisuallyHidden,
} from '@wordpress/ui';
import { Button, Card, Link, Notice, Stack } from '@wordpress/ui';
import {
DropdownMenu,
MenuGroup,
Expand All @@ -28,7 +19,6 @@ import { __, _n, sprintf } from '@wordpress/i18n';
import {
check as checkIcon,
download as downloadIcon,
info as infoIcon,
moreVertical as moreVerticalIcon,
upload as uploadIcon,
} from '@wordpress/icons';
Expand Down Expand Up @@ -263,40 +253,6 @@ const STABLE_FEATURE_DEFINITIONS: FeatureData[] = ( () => {
return unique;
} )();

interface InfoTipProps {
content: string;
}

function InfoTip( { content }: InfoTipProps ) {
const title = __( 'More information', 'ai' );

return (
<Popover.Root>
<Popover.Trigger
openOnHover
delay={ 200 }
closeDelay={ 200 }
aria-label={ title }
className="ai-settings-page__infotip-trigger"
>
<Icon icon={ infoIcon } size={ 20 } />
</Popover.Trigger>
<Popover.Popup
positioner={ <Popover.Positioner side="bottom" align="end" /> }
className="ai-settings-page__infotip-popover"
>
<Popover.Arrow />
<VisuallyHidden render={ <Popover.Title /> }>
{ title }
</VisuallyHidden>
<Popover.Description className="ai-settings-page__infotip-description">
{ content }
</Popover.Description>
</Popover.Popup>
</Popover.Root>
);
}

function buildToggleMessage(
edits: Record< string, unknown >,
featureDefinitions: FeatureData[]
Expand Down Expand Up @@ -791,10 +747,6 @@ function AISettingsPage() {
}, [ aiSettingKeys, editedRecord ] );

const globalEnabled = Boolean( data[ GLOBAL_FIELD_ID ] );
const globalToggleDescription = __(
'Control whether AI is enabled for your site. When disabled, all features and experiments will be inactive regardless of their individual settings.',
'ai'
);

const handleChange = useCallback(
async ( edits: Record< string, unknown > ) => {
Expand Down Expand Up @@ -1012,19 +964,6 @@ function AISettingsPage() {
) }
actions={
<>
<Stack align="center" gap="xs">
<ToggleControl
label={ __( 'Enable AI', 'ai' ) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we remove the display of the setting here but we don't actually remove the registration of the setting in includes/Settings/Settings_Registration.php. Should we?

checked={ globalEnabled }
onChange={ ( checked ) => {
void handleChange( {
[ GLOBAL_FIELD_ID ]: checked,
} );
} }
disabled={ isLoading }
/>
<InfoTip content={ globalToggleDescription } />
</Stack>
<Link
href="https://github.com/WordPress/ai/tree/develop/docs"
openInNewTab
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/specs/admin/import-export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ test.describe( 'Settings import/export', () => {
await dialog.getByRole( 'button', { name: 'Cancel' } ).click();
await expect( dialog ).not.toBeVisible();

// Global AI toggle must remain disabled since the import was cancelled.
await expect( page.getByLabel( 'Enable AI' ) ).not.toBeChecked();
// Title Generation toggle must remain disabled since the import was cancelled.
await expect( page.getByLabel( 'Title Generation' ) ).not.toBeChecked();
} );

test( 'Confirming the import applies settings without a page reload', async ( {
admin,
page,
} ) => {
// Start with AI disabled so the imported value is a visible change.
// Start with experiments disabled so the imported value is a visible change.
await disableExperiments( admin, page );
await expect( page.getByLabel( 'Enable AI' ) ).not.toBeChecked();
await expect( page.getByLabel( 'Title Generation' ) ).not.toBeChecked();

const filePath = writeTempExportFile( {
wpai_features_enabled: true,
wpai_title_generation_enabled: true,
} );
tempFiles.push( filePath );

Expand All @@ -234,7 +234,7 @@ test.describe( 'Settings import/export', () => {
// The toggle should reflect the imported value immediately, with no
// manual page reload required (regression guard for the stale
// core-data cache/infinite-spinner issue).
await expect( page.getByLabel( 'Enable AI' ) ).toBeChecked( {
await expect( page.getByLabel( 'Title Generation' ) ).toBeChecked( {
timeout: 10000,
} );

Expand Down
28 changes: 6 additions & 22 deletions tests/e2e/specs/admin/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,16 @@ test.describe( 'Plugin settings', () => {
} );

test( 'Can turn on Experiments', async ( { admin, page } ) => {
// Globally disable experiments.
await disableExperiments( admin, page );

// Ensure global AI setting is disabled.
await expect( page.getByLabel( 'Enable AI' ) ).not.toBeChecked();

// Ensure feature toggles are disabled when AI is disabled.
// Ensure we see the editor experiments section.
await expect(
page
.locator(
'#ai-wp-admin-app .components-form-toggle.is-disabled'
)
.first()
page.getByText( 'Editor Experiments', { exact: true } )
).toBeVisible();

// Globally turn on experiments.
await enableExperiments( admin, page );

// Ensure global AI setting is enabled.
await expect( page.getByLabel( 'Enable AI' ) ).toBeChecked();

// Ensure we see the editor experiments section.
await expect(
page.getByText( 'Editor Experiments', { exact: true } )
).toBeVisible();

// Ensure we see the admin experiments section.
await expect(
page.getByText( 'Admin Experiments', { exact: true } )
Expand All @@ -143,10 +127,10 @@ test.describe( 'Plugin settings', () => {
await page.setViewportSize( { width: 1280, height: 800 } );
await visitSettingsPage( admin );

// Toggle the global setting to trigger a snackbar.
const globalToggle = page.getByLabel( 'Enable AI' );
await expect( globalToggle ).toBeVisible( { timeout: 10000 } );
await globalToggle.click();
// Toggle a feature setting to trigger a snackbar.
const featureToggle = page.getByLabel( 'Title Generation' );
await expect( featureToggle ).toBeVisible( { timeout: 10000 } );
await featureToggle.click();

const snackbar = page.getByTestId( 'snackbar' ).first();
await expect( snackbar ).toBeVisible();
Expand Down
44 changes: 16 additions & 28 deletions tests/e2e/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,16 @@
export const disableExperiments = async ( admin: Admin, page: Page ) => {
await visitSettingsPage( admin );

// Wait for page to fully load before finding the global toggle.
const globalToggle = page.getByLabel( 'Enable AI' );
await expect( globalToggle ).toBeVisible( { timeout: 10000 } );
await expect( globalToggle ).toBeEnabled( { timeout: 10000 } );

// Nothing to do if experiments are already disabled.
if ( ! ( await globalToggle.isChecked() ) ) {
return;
const disableAllButtons = page.getByRole( 'button', {
name: 'Disable all',
} );
const count = await disableAllButtons.count();
for ( let i = 0; i < count; i++ ) {
const button = disableAllButtons.nth( i );
if ( await button.isEnabled() ) {
await button.click();
}
}
await globalToggle.uncheck();
await expect(
page.locator( '.components-snackbar__content', {
hasText: 'AI disabled.',
} )
).toBeVisible();
};

/**
Expand All @@ -189,21 +184,14 @@
export const enableExperiments = async ( admin: Admin, page: Page ) => {
await visitSettingsPage( admin );

// Wait for page to fully load before finding the global toggle.
const globalToggle = page.getByLabel( 'Enable AI' );
await expect( globalToggle ).toBeVisible( { timeout: 10000 } );
await expect( globalToggle ).toBeEnabled( { timeout: 10000 } );

// Nothing to do if experiments are already enabled.
if ( await globalToggle.isChecked() ) {
return;
const enableAllButtons = page.getByRole( 'button', { name: 'Enable all' } );
const count = await enableAllButtons.count();
for ( let i = 0; i < count; i++ ) {
const button = enableAllButtons.nth( i );
if ( await button.isEnabled() ) {
await button.click();
}
}
await globalToggle.check();
await expect(
page.locator( '.components-snackbar__content', {
hasText: 'AI enabled.',
} )
).toBeVisible();
};

/**
Expand All @@ -222,7 +210,7 @@

const toggle = page.getByLabel( experimentLabel );
await expect( toggle ).toBeVisible( { timeout: 10000 } );
await expect( toggle ).toBeEnabled( { timeout: 10000 } );

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:169:2 › core/read-content ability (client-side Abilities API) › limits each post to the requested fields

4) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:169:2 › core/read-content ability (client-side Abilities API) › limits each post to the requested fields Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one

3) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one

3) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one

3) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:158:2 › core/read-content ability (client-side Abilities API) › rejects a page beyond the last one Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page

2) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page

2) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page

2) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:129:2 › core/read-content ability (client-side Abilities API) › paginates with page and per_page Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type

1) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type

1) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

Check failure on line 213 in tests/e2e/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests

[chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type

1) [chromium] › tests/e2e/specs/abilities/core-read-content.spec.js:99:2 › core/read-content ability (client-side Abilities API) › returns a posts list of the requested post type Error: expect(locator).toBeEnabled() failed Locator: getByLabel('Excerpt Generation') Expected: enabled Received: disabled Timeout: 10000ms Call log: - Expect "toBeEnabled" with timeout 10000ms - waiting for getByLabel('Excerpt Generation') 24 × locator resolved to <input disabled type="checkbox" id="inspector-toggle-control-17" class="components-form-toggle__input" aria-describedby="inspector-toggle-control-17__help"/> - unexpected value "disabled" at ../utils/helpers.ts:213 211 | const toggle = page.getByLabel( experimentLabel ); 212 | await expect( toggle ).toBeVisible( { timeout: 10000 } ); > 213 | await expect( toggle ).toBeEnabled( { timeout: 10000 } ); | ^ 214 | 215 | // Nothing to do if this experiment is already enabled. 216 | if ( await toggle.isChecked() ) { at enableExperiment (/home/runner/work/ai/ai/tests/e2e/utils/helpers.ts:213:25) at /home/runner/work/ai/ai/tests/e2e/specs/abilities/core-read-content.spec.js:88:3

// Nothing to do if this experiment is already enabled.
if ( await toggle.isChecked() ) {
Expand Down
Loading