Skip to content
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

User defined variables incorrectly rendered #280

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/ui/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export const CheckMkGenericAsyncSelect = function <Value extends string | (strin
const data = await autocompleter(inputValue);
if (showVariables !== false) {
for (const variable of getTemplateSrv().getVariables()) {
const variableId = variable?.id || variable.name;
data.splice(0, 0, {
value: `$${variable.id}` as Value,
label: `$${variable.id}`,
value: `$${variableId}` as Value,
label: `$${variableId}`,
isGrafanaVariable: true,
});
}
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const GRAFANA_SELECTORS = {
HOST_LABEL_FILTER_FIELD_ID: 'input_host_label',
REMOVE_FILTER: (f: string) => `button[data-test-id="cmk-oac-minus-button-${f}"]`,

AGGREGATION_FIELD_ID: 'input_Aggregation',
HOST_NAME_FILTER_FIELD_ID: 'input_Hostname',
SERVICE_FILTER_FIELD_ID: 'input_Service',
HOSTNAME_REGEX_FILTER_FIELD: 'input[data-test-id="host_name_regex-filter-input"]',
Expand All @@ -63,6 +64,13 @@ export const GRAFANA_SELECTORS = {
APPLY_CHANGES_AND_SAVE_BUTTON: 'button[data-testid="data-testid Save dashboard button"]',
SAVE_DASHBOARD_TITLE: 'input[aria-label="Save dashboard title field"]',
SAVE_BUTTON: 'button[data-testid="data-testid Save dashboard drawer button"]',

SETTINGS_BUTTON: 'button[data-testid="data-testid Dashboard settings"]',
VARIABLES_TAB: 'a[data-testid="data-testid Tab Variables"]',
ADD_VARIABLE_BUTTON: 'button[data-testid="data-testid Call to action button Add variable"]',
VARIABLE_NAME_INPUT: 'input[data-testid="data-testid Variable editor Form Name field"]',
BACK_TO_DASHBOARD_BUTTON: 'button[data-testid="data-testid Back to dashboard button"]',
ADD_VISUALIZATION_BUTTON: 'button[data-testid="data-testid Create new panel button"]',
},
};

Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/models/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,33 @@ export class DashboardPage {
async refresGraph() {
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.REFRESH_GRAPH_BUTTON).click();
}

async goToNewDashboardSettings() {
await this.page.goto(current_config.grafanaUrl + 'dashboard/new');
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.SETTINGS_BUTTON).click();
}

async addNewVariable(variableName: string) {
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.VARIABLES_TAB).click();
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.ADD_VARIABLE_BUTTON).click();
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.VARIABLE_NAME_INPUT).fill(variableName);
}

async goBackToDashboard() {
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.BACK_TO_DASHBOARD_BUTTON).click();
}

async addVisualization() {
await this.page.locator(GRAFANA_SELECTORS.DASHBOARD.ADD_VISUALIZATION_BUTTON).click();
}

async assertAggregationVariableExists(variableName: string) {
const fieldSelector = `input[id="${GRAFANA_SELECTORS.DASHBOARD.AGGREGATION_FIELD_ID}"]`;
await this.page.locator(fieldSelector).fill(variableName);
await this.expectSpinners(false);
await this.page.keyboard.press('Enter');
await this.expectSpinners(false);
await expect(this.page.getByText(variableName).first()).toBeVisible();
}
}
export default DashboardPage;
15 changes: 15 additions & 0 deletions tests/e2e/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,18 @@ test.describe('E2E tests', () => {
});
});
});

test.describe('General tests', () => {
test.slow();
test('Variables get rendered', async ({ page }) => {
const customVariableName = 'MyVariable';
const dashboardPage = new DashboardPage(page);
await dashboardPage.goToNewDashboardSettings();
await dashboardPage.addNewVariable(customVariableName);
await dashboardPage.saveDashboard();
await dashboardPage.goBackToDashboard();
await dashboardPage.addVisualization();
await dashboardPage.selectDatasource(CMK_EDITION.CEE);
await dashboardPage.assertAggregationVariableExists(customVariableName);
});
});
Loading