Skip to content

Commit 8552182

Browse files
authored
test: add E2E tests for plugin metadata resource (#3247)
* test(plugin_metadata): add E2E tests for plugin metadata resource - Add POM (Page Object Model) for plugin metadata pages - Implement list page tests for navigation and search functionality - Implement CRUD tests with required fields only (simple metadata) - Implement CRUD tests with all fields (comprehensive metadata) - Tests verify add, edit, and delete operations - All 4 tests passing Closes #3089 * test(e2e): add verification after editing plugin metadata - Add API verification to confirm configuration changes persist - Verify updated fields (time_iso8601, http_user_agent) appear in saved metadata - Address review feedback requesting verification of configuration changes * test(e2e): enhance plugin metadata dialog interactions with helper functions
1 parent bb5dddb commit 8552182

File tree

4 files changed

+493
-0
lines changed

4 files changed

+493
-0
lines changed

e2e/pom/plugin_metadata.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import { uiGoto } from '@e2e/utils/ui';
18+
import { expect, type Page } from '@playwright/test';
19+
20+
const locator = {
21+
getPluginMetadataNavBtn: (page: Page) =>
22+
page.getByRole('link', { name: 'Plugin Metadata', exact: true }),
23+
getSelectPluginsBtn: (page: Page) =>
24+
page.getByRole('button', { name: 'Select Plugins' }),
25+
};
26+
27+
const assert = {
28+
isIndexPage: async (page: Page) => {
29+
await expect(page).toHaveURL((url) =>
30+
url.pathname.endsWith('/plugin_metadata')
31+
);
32+
const title = page.getByRole('heading', { name: 'Plugin Metadata' });
33+
await expect(title).toBeVisible();
34+
},
35+
};
36+
37+
const goto = {
38+
toIndex: (page: Page) => uiGoto(page, '/plugin_metadata'),
39+
};
40+
41+
export const pluginMetadataPom = {
42+
...locator,
43+
...assert,
44+
...goto,
45+
};
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import { pluginMetadataPom } from '@e2e/pom/plugin_metadata';
18+
import { e2eReq } from '@e2e/utils/req';
19+
import { test } from '@e2e/utils/test';
20+
import {
21+
uiFillMonacoEditor,
22+
uiGetMonacoEditor,
23+
uiHasToastMsg,
24+
} from '@e2e/utils/ui';
25+
import type { Locator } from '@playwright/test';
26+
import { expect } from '@playwright/test';
27+
28+
import { API_PLUGIN_METADATA } from '@/config/constant';
29+
30+
// Helper function to delete plugin metadata
31+
const deletePluginMetadata = async (req: typeof e2eReq, name: string) => {
32+
await req.delete(`${API_PLUGIN_METADATA}/${name}`).catch(() => {
33+
// Ignore errors if metadata doesn't exist
34+
});
35+
};
36+
const getMonacoEditorValue = async (editPluginDialog: Locator) => {
37+
let editorValue = '';
38+
const textarea = editPluginDialog.locator('textarea');
39+
if (await textarea.count() > 0) {
40+
editorValue = await textarea.inputValue();
41+
}
42+
if (!editorValue || editorValue.trim() === '{') {
43+
const lines = await editPluginDialog.locator('.view-line').allTextContents();
44+
editorValue = lines.join('\n').replace(/\s+/g, ' ');
45+
}
46+
if (!editorValue || editorValue.trim() === '{') {
47+
const allText = await editPluginDialog.textContent();
48+
console.log('DEBUG: editorValue fallback failed, dialog text:', allText);
49+
}
50+
return editorValue;
51+
};
52+
53+
// Helper function to close edit dialog
54+
const closeEditDialog = async (editPluginDialog: Locator) => {
55+
const buttons = await editPluginDialog.locator('button').allTextContents();
56+
console.log('DEBUG: Edit Plugin dialog buttons:', buttons);
57+
let closed = false;
58+
for (const [i, name] of buttons.entries()) {
59+
if (name.trim().toLowerCase() === 'cancel') {
60+
await editPluginDialog.locator('button').nth(i).click();
61+
closed = true;
62+
break;
63+
}
64+
}
65+
if (!closed && buttons.length > 0) {
66+
await editPluginDialog.locator('button').first().click();
67+
}
68+
};
69+
70+
test.beforeAll(async () => {
71+
await deletePluginMetadata(e2eReq, 'http-logger');
72+
});
73+
74+
test.afterAll(async () => {
75+
await deletePluginMetadata(e2eReq, 'http-logger');
76+
});
77+
78+
test('should CRUD plugin metadata with all fields', async ({ page }) => {
79+
await pluginMetadataPom.toIndex(page);
80+
await pluginMetadataPom.isIndexPage(page);
81+
82+
await test.step('add plugin metadata with comprehensive configuration', async () => {
83+
// Click Select Plugins button
84+
await pluginMetadataPom.getSelectPluginsBtn(page).click();
85+
86+
// Select Plugins dialog should appear
87+
const selectPluginsDialog = page.getByRole('dialog', {
88+
name: 'Select Plugins',
89+
});
90+
await expect(selectPluginsDialog).toBeVisible();
91+
92+
// Search for http-logger plugin
93+
const searchInput = selectPluginsDialog.getByPlaceholder('Search');
94+
await searchInput.fill('http-logger');
95+
96+
// Click Add button for http-logger
97+
await selectPluginsDialog
98+
.getByTestId('plugin-http-logger')
99+
.getByRole('button', { name: 'Add' })
100+
.click();
101+
102+
// Add Plugin dialog should appear
103+
const addPluginDialog = page.getByRole('dialog', { name: 'Add Plugin' });
104+
await expect(addPluginDialog).toBeVisible();
105+
106+
// Fill in comprehensive configuration with all available fields
107+
const pluginEditor = await uiGetMonacoEditor(page, addPluginDialog);
108+
await uiFillMonacoEditor(
109+
page,
110+
pluginEditor,
111+
JSON.stringify({
112+
log_format: {
113+
host: '$host',
114+
client_ip: '$remote_addr',
115+
request_method: '$request_method',
116+
request_uri: '$request_uri',
117+
status: '$status',
118+
body_bytes_sent: '$body_bytes_sent',
119+
request_time: '$request_time',
120+
upstream_response_time: '$upstream_response_time',
121+
},
122+
})
123+
);
124+
125+
// Click Add button
126+
await addPluginDialog.getByRole('button', { name: 'Add' }).click();
127+
128+
// Should show success message
129+
await uiHasToastMsg(page, {
130+
hasText: 'success',
131+
});
132+
133+
// Dialog should close
134+
await expect(addPluginDialog).toBeHidden();
135+
136+
// Plugin card should now be visible
137+
const httpLoggerCard = page.getByTestId('plugin-http-logger');
138+
await expect(httpLoggerCard).toBeVisible();
139+
});
140+
141+
await test.step('edit plugin metadata with extended fields', async () => {
142+
// Find the http-logger card
143+
const httpLoggerCard = page.getByTestId('plugin-http-logger');
144+
145+
// Click Edit button
146+
await httpLoggerCard.getByRole('button', { name: 'Edit' }).click();
147+
148+
// Edit Plugin dialog should appear
149+
const editPluginDialog = page.getByRole('dialog', { name: 'Edit Plugin' });
150+
await expect(editPluginDialog).toBeVisible();
151+
152+
// Verify existing configuration is shown
153+
await expect(editPluginDialog.getByText('log_format')).toBeVisible();
154+
155+
// Update the configuration with additional fields
156+
const pluginEditor = await uiGetMonacoEditor(page, editPluginDialog);
157+
await uiFillMonacoEditor(
158+
page,
159+
pluginEditor,
160+
JSON.stringify({
161+
log_format: {
162+
host: '$host',
163+
client_ip: '$remote_addr',
164+
request_method: '$request_method',
165+
request_uri: '$request_uri',
166+
status: '$status',
167+
body_bytes_sent: '$body_bytes_sent',
168+
request_time: '$request_time',
169+
upstream_response_time: '$upstream_response_time',
170+
time: '$time_iso8601',
171+
user_agent: '$http_user_agent',
172+
},
173+
})
174+
);
175+
176+
// Click Save button
177+
await editPluginDialog.getByRole('button', { name: 'Save' }).click();
178+
179+
// Should show success message
180+
await uiHasToastMsg(page, {
181+
hasText: 'success',
182+
});
183+
184+
// Dialog should close
185+
await expect(editPluginDialog).toBeHidden();
186+
});
187+
188+
await test.step('verify configuration changes were saved', async () => {
189+
// Re-open the edit dialog via UI
190+
const httpLoggerCard = page.getByTestId('plugin-http-logger');
191+
await httpLoggerCard.getByRole('button', { name: 'Edit' }).click();
192+
const editPluginDialog = page.getByRole('dialog', { name: 'Edit Plugin' });
193+
await expect(editPluginDialog).toBeVisible();
194+
195+
// Get Monaco editor value using helper
196+
const editorValue = await getMonacoEditorValue(editPluginDialog);
197+
expect(editorValue).toMatch(/"time"\s*:\s*"\$time_iso8601"/);
198+
expect(editorValue).toMatch(/"user_agent"\s*:\s*"\$http_user_agent"/);
199+
expect(editorValue).toMatch(/"host"\s*:\s*"\$host"/);
200+
expect(editorValue).toMatch(/"client_ip"\s*:\s*"\$remote_addr"/);
201+
202+
// Close the dialog using helper
203+
await closeEditDialog(editPluginDialog);
204+
await expect(editPluginDialog).toBeHidden();
205+
});
206+
207+
await test.step('delete plugin metadata', async () => {
208+
// Find the http-logger card
209+
const httpLoggerCard = page.getByTestId('plugin-http-logger');
210+
211+
// Click Delete button
212+
await httpLoggerCard.getByRole('button', { name: 'Delete' }).click();
213+
214+
// Should show success message
215+
await uiHasToastMsg(page, {
216+
hasText: 'success',
217+
});
218+
219+
// Card should be removed
220+
await expect(httpLoggerCard).toBeHidden();
221+
});
222+
});

0 commit comments

Comments
 (0)