mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Both contexts start as {} and nothing distinguished that from a
server that reported nothing, so for up to one poll interval after a
page load consumers rendered the negative case as fact: the Settings
form appeared with blank values and an "undefined/config/wrolpi.yaml"
path (the ready check `settings ? true : undefined` was always true),
the Downloads toggle was clickable and read "Downloading Disabled",
the upgrade panel said "up to date, vundefined", and the five hardware
toggles on the Controller page claimed "not supported on this server".
Invariants now enforced and tested:
* StatusContext.loaded is true once a poll returned a real status;
the API being down does not count. SettingsContext.loaded is true
once settings were fetched, and `failed` when a fetch returned
nothing before that; a failed refresh after a load keeps the last
known values and `loaded`.
* The Settings page shows its loader until loaded and its error only
when failed. The upgrade panel shows a loader until status loaded.
The Downloads toggle is disabled with a neutral label until then.
* A subsystem toggle is disabled without claiming "unsupported" while
status is unknown (undefined); "unsupported" (null) is reserved for
a loaded status that lacks the field. A call in flight is unknown,
not unsupported.
The context fixtures declare loaded so existing specs render as
before.
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
69 lines
3.1 KiB
JavaScript
69 lines
3.1 KiB
JavaScript
import React from 'react';
|
|
import {render, screen} from '../test-utils';
|
|
import {DisableDownloadsToggle, HotspotToggle} from './Common';
|
|
import {SettingsPage, UpgradeSegment} from './admin/Settings';
|
|
|
|
// The status and settings contexts start empty and are filled by the first poll. Until then a
|
|
// consumer must not claim a negative ("Downloading Disabled", "not supported", "up to date") or
|
|
// render a form over blank values; `loaded` on each context says whether the first poll landed.
|
|
|
|
jest.mock('../api', () => ({
|
|
...jest.requireActual('../api'),
|
|
getConfigs: jest.fn(() => new Promise(() => {
|
|
})),
|
|
}));
|
|
|
|
const unloadedStatus = {status: {}, loaded: false};
|
|
|
|
describe('DisableDownloadsToggle before status has loaded', () => {
|
|
test('is disabled and does not claim downloading is disabled', () => {
|
|
render(<DisableDownloadsToggle/>, {status: unloadedStatus});
|
|
expect(screen.getByTestId('toggle')).toBeDisabled();
|
|
expect(screen.queryByText('Downloading Disabled')).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('once loaded, reads the downloads state', () => {
|
|
render(<DisableDownloadsToggle/>, {status: {status: {downloads: {disabled: true, stopped: false}}, loaded: true}});
|
|
expect(screen.getByText('Downloading Disabled')).toBeInTheDocument();
|
|
expect(screen.getByTestId('toggle')).toBeEnabled();
|
|
});
|
|
});
|
|
|
|
describe('HotspotToggle before status has loaded', () => {
|
|
test('is disabled without claiming the hotspot is unsupported', () => {
|
|
render(<HotspotToggle/>, {status: unloadedStatus});
|
|
expect(screen.getByTestId('toggle')).toBeDisabled();
|
|
expect(screen.queryByTestId('subsystem-popup')).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('once loaded without a hotspot field, is unsupported', () => {
|
|
render(<HotspotToggle/>, {status: {status: {}, loaded: true}});
|
|
expect(screen.getByTestId('toggle')).toBeDisabled();
|
|
expect(screen.getByTestId('subsystem-popup')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('UpgradeSegment before status has loaded', () => {
|
|
test('does not claim the WROLPi is up to date', () => {
|
|
render(<UpgradeSegment/>, {status: unloadedStatus});
|
|
expect(screen.queryByText(/up to date/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('once loaded with no update, says so', () => {
|
|
render(<UpgradeSegment/>, {status: {status: {update_available: false, version: '1.0'}, loaded: true}});
|
|
expect(screen.getByText(/up to date/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('SettingsPage before settings have loaded', () => {
|
|
test('shows a loader, not a form over blank values', () => {
|
|
const {container} = render(<SettingsPage/>, {settings: {settings: {}, loaded: false, failed: false}});
|
|
expect(container.querySelector('.wrolpi-loading')).toBeInTheDocument();
|
|
expect(screen.queryByText(/Any changes will be written/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('shows an error when the settings could not be fetched', () => {
|
|
render(<SettingsPage/>, {settings: {settings: {}, loaded: false, failed: true}});
|
|
expect(screen.getByText('Unable to fetch settings')).toBeInTheDocument();
|
|
});
|
|
});
|