#4 Added set of unit tests to ensure functionality of currently implemented behaviour
This commit is contained in:
29
src/lib/api/weatherservice.test.ts
Normal file
29
src/lib/api/weatherservice.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { aviationWeatherApi } from './weatherservice';
|
||||
|
||||
describe('aviationWeatherApi', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('fetches METAR data successfully', async () => {
|
||||
const mockMetar = { icaoId: 'EGKK', temp: 20 };
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(mockMetar)
|
||||
}));
|
||||
|
||||
const result = await aviationWeatherApi.fetchMetar('EGKK');
|
||||
expect(result).toEqual(mockMetar);
|
||||
expect(fetch).toHaveBeenCalledWith('/api/metar/EGKK');
|
||||
});
|
||||
|
||||
it('throws error if fetch fails', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
statusText: 'Not Found'
|
||||
}));
|
||||
|
||||
await expect(aviationWeatherApi.fetchMetar('XXXX')).rejects.toThrow('Failed to fetch METAR: Not Found');
|
||||
});
|
||||
});
|
@@ -9,6 +9,12 @@
|
||||
perspective: 800px;
|
||||
}
|
||||
|
||||
.loaderText {
|
||||
position: absolute;
|
||||
top: calc(50% - 84px);
|
||||
left: calc(50% - 64px);
|
||||
}
|
||||
|
||||
.inner {
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
@@ -66,6 +72,9 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="loaderText">
|
||||
Loading...
|
||||
</div>
|
||||
<div class="loader">
|
||||
<div class="inner one"></div>
|
||||
<div class="inner two"></div>
|
||||
|
12
src/routes/page.svelte.test.ts
Normal file
12
src/routes/page.svelte.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { render } from '@testing-library/svelte';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import Page from './+page.svelte';
|
||||
|
||||
describe('Main Page', () => {
|
||||
it('renders the page without HTTP error codes', () => {
|
||||
const { container } = render(Page);
|
||||
// Check that common HTTP error codes are not present in the rendered output
|
||||
const html = container.innerHTML;
|
||||
expect(html).not.toMatch(/404|500|403|401|bad request|not found|internal server error/i);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user