Repository: streamlit/streamlit
File: frontend/app/src/App.test.tsx (TypeScript)

Code before:

          expect(props.theme.addThemes).toHaveBeenCalledTimes(1)
          // Should set theme to update with full server config while preserving Light selection (FIX FOR #13280)
          expect(props.theme.setTheme).toHaveBeenCalledWith(
            expect.objectContaining({
              name: CUSTOM_THEME_LIGHT_NAME,
              displayName: "Light",
            })
          )

          window.localStorage.removeItem(LocalStore.ACTIVE_THEME)
        })
      })
    })
  })

  describe("embed_options with custom themes", () => {
    let windowSpy: MockInstance

    beforeEach(() => {
      window.localStorage.clear()
    })

    afterEach(() => {
      windowSpy?.mockRestore()
    })

    it("respects embed_options=light_theme over cached dark preference", () => {
      // Set cached theme to dark
      const cachedTheme: CachedTheme = {
        name: CUSTOM_THEME_DARK_NAME,
      }
      window.localStorage.setItem(
        LocalStore.ACTIVE_THEME,
        JSON.stringify(cachedTheme)
      )

      // Mock query params with light_theme
      windowSpy = mockWindow(
        windowLocationSearch("?embed=true&embed_options=light_theme")
      )

      const props = getProps()
      renderApp(props)

      // Send custom theme config with light and dark sections
      const customTheme = new CustomThemeConfig({
        primaryColor: "blue",
        light: {
          backgroundColor: "white",
        },

Review comment (suggestion):
**Suggestion**: Perhaps it would be cleaner to do:
```javascript
 let prevWindowLocation: Location

  beforeEach(() => {
    window.localStorage.clear()
    prevWindowLocation = window.location
  })

  afterEach(() => {
    Object.defineProperty(window, "location", {
      value: prevWindowLocation,
      writable: true,
      configurable: true,
    })
  })

  const setLocationSearch = (search: string): void => {
    Object.defineProperty(window, "location", {
      value: {
        ...prevWindowLocation,
        search,
        href: `http://localhost${search}`,
      },
      writable: true,
      configurable: true,
    })
  }
```

Code after:
            customTheme: themeInput,
          })

          expect(props.theme.addThemes).toHaveBeenCalledTimes(1)
          // Should set theme to update with full server config while preserving Light selection (FIX FOR #13280)
          expect(props.theme.setTheme).toHaveBeenCalledWith(
            expect.objectContaining({
              name: CUSTOM_THEME_LIGHT_NAME,
              displayName: "Light",
            })
          )

          window.localStorage.removeItem(LocalStore.ACTIVE_THEME)
        })
      })
    })
  })

  describe("embed_options with custom themes", () => {
    let prevWindowLocation: Location

    beforeEach(() => {
      window.localStorage.clear()
      prevWindowLocation = window.location
    })

    afterEach(() => {
      Object.defineProperty(window, "location", {
        value: prevWindowLocation,
        writable: true,
        configurable: true,
      })
    })

    const setLocationSearch = (search: string): void => {
      Object.defineProperty(window, "location", {
        value: {
          ...prevWindowLocation,
          search,
          href: `http://localhost/${search}`,
        },
        writable: true,
        configurable: true,
      })
    }

    const customTheme = new CustomThemeConfig({
      primaryColor: "blue",
      light: {
        backgroundColor: "white",
      },