Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): announce the sign-in and load errors

Yudhi Armyndharis687b64f55ce2
diff --git a/dashboard/src/pages/Dashboard.test.ts b/dashboard/src/pages/Dashboard.test.ts
index cbf350bf5..1c860c512 100644
--- a/dashboard/src/pages/Dashboard.test.ts
+++ b/dashboard/src/pages/Dashboard.test.ts
@@ -233,7 +233,8 @@ test('a failed first read of the sessions still shows the error', async () => {
webhooksStatus = 200;
sessionsStatus = 502;
renderDashboard();
- await rtl.screen.findByText(/Bad Gateway/);
+ const alert = await rtl.screen.findByRole('alert');
+ assert.match(alert.textContent ?? '', /Bad Gateway/);
});
test('a non-admin key never loads the chart section', async () => {
diff --git a/dashboard/src/pages/Dashboard.tsx b/dashboard/src/pages/Dashboard.tsx
index 813b62290..be8e062c1 100644
--- a/dashboard/src/pages/Dashboard.tsx
+++ b/dashboard/src/pages/Dashboard.tsx
@@ -96,6 +96,7 @@ export function Dashboard() {
return (
<div className="dashboard" style={{ padding: '2rem' }}>
<div
+ role="alert"
style={{
background: 'rgba(239, 68, 68, 0.12)',
padding: '1rem',
diff --git a/dashboard/src/pages/Login.test.ts b/dashboard/src/pages/Login.test.ts
index cbddcd034..aa994c470 100644
--- a/dashboard/src/pages/Login.test.ts
+++ b/dashboard/src/pages/Login.test.ts
@@ -72,6 +72,17 @@ async function submitAndReadError(): Promise<string> {
return message;
}
+// The only feedback a failed sign-in gives is this message, so it has to reach a screen reader and name the field it is about.
+test('a refused sign-in is announced and tied to the key field', async () => {
+ reply = () => new Response('', { status: 401 });
+ await submitAndReadError();
+ const alert = rtl.screen.getByRole('alert');
+ assert.equal(alert.textContent, 'Invalid API key');
+ const input = rtl.screen.getByLabelText('API Key');
+ assert.equal(input.getAttribute('aria-invalid'), 'true');
+ assert.equal(input.getAttribute('aria-describedby'), alert.id);
+});
+
test('a proxy error page while the gateway is down is a connection error, not an invalid key', async () => {
reply = () => new Response('<html>502 Bad Gateway</html>', { status: 502, headers: { 'Content-Type': 'text/html' } });
assert.equal(await submitAndReadError(), 'Unable to connect to server. Please try again.');
diff --git a/dashboard/src/pages/Login.tsx b/dashboard/src/pages/Login.tsx
index 9d92506c3..b51f05830 100644
--- a/dashboard/src/pages/Login.tsx
+++ b/dashboard/src/pages/Login.tsx
@@ -103,6 +103,8 @@ export function Login({ onLogin }: LoginProps) {
onChange={e => setApiKey(e.target.value)}
placeholder={t('login.apiKeyPlaceholder')}
className={error ? 'error' : ''}
+ aria-invalid={error ? true : undefined}
+ aria-describedby={error ? 'apiKey-error' : undefined}
/>
<button
type="button"
@@ -113,7 +115,11 @@ export function Login({ onLogin }: LoginProps) {
{showKey ? <EyeOff size={20} /> : <Eye size={20} />}
</button>
</div>
- {error && <span className="error-message">{error}</span>}
+ {error && (
+ <span id="apiKey-error" className="error-message" role="alert">
+ {error}
+ </span>
+ )}
</div>
<button type="submit" className="connect-btn" disabled={isLoading}>