Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(settings): reveal an api key so a wrong one can be fixed in place

Luis Ortiz47ca64cc56f0
diff --git a/src/ui/shared/__tests__/key-check.test.tsx b/src/ui/shared/__tests__/key-check.test.tsx
index 867ca29..64246fa 100644
--- a/src/ui/shared/__tests__/key-check.test.tsx
+++ b/src/ui/shared/__tests__/key-check.test.tsx
@@ -1,13 +1,13 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom/vitest';
-import { act, render, renderHook, screen } from '@testing-library/react';
+import { act, fireEvent, render, renderHook, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const { sendMessageMock } = vi.hoisted(() => ({ sendMessageMock: vi.fn() }));
vi.mock('@/lib/messaging', () => ({ sendMessage: sendMessageMock }));
-import { KeyStatusNote, useKeyCheck } from '@/ui/shared/key-check';
+import { KeyStatusNote, SecretInput, useKeyCheck } from '@/ui/shared/key-check';
describe('useKeyCheck', () => {
beforeEach(() => {
@@ -61,3 +61,28 @@ it('shows a distinct model-invalid note', () => {
render(<KeyStatusNote status="model-invalid" />);
expect(screen.getByText('settings.keyModelInvalid')).toBeInTheDocument();
});
+
+describe('SecretInput', () => {
+ it('hides the key until the reveal button is pressed, and hides it again', () => {
+ render(<SecretInput value="sk-secret" onChange={() => {}} placeholder="sk-..." />);
+
+ const field = screen.getByPlaceholderText('sk-...');
+ expect(field).toHaveAttribute('type', 'password');
+
+ fireEvent.click(screen.getByRole('button'));
+ expect(field).toHaveAttribute('type', 'text');
+ expect(field).toHaveValue('sk-secret');
+
+ fireEvent.click(screen.getByRole('button'));
+ expect(field).toHaveAttribute('type', 'password');
+ });
+
+ it('reports edits while revealed', () => {
+ const onChange = vi.fn();
+ render(<SecretInput value="" onChange={onChange} placeholder="sk-..." />);
+
+ fireEvent.click(screen.getByRole('button'));
+ fireEvent.change(screen.getByPlaceholderText('sk-...'), { target: { value: 'sk-typed' } });
+ expect(onChange).toHaveBeenCalledWith('sk-typed');
+ });
+});
diff --git a/src/ui/shared/key-check.tsx b/src/ui/shared/key-check.tsx
index 25b95e2..28471df 100644
--- a/src/ui/shared/key-check.tsx
+++ b/src/ui/shared/key-check.tsx
@@ -1,7 +1,8 @@
-import { Check } from 'lucide-react';
+import { Check, Eye, EyeOff } from 'lucide-react';
import { useCallback, useRef, useState } from 'react';
import { i18n } from '#imports';
import { sendMessage } from '@/lib/messaging';
+import { Input } from '@/ui/components/ui/input';
export type KeyStatus = 'checking' | 'valid' | 'rejected' | 'unreachable' | 'model-required' | 'model-invalid' | null;
@@ -105,3 +106,41 @@ export function ModelList({ models }: { models: string[] }) {
</div>
);
}
+
+export function SecretInput({
+ value,
+ onChange,
+ placeholder,
+ className,
+ buttonClassName,
+}: {
+ value: string;
+ onChange: (next: string) => void;
+ placeholder?: string;
+ className?: string;
+ buttonClassName?: string;
+}) {
+ const [revealed, setRevealed] = useState(false);
+ const Icon = revealed ? EyeOff : Eye;
+ return (
+ <div className="relative flex-1 min-w-0">
+ <Input
+ type={revealed ? 'text' : 'password'}
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ placeholder={placeholder}
+ className={`pr-8 ${className ?? ''}`}
+ />
+ <button
+ type="button"
+ onClick={() => setRevealed((on) => !on)}
+ aria-pressed={revealed}
+ aria-label={i18n.t(revealed ? 'settings.hideKey' : 'settings.showKey')}
+ title={i18n.t(revealed ? 'settings.hideKey' : 'settings.showKey')}
+ className={`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors ${buttonClassName ?? ''}`}
+ >
+ <Icon size={13} />
+ </button>
+ </div>
+ );
+}