diff --git a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx
index d8535cf791..ae513c04e0 100644
--- a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx
+++ b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx
@@ -73,8 +73,9 @@ describe('', () => {
it(`Should select ${duration}`, async () => {
const mockOnSelect = jest.fn();
const mockAggregation =
+ // Can't select an option that's already the default
DefaultPageFilters.duration === duration
- ? Duration.P1M
+ ? Duration.P30D
: DefaultPageFilters.duration;
const rendered = await renderInTestApp(
@@ -88,7 +89,6 @@ describe('', () => {
const button = getByRole(periodSelect, 'button');
UserEvent.click(button);
- await waitFor(() => rendered.getByText('Past 60 Days'));
UserEvent.click(rendered.getByTestId(`period-select-option-${duration}`));
expect(mockOnSelect).toHaveBeenLastCalledWith(duration);
});
diff --git a/plugins/cost-insights/src/utils/duration.ts b/plugins/cost-insights/src/utils/duration.ts
index 5a3fb52271..2ca2817324 100644
--- a/plugins/cost-insights/src/utils/duration.ts
+++ b/plugins/cost-insights/src/utils/duration.ts
@@ -60,10 +60,7 @@ export function exclusiveEndDateOf(
.add(1, 'day')
.format(DEFAULT_DATE_FORMAT);
case Duration.P3M:
- return moment(inclusiveEndDate)
- .utc()
- .startOf('quarter')
- .format(DEFAULT_DATE_FORMAT);
+ return quarterEndDate(inclusiveEndDate);
default:
return assertNever(duration);
}
@@ -83,3 +80,12 @@ export function inclusiveEndDateOf(
export function intervalsOf(duration: Duration, inclusiveEndDate: string) {
return `R2/${duration}/${exclusiveEndDateOf(duration, inclusiveEndDate)}`;
}
+
+function quarterEndDate(inclusiveEndDate: string): string {
+ const endDate = moment(inclusiveEndDate).utc();
+ const endOfQuarter = endDate.endOf('quarter').format(DEFAULT_DATE_FORMAT);
+ if (endOfQuarter === inclusiveEndDate) {
+ return inclusiveEndDate;
+ }
+ return endDate.startOf('quarter').format(DEFAULT_DATE_FORMAT);
+}