2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-06-01 18:42:05 +00:00
|
|
|
import { Response } from 'miragejs';
|
2022-02-24 20:04:40 +00:00
|
|
|
|
|
|
|
/** Scenarios
|
2022-06-01 18:42:05 +00:00
|
|
|
Config off, no data
|
|
|
|
Config on, no data
|
|
|
|
Config on, with data
|
|
|
|
Filtering (data with mounts)
|
|
|
|
Filtering (data without mounts)
|
|
|
|
Filtering (data without mounts)
|
2022-06-03 22:47:19 +00:00
|
|
|
* -- HISTORY ONLY --
|
|
|
|
Filtering different date ranges (hist only)
|
|
|
|
Upgrade warning
|
2022-06-01 18:42:05 +00:00
|
|
|
No permissions for license
|
|
|
|
Version
|
|
|
|
queries available
|
|
|
|
queries unavailable
|
|
|
|
License start date this month
|
|
|
|
*/
|
2022-02-24 20:04:40 +00:00
|
|
|
export const SELECTORS = {
|
2023-01-27 02:21:12 +00:00
|
|
|
dashboardActiveTab: '.active[data-test-dashboard]',
|
2022-02-24 20:04:40 +00:00
|
|
|
emptyStateTitle: '[data-test-empty-state-title]',
|
|
|
|
usageStats: '[data-test-usage-stats]',
|
|
|
|
dateDisplay: '[data-test-date-display]',
|
|
|
|
attributionBlock: '[data-test-clients-attribution]',
|
|
|
|
filterBar: '[data-test-clients-filter-bar]',
|
2023-05-03 01:36:15 +00:00
|
|
|
rangeDropdown: '[data-test-calendar-widget-trigger]',
|
2022-03-02 18:44:41 +00:00
|
|
|
monthDropdown: '[data-test-popup-menu-trigger="month"]',
|
|
|
|
yearDropdown: '[data-test-popup-menu-trigger="year"]',
|
|
|
|
dateDropdownSubmit: '[data-test-date-dropdown-submit]',
|
2022-06-01 18:42:05 +00:00
|
|
|
runningTotalMonthStats: '[data-test-running-total="single-month-stats"]',
|
|
|
|
runningTotalMonthlyCharts: '[data-test-running-total="monthly-charts"]',
|
|
|
|
monthlyUsageBlock: '[data-test-monthly-usage]',
|
2023-01-27 02:21:12 +00:00
|
|
|
selectedAuthMount: 'div#auth-method-search-select [data-test-selected-option] div',
|
|
|
|
selectedNs: 'div#namespace-search-select [data-test-selected-option] div',
|
2022-02-24 20:04:40 +00:00
|
|
|
};
|
|
|
|
|
2022-03-16 18:36:41 +00:00
|
|
|
export const CHART_ELEMENTS = {
|
|
|
|
entityClientDataBars: '[data-test-group="entity_clients"]',
|
|
|
|
nonEntityDataBars: '[data-test-group="non_entity_clients"]',
|
|
|
|
yLabels: '[data-test-group="y-labels"]',
|
|
|
|
actionBars: '[data-test-group="action-bars"]',
|
|
|
|
labelActionBars: '[data-test-group="label-action-bars"]',
|
|
|
|
totalValues: '[data-test-group="total-values"]',
|
|
|
|
};
|
|
|
|
|
2022-02-24 20:04:40 +00:00
|
|
|
export function sendResponse(data, httpStatus = 200) {
|
|
|
|
if (httpStatus === 403) {
|
|
|
|
return [
|
|
|
|
httpStatus,
|
|
|
|
{ 'Content-Type': 'application/json' },
|
|
|
|
JSON.stringify({ errors: ['permission denied'] }),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
if (httpStatus === 204) {
|
|
|
|
// /activity endpoint returns 204 when no data, while
|
|
|
|
// /activity/monthly returns 200 with zero values on data
|
|
|
|
return [httpStatus, { 'Content-Type': 'application/json' }];
|
|
|
|
}
|
|
|
|
return [httpStatus, { 'Content-Type': 'application/json' }, JSON.stringify(data)];
|
|
|
|
}
|
|
|
|
|
2022-06-01 18:42:05 +00:00
|
|
|
export function overrideResponse(httpStatus, data) {
|
|
|
|
if (httpStatus === 403) {
|
|
|
|
return new Response(
|
|
|
|
403,
|
|
|
|
{ 'Content-Type': 'application/json' },
|
|
|
|
JSON.stringify({ errors: ['permission denied'] })
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// /activity endpoint returns 204 when no data, while
|
|
|
|
// /activity/monthly returns 200 with zero values on data
|
|
|
|
if (httpStatus === 204) {
|
|
|
|
return new Response(204, { 'Content-Type': 'application/json' });
|
|
|
|
}
|
|
|
|
return new Response(200, { 'Content-Type': 'application/json' }, JSON.stringify(data));
|
2022-02-24 20:04:40 +00:00
|
|
|
}
|