Skip to content
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
28 changes: 28 additions & 0 deletions frontend/src/__tests__/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,34 @@ describe('Settings Module', () => {
expect(coverageSentFor('savings-plans-compute')).toBe(20);
});

test('a rejected global PUT leaves the coverage dirty and sends no service PUTs', async () => {
await loadWithCoverage50();
(document.getElementById('setting-default-coverage') as HTMLInputElement).value = '70';
(api.updateConfig as jest.Mock).mockRejectedValueOnce(new Error('boom'));

await saveGlobalSettings({ preventDefault: jest.fn() } as unknown as Event);

expect(api.updateServiceConfig).not.toHaveBeenCalled();
expect(isUnsavedChanges()).toBe(true);
});

test('an SP card coverage whose service PUT failed stays dirty and is resent', async () => {
await loadWithCoverage50();
(document.getElementById('aws-savings-plans-compute-coverage') as HTMLInputElement).value = '70';
(api.updateServiceConfig as jest.Mock).mockImplementation(async (provider: string, svc: string) => {
if (provider === 'aws' && svc === 'savings-plans-compute') throw new Error('sp failed');
});

await saveGlobalSettings({ preventDefault: jest.fn() } as unknown as Event);
expect(isUnsavedChanges()).toBe(true);

(api.updateServiceConfig as jest.Mock).mockClear().mockResolvedValue(undefined);
await saveGlobalSettings({ preventDefault: jest.fn() } as unknown as Event);

expect(coverageSentFor('savings-plans-compute')).toBe(70);
expect(isUnsavedChanges()).toBe(false);
});

test('an empty global coverage field is rejected instead of saving 0', async () => {
await loadWithCoverage50();
(document.getElementById('setting-default-coverage') as HTMLInputElement).value = '';
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3591,9 +3591,7 @@ export async function saveGlobalSettings(e: Event): Promise<void> {
// controls. Read from the DOM when the card has the controls; fall back
// to the base row value (or the global default) otherwise so RI and
// Azure/GCP cards continue to inherit the global settings.
let coverage = defaultCoverageChanged
? settings.default_coverage
: (base?.coverage ?? settings.default_coverage);
let coverage = base?.coverage ?? settings.default_coverage;
let enabled = base?.enabled ?? true;
if ('coverageId' in field && field.coverageId) {
const rawCov = byId<HTMLInputElement>(field.coverageId)?.value ?? '';
Expand Down
Loading