Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

fix: flaky usage auditing tests (#73454)

Maksym Yakubych8f4727f29c1d
diff --git a/e2e/test/scenarios/metabot/usage-auditing.cy.spec.ts b/e2e/test/scenarios/metabot/usage-auditing.cy.spec.ts
index 084bed142c6..e55081edffe 100644
--- a/e2e/test/scenarios/metabot/usage-auditing.cy.spec.ts
+++ b/e2e/test/scenarios/metabot/usage-auditing.cy.spec.ts
@@ -31,12 +31,6 @@ type UsageAuditingTenants = {
robertTenant: UsageAuditingTenant;
};
-const USAGE_STATS_METRICS: UsageStatsMetric[] = [
- "conversations",
- "messages",
- "tokens",
-];
-
const METRIC_TAB_NAMES: Record<UsageStatsMetric, string> = {
conversations: "Conversations",
messages: "Messages",
@@ -122,13 +116,6 @@ const TODAY_CHART_LABELS: CompleteChartLabels = {
ip: ["10.0.0.1", "10.0.0.6", "10.0.0.7"],
};
-const YESTERDAY_CHART_LABELS: CompleteChartLabels = {
- source: ["SQL", "Documents"],
- profile: ["SQL", "Documents"],
- user: ["Robert Tableton"],
- ip: ["10.0.0.3", "10.0.0.4"],
-};
-
const PREVIOUS_WEEK_CHART_LABELS: CompleteChartLabels = {
source: ["Metabot"],
profile: ["NLQ"],
@@ -143,13 +130,6 @@ const RECENT_CHART_LABELS: CompleteChartLabels = {
ip: ["10.0.0.1", "10.0.0.2", "10.0.0.3", "10.0.0.4", "10.0.0.5"],
};
-const PREVIOUS_MONTH_CHART_LABELS: CompleteChartLabels = {
- source: ["SQL"],
- profile: ["SQL"],
- user: ["Robert Tableton"],
- ip: ["10.0.0.8"],
-};
-
const OUT_OF_BOUNDS_CHART_LABELS: ChartLabels = {
ip: ["10.0.0.99"],
};
@@ -159,13 +139,7 @@ const DATE_FILTER_CASES: Array<{
chartLabels: ChartLabels;
}> = [
{ label: "Today", chartLabels: TODAY_CHART_LABELS },
- { label: "Yesterday", chartLabels: YESTERDAY_CHART_LABELS },
{ label: "Previous week", chartLabels: PREVIOUS_WEEK_CHART_LABELS },
- { label: "Previous 7 days", chartLabels: RECENT_CHART_LABELS },
- { label: "Previous 30 days", chartLabels: RECENT_CHART_LABELS },
- { label: "Previous month", chartLabels: PREVIOUS_MONTH_CHART_LABELS },
- { label: "Previous 3 months", chartLabels: PREVIOUS_MONTH_CHART_LABELS },
- { label: "Previous 12 months", chartLabels: PREVIOUS_MONTH_CHART_LABELS },
];
const MAIN_PROFILE_LABELS: string[] = [
@@ -652,19 +626,18 @@ function clickLastTimeseriesChartDot(title: string): void {
}
function clickRowChartBarForLabel(title: string, label: string): void {
- getChartCard(title)
- .findByText(label)
- .then(($label) => {
- const rect = $label[0].getBoundingClientRect();
- // Row-chart labels are not the click target; click the bar next to the visible label.
- const target = $label[0].ownerDocument.elementFromPoint(
- rect.right + 30,
- rect.top + rect.height / 2,
- );
-
- expect(target).to.exist;
- cy.wrap(target).realClick({ force: true });
+ getChartCard(title).within(() => {
+ cy.findByTestId("row-chart-container").then(($container) => {
+ cy.findByText(label).then(($label) => {
+ const containerRect = $container[0].getBoundingClientRect();
+ const labelRect = $label[0].getBoundingClientRect();
+ const x = labelRect.right - containerRect.left + 30;
+ const y = labelRect.top - containerRect.top + labelRect.height / 2;
+
+ cy.wrap($container).realClick({ x, y, scrollBehavior: false });
+ });
});
+ });
}
function openConversationFromProfile(profileLabel: string): void {
@@ -709,22 +682,50 @@ describe("scenarios > metabot > usage auditing", () => {
assertConversationChartLabels(RECENT_CHART_LABELS);
});
- it("renders usage stats charts for every date shortcut on every metric tab", () => {
+ it("renders usage stats charts for selected date shortcuts on conversations", () => {
visitUsageStatsPage();
- USAGE_STATS_METRICS.forEach((metric) => {
- if (metric !== "conversations") {
- selectMetricTab(metric);
- }
+ const metric = "conversations";
- DATE_FILTER_CASES.forEach(({ label, chartLabels }) => {
- cy.log(`${METRIC_TAB_NAMES[metric]} date filter: ${label}`);
- selectDateFilter(label);
+ DATE_FILTER_CASES.forEach(({ label, chartLabels }) => {
+ cy.log(`${METRIC_TAB_NAMES[metric]} date filter: ${label}`);
+ selectDateFilter(label);
- assertMetricChartsRenderedForDate(metric, label);
- assertMetricChartLabels(metric, chartLabels);
- assertMetricChartLabelsAbsent(metric, OUT_OF_BOUNDS_CHART_LABELS);
- });
+ assertMetricChartsRenderedForDate(metric, label);
+ assertMetricChartLabels(metric, chartLabels);
+ assertMetricChartLabelsAbsent(metric, OUT_OF_BOUNDS_CHART_LABELS);
+ });
+ });
+
+ it("renders usage stats charts for selected date shortcuts on tokens", () => {
+ visitUsageStatsPage();
+
+ const metric = "tokens";
+ selectMetricTab(metric);
+
+ DATE_FILTER_CASES.forEach(({ label, chartLabels }) => {
+ cy.log(`${METRIC_TAB_NAMES[metric]} date filter: ${label}`);
+ selectDateFilter(label);
+
+ assertMetricChartsRenderedForDate(metric, label);
+ assertMetricChartLabels(metric, chartLabels);
+ assertMetricChartLabelsAbsent(metric, OUT_OF_BOUNDS_CHART_LABELS);
+ });
+ });
+
+ it("renders usage stats charts for selected date shortcuts on messages", () => {
+ visitUsageStatsPage();
+
+ const metric = "messages";
+ selectMetricTab(metric);
+
+ DATE_FILTER_CASES.forEach(({ label, chartLabels }) => {
+ cy.log(`${METRIC_TAB_NAMES[metric]} date filter: ${label}`);
+ selectDateFilter(label);
+
+ assertMetricChartsRenderedForDate(metric, label);
+ assertMetricChartLabels(metric, chartLabels);
+ assertMetricChartLabelsAbsent(metric, OUT_OF_BOUNDS_CHART_LABELS);
});
});
@@ -844,6 +845,8 @@ describe("scenarios > metabot > usage auditing", () => {
visitUsageStatsPage("/admin/metabot/usage-auditing?date=past7days~");
interceptConversationsApi();
+ assertMetricChartsRendered("conversations");
+
clickRowChartBarForLabel(
TENANT_CONVERSATIONS_CHART_TITLE,
bobbyTenant.name,
@@ -881,6 +884,8 @@ describe("scenarios > metabot > usage auditing", () => {
visitUsageStatsPage("/admin/metabot/usage-auditing?date=past7days~");
interceptConversationsApi();
+ assertMetricChartsRendered("conversations");
+
clickRowChartBarForLabel(
"Groups with most conversations",
"Administrators",
@@ -913,6 +918,8 @@ describe("scenarios > metabot > usage auditing", () => {
visitUsageStatsPage();
interceptConversationsApi();
+ assertMetricChartsRendered("conversations");
+
clickRowChartBarForLabel("Users with most conversations", "Bobby Tables");
waitForConversations();