forked from WordPress/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.spec.js
More file actions
137 lines (117 loc) · 3.32 KB
/
settings.spec.js
File metadata and controls
137 lines (117 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
/**
* Internal dependencies
*/
const {
clearConnectors,
disableExperiments,
enableExperiment,
enableExperiments,
visitConnectorsPage,
visitSettingsPage,
} = require( '../../utils/helpers' );
test.describe( 'Plugin settings', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin( 'e2e-test-request-mocking' );
} );
test( 'Can visit the settings page and see error message', async ( {
admin,
page,
requestUtils,
} ) => {
// Activate the request mocking plugin.
await requestUtils.activatePlugin( 'e2e-test-request-mocking' );
// Clear out any existing Connectors.
await clearConnectors( admin, page );
// Visit the settings page.
await visitSettingsPage( admin );
// Ensure the page title is correct.
await expect(
page.locator( '.wrap h1', { hasText: 'AI' } )
).toHaveCount( 1 );
// Ensure the no AI Connectors error message is displayed.
await expect(
page.locator( '.wrap .notice-error', {
hasText:
'The AI plugin requires a valid AI Connector to function properly',
} )
).toHaveCount( 1 );
} );
test( 'Can visit the Connectors page and add a valid OpenAI Connector', async ( {
admin,
page,
requestUtils,
} ) => {
// Activate the request mocking plugin.
await requestUtils.activatePlugin( 'e2e-test-request-mocking' );
await visitConnectorsPage( admin );
// Add dummy credentials for OpenAI.
await page
.locator( '.connector-item--ai-provider-for-openai button' )
.click();
await page
.locator(
'.connector-item--ai-provider-for-openai input[type="text"]'
)
.fill( 'valid-api-key' );
// Save the credentials.
await page
.locator(
'.connector-item--ai-provider-for-openai .connector-settings button'
)
.click();
} );
test( 'Can turn on Experiments', async ( { admin, page } ) => {
// Globally disable experiments.
await disableExperiments( admin, page );
// Ensure the experiments disabled notice is displayed.
await expect(
page
.locator( '.ai-experiments__notice', {
hasText:
'Enable AI above to configure individual experiment settings',
} )
.first()
).toHaveCount( 1 );
// Globally turn on experiments.
await enableExperiments( admin, page );
// Ensure the experiments disabled notice is removed.
await expect( page.locator( '.ai-experiments__notice' ) ).toHaveCount(
0
);
// Ensure we see the editor experiments section.
await expect(
page.locator(
'.ai-experiments__card .ai-experiments__card-heading',
{
hasText: 'Editor Experiments',
}
)
).toHaveCount( 1 );
// Ensure we see the admin experiments section.
await expect(
page.locator(
'.ai-experiments__card .ai-experiments__card-heading',
{
hasText: 'Admin Experiments',
}
)
).toHaveCount( 1 );
} );
test( 'Per-experiment settings persist after disabling and re-enabling AI', async ( {
admin,
page,
} ) => {
await enableExperiments( admin, page );
await enableExperiment( admin, page, 'title-generation' );
await disableExperiments( admin, page );
await enableExperiments( admin, page );
await visitSettingsPage( admin );
await expect(
page.locator( '#wpai_feature_title-generation_enabled' )
).toBeChecked();
} );
} );