Cover remaining branches in api-env-switcher: unknown env, missing DOM elements
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -72,4 +72,37 @@ describe('initApiEnvSwitcher', () => {
|
||||
|
||||
expect(document.getElementById('env-base-url').textContent).toContain('/api/live')
|
||||
})
|
||||
|
||||
it('handles unknown env gracefully', () => {
|
||||
document.body.innerHTML = `
|
||||
<div id="env-switcher">
|
||||
<button data-env="unknown" class="env-btn">Unknown</button>
|
||||
</div>
|
||||
<div data-host="https://test.com">
|
||||
<p id="env-base-url">original</p>
|
||||
</div>
|
||||
<p id="env-description">original desc</p>
|
||||
`
|
||||
initApiEnvSwitcher()
|
||||
|
||||
document.querySelector('[data-env="unknown"]').click()
|
||||
|
||||
expect(document.getElementById('env-base-url').textContent).toBe('original')
|
||||
expect(document.getElementById('env-description').textContent).toBe('original desc')
|
||||
})
|
||||
|
||||
it('works without base-url and description elements', () => {
|
||||
document.body.innerHTML = `
|
||||
<div id="env-switcher">
|
||||
<button data-env="sandbox" class="env-btn">Sandbox</button>
|
||||
<button data-env="live" class="env-btn">Live</button>
|
||||
</div>
|
||||
<div data-host="https://test.com"></div>
|
||||
<span class="api-env-prefix">/api/sandbox</span>
|
||||
`
|
||||
initApiEnvSwitcher()
|
||||
|
||||
expect(() => document.querySelector('[data-env="live"]').click()).not.toThrow()
|
||||
expect(document.querySelector('.api-env-prefix').textContent).toBe('/api/live')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user