mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 15:12:13 +08:00

* separate playwright into its own folder * better separation * add login scenario, add tags * remove ui option * update CODEOWNERS * add a panels suite test * migrate queries test to playwright * rename + add dashlist test * add panelEdit_base * add geomap map controls test * add geomap-layer-types * add geomap-spatial-operations tests * add frontend-sandbox-panel tests * add smoke-tests-suite * add comment about adding datasource * add dashboard-browse-nested * add dashboard-browse * add dashboard-export-json * add dashboard-keybindings test * remove @wip tag * turn on screenshots and add comment for why this test fails * add dashboard-links-without-slug test * try adding permissions in the test as well * add dashboard-live-streaming * context in the test doesn't work - sad * create dashboard-public-templating * add dashboard-public-create and make live streaming more resilient * add share externally test * add dashboard-share-internally * add share-snapshot-create test * add dashboard-templating * add timepicker tests * add embedded-dashboard test * add general_dashboards test * add import-dashboard test * add load-options-from-url test * add new-constant-variable test * add custom-variable test * add new-datasource-variable test * add new-interval-variable test * add text-box-variable test * add new-query-variable test * add horizontal repeat test * add panel-vertical-repeat test * add empty-row-repeat test * add set-options-from-ui test * add snapshot-create test * add templating test * add textbox-variables test * add cloud-plugins-suite * add storybook verification tests * add playwright storybook verification workflow * add playwright browsers * update CODEOWNERS * test change to trigger storybook verification workflows * try container instead * get the version right... * go back to installing - less chance of forgetting to update * Basic Github Actions Squashed commit of the following: commit f84c650a71bba339da7f96303292717569d4caa6 Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 13:23:46 2025 +0100 add arg for sharding, but not using it yet commit 7bcf0512c6652e079757e7f892d1802eb255a6a7 Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 12:30:30 2025 +0100 less newline commit b6439118829a09a4c8c49d7692d38df0dff7e7ae Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 12:24:31 2025 +0100 less logs commit 38f871e9c235344f12ef31121fdfced549c5323c Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 10:00:26 2025 +0100 fix yaml commit db9a773136eff40a82beb3b2f55f73ab0d07a717 Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 09:57:47 2025 +0100 clean up files commit c0525f41fa8b498f2fdf71b5047301b0e2945498 Author: joshhunt <josh.hunt@grafana.com> Date: Tue Jul 1 09:44:56 2025 +0100 gha workflow commit 895bea7c527bfbb148a421b9283fa0805f6ab11d Author: joshhunt <josh.hunt@grafana.com> Date: Mon Jun 30 19:33:08 2025 +0100 working dagger commit cea1f8443738e9e4b375c065dd4a1e466036bb74 Author: joshhunt <josh.hunt@grafana.com> Date: Mon Jun 30 16:17:46 2025 +0100 wip * shard gha * some tidy up * add flags for exporting results, and a gha step to merge runs * fix shard gha * add dashboard-duplicate-panel test * add dashboard-outline test * add dashboards-add-panel * remove some commented out code * add dashboards-title-description test * add dashboards-remove-panel * don't install cypress * gha: check playwright results * add dashboards-edit-adhoc-variables test * fix check-jobs * add dagger cloud token * add dagger cloud token * add edit-datasource-variable test * update CODEOWNERS * add dashboards-edit-group-by-variables (skipped for now) * add dashboards-edit-panel-title-description test * add dashboards-edit-transparent-bg test * add dashboards-edit-query-variables test * run with 8 shards * add dashboards-edit-variables * tidy up gha * add dashboard-group-panels * fix action * try to cache the grafana build * fix missing action becuase no checkout, use builtin continue-on-error instead * fix missing id * cat out.txt * debug build cache * fix debug build cache * add dashboards-panel-layouts test * tidy up * no more debug * fix grafana dir * add dashboards-move-panel test * skip some failing tests * mark up plugins tests with @plugins tag, only run @plugins tests in drone * Hackathon/Playwright Conversion - Various Suite (#107516) * Playwright Migration: Various Suite tests * skipping bad tests * fix some tests that can fail * fix uid * separate user for the verify-i18n test * build test plugins for grafana server * properly blur input fields * login manually * get dashboardPage from goto * ignore a couple of type assertions * remove a couple of timeouts * remove timeouts on dashboard-share-internally * use toBeHidden * make dashboard-share-internally more stable * remove TEMP_DAGGER_TOKEN * clean up visaulization-suggestions * unskip gauge test * unskip trace-view-scrolling * attempt to make create variable utils stable * unskip loki tests * make go linter happy * unskip edit-group-by-variables test * unskip move panel tests * isolate dashboard-timepicker tests with separate user * create data source as part of smoke test * make sure we're awaiting in dashboard-edit-adhoc-variables * make dashboards-edit-variables test more robust * Hackathon Playwright: Dashboards Search (#107580) * Hackathon Playwright: Dashboards Search * Feedback changes * make trace-view-scrolling more stable * add json report and bench step * fix bench version * move fail step to after the playwright report so we can report test failures * fix output file name * fix typo * try wrap in expect.poll * stability * bit more tidy up * fix dashboard-new-layouts tests * move test-plugins to e2e-playwright * fix go code for drone e2e run * move loki plugin-e2e test * make v2 dashboards work again --------- Co-authored-by: joshhunt <josh.hunt@grafana.com> Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com> Co-authored-by: Collin Fingar <collin.fingar@grafana.com> Co-authored-by: Jeff Levin <jeff@levinology.com>
394 lines
16 KiB
TypeScript
394 lines
16 KiB
TypeScript
import { test, expect } from '@grafana/plugin-e2e';
|
|
|
|
test.describe(
|
|
'Migrate to Cloud (On-prem)',
|
|
{
|
|
tag: ['@various', '@wip'],
|
|
},
|
|
() => {
|
|
test.describe('with mocked calls to the API backend', () => {
|
|
test.afterEach(async ({ page }) => {
|
|
const disconnectButton = page.getByTestId('migrate-to-cloud-summary-disconnect-button');
|
|
await expect(disconnectButton).toBeVisible();
|
|
await disconnectButton.click();
|
|
});
|
|
|
|
const SESSION_UID = 'fehq6hqd246iox';
|
|
const SNAPSHOT_UID1 = 'cehq6vdjqbqbkx';
|
|
|
|
const SNAPSHOT_RESULTS = [
|
|
{ name: 'FolderA', type: 'FOLDER', refId: 'ref-id-folder-a', parentName: 'General' },
|
|
{ name: 'FolderB', type: 'FOLDER', refId: 'ref-id-folder-b', parentName: 'General' },
|
|
{ name: 'Prometheus', type: 'DATASOURCE', refId: 'prometheus' },
|
|
{ name: 'Postgres', type: 'DATASOURCE', refId: 'postgres' },
|
|
{ name: 'Loki', type: 'DATASOURCE', refId: 'loki' },
|
|
{ name: 'Alert Rule A', type: 'ALERT_RULE', refId: 'alert-rule-a', parentName: 'FolderA' },
|
|
{ name: 'Alert Rule B', type: 'ALERT_RULE', refId: 'alert-rule-b', parentName: 'FolderB' },
|
|
{ name: 'Alert Rule C', type: 'ALERT_RULE', refId: 'alert-rule-c', parentName: 'FolderB' },
|
|
{ name: 'Alert Rule Group A', type: 'ALERT_RULE_GROUP', refId: 'alert-rule-group-a', parentName: 'FolderA' },
|
|
{ name: 'Alert Rule Group B', type: 'ALERT_RULE_GROUP', refId: 'alert-rule-group-b', parentName: 'FolderB' },
|
|
{ name: 'Contact Point A', type: 'CONTACT_POINT', refId: 'contact-point-a' },
|
|
{ name: 'Contact Point B', type: 'CONTACT_POINT', refId: 'contact-point-b' },
|
|
{ name: 'Contact Point C', type: 'CONTACT_POINT', refId: 'contact-point-c' },
|
|
{ name: 'Notification Policy A', type: 'NOTIFICATION_POLICY', refId: 'notification-policy-a' },
|
|
{ name: 'Notification Template A', type: 'NOTIFICATION_TEMPLATE', refId: 'notification-template-a' },
|
|
{ name: 'Notification Template B', type: 'NOTIFICATION_TEMPLATE', refId: 'notification-template-b' },
|
|
{ name: 'Notification Template C', type: 'NOTIFICATION_TEMPLATE', refId: 'notification-template-c' },
|
|
{ name: 'Plugin A', type: 'PLUGIN', refId: 'plugin-a' },
|
|
{ name: 'Plugin B', type: 'PLUGIN', refId: 'plugin-b' },
|
|
{ name: 'Plugin C', type: 'PLUGIN', refId: 'plugin-c' },
|
|
{ name: 'Mute Timing A', type: 'MUTE_TIMING', refId: 'mute-timing-a' },
|
|
{ name: 'Mute Timing B', type: 'MUTE_TIMING', refId: 'mute-timing-b' },
|
|
];
|
|
|
|
const MIGRATION_SESSION = {
|
|
uid: SESSION_UID,
|
|
slug: 'test-slug',
|
|
created: '2025-04-02T21:36:08+02:00',
|
|
updated: '2025-04-02T21:36:08+02:00',
|
|
};
|
|
|
|
const STATS = {
|
|
types: SNAPSHOT_RESULTS.reduce<Record<string, number>>((acc, r) => {
|
|
acc[r.type] = (acc[r.type] || 0) + 1;
|
|
return acc;
|
|
}, {}),
|
|
statuses: {
|
|
PENDING: SNAPSHOT_RESULTS.length,
|
|
},
|
|
total: SNAPSHOT_RESULTS.length,
|
|
};
|
|
|
|
// TODO: fix the test. It makes it most of the way through. Probably a network mock issue.
|
|
test.skip('creates and uploads a snapshot successfully', async ({ page }) => {
|
|
// Visit the migrate to cloud onprem page
|
|
await page.goto('/admin/migrate-to-cloud');
|
|
|
|
// Open the connect modal and enter the token
|
|
const connectButton = page.getByTestId('migrate-to-cloud-connect-session-modal-button');
|
|
await expect(connectButton).toBeVisible();
|
|
await connectButton.click();
|
|
|
|
const tokenInput = page.getByTestId('migrate-to-cloud-connect-session-modal-token-input');
|
|
await expect(tokenInput).toBeVisible();
|
|
await tokenInput.focus();
|
|
await tokenInput.fill('test');
|
|
|
|
// Mock API responses
|
|
await page.route(/api\/cloudmigration\/migration/, async (route) => {
|
|
if (route.request().method() === 'POST') {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(MIGRATION_SESSION),
|
|
});
|
|
} else if (route.request().method() === 'GET') {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
sessions: [MIGRATION_SESSION],
|
|
}),
|
|
});
|
|
}
|
|
});
|
|
|
|
await page.route(/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshots\?page=1&limit=1/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
snapshots: [],
|
|
}),
|
|
});
|
|
});
|
|
|
|
// Click the connect button to create the token
|
|
const connectSessionButton = page.getByTestId('migrate-to-cloud-connect-session-modal-connect-button');
|
|
await expect(connectSessionButton).toBeVisible();
|
|
await connectSessionButton.click();
|
|
|
|
// Check the 'Include all' resources checkbox
|
|
const includeAllCheckbox = page.getByTestId(
|
|
'migrate-to-cloud-configure-snapshot-checkbox-resource-include-all'
|
|
);
|
|
await includeAllCheckbox.check({ force: true });
|
|
await expect(includeAllCheckbox).toBeChecked();
|
|
|
|
// And validate that all resources are indeed checked
|
|
for (const resourceType of [
|
|
'alert_rule',
|
|
'alert_rule_group',
|
|
'contact_point',
|
|
'dashboard',
|
|
'datasource',
|
|
'folder',
|
|
'library_element',
|
|
'mute_timing',
|
|
'notification_policy',
|
|
'notification_template',
|
|
'plugin',
|
|
]) {
|
|
const checkbox = page.getByTestId(
|
|
`migrate-to-cloud-configure-snapshot-checkbox-resource-${resourceType.toLowerCase()}`
|
|
);
|
|
await expect(checkbox).toBeChecked();
|
|
}
|
|
|
|
// Remove one of the resources that has dependencies
|
|
// Mute Timings are dependencies of Alert Rules, which are dependencies of Alert Rule Groups
|
|
const muteTimingCheckbox = page.getByTestId(
|
|
'migrate-to-cloud-configure-snapshot-checkbox-resource-mute_timing'
|
|
);
|
|
await muteTimingCheckbox.uncheck({ force: true });
|
|
await expect(muteTimingCheckbox).not.toBeChecked();
|
|
|
|
// Validate that those resources are now unchecked
|
|
for (const resourceType of ['alert_rule', 'alert_rule_group', 'include-all']) {
|
|
const checkbox = page.getByTestId(
|
|
`migrate-to-cloud-configure-snapshot-checkbox-resource-${resourceType.toLowerCase()}`
|
|
);
|
|
await expect(checkbox).not.toBeChecked();
|
|
}
|
|
|
|
// Check everything again because we can
|
|
await includeAllCheckbox.check({ force: true });
|
|
await expect(includeAllCheckbox).toBeChecked();
|
|
|
|
// Validate that those resources are now checked again
|
|
for (const resourceType of ['alert_rule', 'alert_rule_group', 'mute_timing']) {
|
|
const checkbox = page.getByTestId(
|
|
`migrate-to-cloud-configure-snapshot-checkbox-resource-${resourceType.toLowerCase()}`
|
|
);
|
|
await expect(checkbox).toBeChecked();
|
|
}
|
|
|
|
// Mock snapshot creation
|
|
await page.route(/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshot/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
uid: SNAPSHOT_UID1,
|
|
}),
|
|
});
|
|
});
|
|
|
|
await page.route(/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshots\?page=1&limit=1/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
snapshots: [
|
|
{
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: 'CREATING',
|
|
created: '2025-04-02T21:40:23+02:00',
|
|
finished: '0001-01-01T00:00:00Z',
|
|
},
|
|
],
|
|
}),
|
|
});
|
|
});
|
|
|
|
let getSnapshotCalled = false;
|
|
await page.route(
|
|
/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshot\/${SNAPSHOT_UID1}\?resultPage=1&resultLimit=50/,
|
|
async (route) => {
|
|
if (!getSnapshotCalled) {
|
|
getSnapshotCalled = true;
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: 'CREATING',
|
|
created: '2025-04-02T21:40:23+02:00',
|
|
finished: '0001-01-01T00:00:00Z',
|
|
results: [],
|
|
stats: {
|
|
types: {},
|
|
statuses: {},
|
|
total: 0,
|
|
},
|
|
}),
|
|
});
|
|
} else {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: 'PENDING_UPLOAD',
|
|
created: '2025-04-02T21:40:23+02:00',
|
|
finished: '0001-01-01T00:00:00Z',
|
|
results: SNAPSHOT_RESULTS.map((r) => ({ ...r, status: 'PENDING' })),
|
|
stats: STATS,
|
|
}),
|
|
});
|
|
}
|
|
}
|
|
);
|
|
|
|
// Build the snapshot
|
|
const buildSnapshotButton = page.getByTestId('migrate-to-cloud-configure-snapshot-build-snapshot-button');
|
|
await expect(buildSnapshotButton).toBeVisible();
|
|
await buildSnapshotButton.click();
|
|
|
|
// Mock upload
|
|
const uploadSnapshot = await page.route(
|
|
/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshot\/${SNAPSHOT_UID1}\/upload/,
|
|
async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: true }),
|
|
});
|
|
}
|
|
);
|
|
|
|
// Upload the snapshot
|
|
const uploadButton = page.getByTestId('migrate-to-cloud-summary-upload-snapshot-button');
|
|
await expect(uploadButton).toBeVisible();
|
|
|
|
await uploadButton.focus();
|
|
await uploadButton.click({ force: true });
|
|
|
|
// Mock uploading status
|
|
const getSnapshotListUploading = await page.route(
|
|
/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshots\?page=1&limit=1/,
|
|
async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
snapshots: [
|
|
{
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: 'UPLOADING',
|
|
created: '2025-04-02T21:40:23+02:00',
|
|
finished: '0001-01-01T00:00:00Z',
|
|
},
|
|
],
|
|
}),
|
|
});
|
|
}
|
|
);
|
|
|
|
// Simulate the snapshot being uploaded
|
|
let getSnapshotUploadingCalls = 0;
|
|
const getSnapshotUploading = await page.route(
|
|
/api\/cloudmigration\/migration\/${SESSION_UID}\/snapshot\/${SNAPSHOT_UID1}\?resultPage=1&resultLimit=50/,
|
|
async (route) => {
|
|
if (getSnapshotUploadingCalls <= 1) {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: getSnapshotUploadingCalls === 1 ? 'PROCESSING' : 'UPLOADING',
|
|
created: '2025-04-02T21:40:23+02:00',
|
|
finished: '0001-01-01T00:00:00Z',
|
|
results: SNAPSHOT_RESULTS.map((r) => ({ ...r, status: 'PENDING' })),
|
|
stats: STATS,
|
|
}),
|
|
});
|
|
getSnapshotUploadingCalls++;
|
|
} else {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
uid: SNAPSHOT_UID1,
|
|
sessionUid: SESSION_UID,
|
|
status: 'FINISHED',
|
|
created: '2025-03-27T12:00:00Z',
|
|
finished: '2025-03-27T12:00:00Z',
|
|
results: SNAPSHOT_RESULTS.map((r) => ({ ...r, status: 'OK' })),
|
|
stats: {
|
|
types: STATS.types,
|
|
statuses: SNAPSHOT_RESULTS.reduce(
|
|
(acc, r) => {
|
|
const status = (r as { status?: string }).status || 'UNKNOWN';
|
|
acc[status] = (acc[status] || 0) + 1;
|
|
return acc;
|
|
},
|
|
{} as Record<string, number>
|
|
),
|
|
total: SNAPSHOT_RESULTS.length,
|
|
},
|
|
}),
|
|
});
|
|
}
|
|
}
|
|
);
|
|
|
|
await uploadSnapshot;
|
|
await getSnapshotListUploading;
|
|
await getSnapshotUploading;
|
|
|
|
// At least some of the items are marked with "Uploaded to cloud" status
|
|
await expect(page.getByText('Uploaded to cloud')).toBeVisible();
|
|
|
|
// We can now reconfigure the snapshot
|
|
const reconfigureButton = page.getByTestId('migrate-to-cloud-summary-reconfigure-snapshot-button');
|
|
await expect(reconfigureButton).toBeVisible();
|
|
await reconfigureButton.click();
|
|
|
|
// Check the 'Include all' resources checkbox
|
|
await includeAllCheckbox.check({ force: true });
|
|
await expect(includeAllCheckbox).toBeChecked();
|
|
});
|
|
});
|
|
|
|
test.describe('with a fake GMS backend implementation', () => {
|
|
test.afterEach(async ({ page }) => {
|
|
const disconnectButton = page.getByTestId('migrate-to-cloud-summary-disconnect-button');
|
|
await expect(disconnectButton).toBeVisible();
|
|
await disconnectButton.click();
|
|
});
|
|
|
|
// Manually crafted base64 token for testing, does not contain any sensitive data
|
|
const TEST_TOKEN =
|
|
'eyJUb2tlbiI6ImdsY19kZXZfZXlKdklqb2lNVEl6TkNJc0ltNGlPaUpuY21GbVlXNWhMV05zYjNWa0xXMXBaM0poZEdsdmJuTXRNVEl6TkNJc0ltc2lPaUowWlhOMElpd2liU0k2ZXlKeUlqb2laR1YyTFhWekxXTmxiblJ5WVd3aWZYMEsiLCJJbnN0YW5jZSI6eyJTdGFja0lEIjoxMjM0LCJTbHVnIjoidGVzdC1zbHVnIiwiUmVnaW9uU2x1ZyI6ImRldi11cy1jZW50cmFsIiwiQ2x1c3RlclNsdWciOiJkZXYtdXMtY2VudHJhbC0wIn19Cg==';
|
|
|
|
test('creates a snapshot successfully', async ({ page }) => {
|
|
// Visit the migrate to cloud onprem page
|
|
await page.goto('/admin/migrate-to-cloud');
|
|
|
|
// Open the connect modal and enter the token
|
|
const connectButton = page.getByTestId('migrate-to-cloud-connect-session-modal-button');
|
|
await expect(connectButton).toBeVisible();
|
|
await connectButton.click();
|
|
|
|
const tokenInput = page.getByTestId('migrate-to-cloud-connect-session-modal-token-input');
|
|
await expect(tokenInput).toBeVisible();
|
|
await tokenInput.focus();
|
|
await tokenInput.fill(TEST_TOKEN);
|
|
|
|
// Click the connect button to create the token
|
|
const connectSessionButton = page.getByTestId('migrate-to-cloud-connect-session-modal-connect-button');
|
|
await expect(connectSessionButton).toBeVisible();
|
|
await connectSessionButton.click();
|
|
|
|
// Build the snapshot
|
|
const buildSnapshotButton = page.getByTestId('migrate-to-cloud-configure-snapshot-build-snapshot-button');
|
|
await expect(buildSnapshotButton).toBeVisible();
|
|
await buildSnapshotButton.click();
|
|
|
|
// And the rebuild button should be visible
|
|
const reconfigureButton = page.getByTestId('migrate-to-cloud-summary-reconfigure-snapshot-button');
|
|
await expect(reconfigureButton).toBeVisible();
|
|
|
|
// We don't upload the snapshot yet because we need to create a mock server to validate the uploaded items,
|
|
// similarly to what the SMTP (tester) server does
|
|
});
|
|
});
|
|
}
|
|
);
|