Remove tic tac toe
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
function getStoredSecret() {
|
||||
try {
|
||||
return localStorage.getItem('secret') || '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function createSecretInput() {
|
||||
const id = 'secret-input';
|
||||
|
||||
@@ -10,6 +18,7 @@ export function createSecretInput() {
|
||||
input.type = 'password';
|
||||
input.name = 'secret';
|
||||
input.placeholder = 'Enter your secret…';
|
||||
input.value = getStoredSecret();
|
||||
|
||||
label.htmlFor = id;
|
||||
label.textContent = 'Secret';
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
import { describe, expect, it, beforeEach } from 'vitest';
|
||||
import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest';
|
||||
import { screen } from '@testing-library/dom';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { createSecretInput } from './secret-input.js';
|
||||
|
||||
describe.todo('createSecretInput', async () => {});
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
|
||||
describe('createSecretInput', async () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(localStorage, 'getItem').mockReturnValue('test secret');
|
||||
vi.spyOn(localStorage, 'setItem');
|
||||
|
||||
document.body.innerHTML = '';
|
||||
document.body.appendChild(createSecretInput());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should have loaded the secret from localStorage', async () => {
|
||||
expect(screen.getByLabelText('Secret')).toHaveValue('test secret');
|
||||
expect(localStorage.getItem).toHaveBeenCalledWith('secret');
|
||||
});
|
||||
|
||||
it('should save the secret to localStorage', async () => {
|
||||
const input = screen.getByLabelText('Secret');
|
||||
const button = screen.getByText('Store Secret');
|
||||
|
||||
await userEvent.clear(input);
|
||||
await userEvent.type(input, 'new secret');
|
||||
await userEvent.click(button);
|
||||
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith('secret', 'new secret');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user