mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Feedback, fix lint
This commit is contained in:
parent
84e73d0fbc
commit
a8df72fd28
|
@ -59,7 +59,13 @@ export const Apple2 = (props: Apple2Props) => {
|
|||
setCPU(cpu);
|
||||
apple2.reset();
|
||||
apple2.run();
|
||||
}).catch((e) => setError(e.message));
|
||||
}).catch((e) => {
|
||||
if (e instanceof Error) {
|
||||
setError(e.message);
|
||||
} else {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [props]);
|
||||
|
||||
|
|
|
@ -45,6 +45,14 @@ export const DiskII = ({ disk2, number, on, name, side }: DiskIIProps) => {
|
|||
|
||||
const hash = useHash();
|
||||
|
||||
const handleError = (e: unknown) => {
|
||||
if (e instanceof Error) {
|
||||
setError(e.message);
|
||||
} else {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const hashParts = getHashParts(hash);
|
||||
const newHash = hashParts[number];
|
||||
|
@ -53,11 +61,11 @@ export const DiskII = ({ disk2, number, on, name, side }: DiskIIProps) => {
|
|||
if (hashPart !== currentHash) {
|
||||
if (hashPart.match(/^https?:/)) {
|
||||
loadHttpFile(disk2, number, hashPart)
|
||||
.catch((e) => setError(e.message));
|
||||
.catch((e) => handleError(e));
|
||||
} else {
|
||||
const filename = `/json/disks/${hashPart}.json`;
|
||||
loadJSON(disk2, number, filename)
|
||||
.catch((e) => setError(e.message));
|
||||
.catch((e) => handleError(e));
|
||||
}
|
||||
setCurrentHash(hashPart);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ export const FileModal = ({ disk2, number, onClose, isOpen }: FileModalProps) =>
|
|||
hashParts[number] = name[1];
|
||||
await loadJSON(disk2, number, filename);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
setError(e.message);
|
||||
} else {
|
||||
|
|
|
@ -150,7 +150,7 @@ export const ModalHeader = ({ onClose, title, icon }: ModalHeaderProps) => {
|
|||
return (
|
||||
<header style={modalHeaderStyle}>
|
||||
<span style={modalTitleStyle}>
|
||||
{icon && <i className={`fas fa-${icon}`} />}
|
||||
{icon && <i className={`fas fa-${icon}`} role="img" />}
|
||||
{' '}
|
||||
{title}
|
||||
</span>
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
} from 'js/components/ErrorModal';
|
||||
|
||||
describe('ErrorModal', () => {
|
||||
it('renders when there\'s an error', () => {
|
||||
it('renders when there is an error', () => {
|
||||
const setError = jest.fn();
|
||||
render(
|
||||
<ErrorModal error="My Error" setError={setError} />
|
||||
|
@ -16,7 +16,7 @@ describe('ErrorModal', () => {
|
|||
expect(screen.queryByText('My Error')).toBeVisible();
|
||||
});
|
||||
|
||||
it('does not renders when there\'s not error', () => {
|
||||
it('does not render when there is not an error', () => {
|
||||
const setError = jest.fn();
|
||||
render(
|
||||
<ErrorModal error={undefined} setError={setError} />
|
||||
|
@ -31,7 +31,7 @@ describe('ErrorModal', () => {
|
|||
<ErrorModal error="My Error" setError={setError} />
|
||||
);
|
||||
fireEvent.click(screen.getByTitle('Close'));
|
||||
expect(setError).toHaveBeenCalled();
|
||||
expect(setError).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
|
||||
it('calls setError when OK is clicked', () => {
|
||||
|
@ -40,6 +40,6 @@ describe('ErrorModal', () => {
|
|||
<ErrorModal error="My Error" setError={setError} />
|
||||
);
|
||||
fireEvent.click(screen.getByText('OK'));
|
||||
expect(setError).toHaveBeenCalled();
|
||||
expect(setError).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,6 +22,9 @@ describe('Modal', () => {
|
|||
expect(screen.queryByRole('banner')).toBeVisible();
|
||||
expect(screen.queryByRole('banner')).toHaveTextContent('My Title');
|
||||
expect(screen.queryByText('My Content')).toBeVisible();
|
||||
|
||||
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTitle('Close')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render a title and content when not open', () => {
|
||||
|
@ -76,4 +79,19 @@ describe('Modal', () => {
|
|||
fireEvent.click(button);
|
||||
expect(onClose).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it('can have an icon', () => {
|
||||
render(
|
||||
<Modal
|
||||
title="My Title"
|
||||
isOpen={true}
|
||||
icon="warning"
|
||||
>
|
||||
<ModalContent>
|
||||
My Content
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
);
|
||||
expect(screen.getByRole('img')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user