Bläddra i källkod

Tests: settings saves wait for the clicked value, not the first PUT

- Four SettingsPage tests took the first settings PUT and then checked
  a field in it; on a loaded runner the page can save the external_url
  it detects from the browser before the click lands, so that PUT had
  no such field and the test failed
- They now wait for the PUT that carries the value, as the camera-light
  and AMS alarm tests already do
maziggy 5 dagar sedan
förälder
incheckning
04d15b8dec
1 ändrade filer med 11 tillägg och 7 borttagningar
  1. 11 7
      frontend/src/__tests__/pages/SettingsPage.test.tsx

+ 11 - 7
frontend/src/__tests__/pages/SettingsPage.test.tsx

@@ -188,10 +188,11 @@ describe('SettingsPage', () => {
 
       // The page auto-saves on a 500ms debounce, so the default 1s waitFor
       // window is only just wide enough — give the request room to land.
+      // Wait for the value, not just any save: on a loaded runner the page can
+      // save the external_url it detected before the click lands.
       await waitFor(() => {
-        expect(saved).not.toBeNull();
+        expect(saved?.finish_photo_restore_plate).toBe(false);
       }, { timeout: 3000 });
-      expect(saved!.finish_photo_restore_plate).toBe(false);
     });
   });
 
@@ -260,8 +261,9 @@ describe('SettingsPage', () => {
       await new Promise((resolve) => setTimeout(resolve, 200));
       await userEvent.click(within(label.closest('div')!.parentElement!).getByRole('checkbox'));
 
+      // The save the click made, not the external_url one that can come first.
       await waitFor(() => {
-        expect(saved).not.toBeNull();
+        expect(saved?.finish_photo_restore_plate).toBe(false);
       }, { timeout: 3000 });
       expect(saved!).not.toHaveProperty('energy_cost_per_kwh');
       expect(saved!.energy_price_source).toBe('homeassistant');
@@ -1119,10 +1121,11 @@ describe('SettingsPage', () => {
 
       expect(toggle).toBeChecked();
       expect(screen.getByDisplayValue('15')).toBeInTheDocument();
+      // Wait for the value, not just any save: on a loaded runner the page can
+      // save the external_url it detected before the click lands.
       await waitFor(() => {
-        expect(saved).not.toBeNull();
+        expect(saved?.ambient_drying_sustained_minutes).toBe(15);
       }, { timeout: 3000 });
-      expect(saved!.ambient_drying_sustained_minutes).toBe(15);
     });
 
     it('clearing the field does not snap it to a value mid-edit', async () => {
@@ -2289,10 +2292,11 @@ describe('SettingsPage', () => {
       const row = label.closest('div')!.parentElement!;
       await user.click(within(row).getByRole('checkbox'));
 
+      // Wait for the value, not just any save: on a loaded runner the page can
+      // save the external_url it detected before the click lands.
       await waitFor(() => {
-        expect(saved).not.toBeNull();
+        expect(saved?.confirm_outcome_external_prints).toBe(true);
       }, { timeout: 3000 });
-      expect(saved!.confirm_outcome_external_prints).toBe(true);
     });
 
     it('reflects a value the backend already has', async () => {