-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend tests #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Frontend tests #32
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
4011a4b
add tailwind
ken-zlai f46c568
format code w/ prettier
ken-zlai 6a05ff7
add shadcn
ken-zlai 2a9aad1
add shadcn button
ken-zlai f96c4fe
use button on home page for simple counter
ken-zlai 570ba5d
npm run format
ken-zlai 2b2bddc
modify typescript rules to ignore specific errors in shadcn components
ken-zlai 53e759e
configure tailwind typography
ken-zlai 8dab5f7
Merge branch 'ken-websvc' into ken-frontend
ken-zlai 71895c7
basic dark mode config
ken-zlai d0b55ea
ignore warnings from node_modules folder
ken-zlai 1e11bc2
configure testing stuff
ken-zlai 3205caa
readme
ken-zlai afb9aea
move tests
ken-zlai 05bce39
dark mode should be applied in the app.html
ken-zlai 1c31f4a
create a reusable echart component
ken-zlai 8f5bd92
basic heatmap to start testing
ken-zlai 201dc8e
install echarts
ken-zlai 251a052
fix type issues
ken-zlai a77da82
add sheet component
ken-zlai 6d3a1e9
use resizeobserver on my echart
ken-zlai 7462ed4
refactor echart for clarity
ken-zlai b2270f6
use proper type
ken-zlai cf8c8e6
svelte 5 state
ken-zlai ea4ba7b
create SplitView.svelte
ken-zlai db32508
use SplitView to show heatmap/sidebar
ken-zlai f8060b1
Merge branch 'piyush--apis' into ken-frontend
ken-zlai fffd0ed
add table component
ken-zlai ea0cd3c
index to export table elements
ken-zlai fd3702b
add basic api
ken-zlai 7eb1bea
type for model
ken-zlai 00f3807
format code
ken-zlai dc76a03
add ModelsResponse
ken-zlai 998956a
render a basic table with models data
ken-zlai 7ab1d5d
change route structure
ken-zlai 79268df
add preview of timeseries data
ken-zlai 8e9327c
add avatar
ken-zlai 1855d2e
zipline logo
ken-zlai 3d76751
Wire up Play frontend + server in docker setup
piyush-zlai c3f728a
create a layout for the app w/ top and left bar
ken-zlai 578ed5b
move model code to model route
ken-zlai a284edb
add loading indication on nav
ken-zlai 114511f
Merge branch 'main' into ken-frontend
ken-zlai 7e7d697
Fix based on coder rabbit suggestions
piyush-zlai 557555b
Address feedback
piyush-zlai 5691a3c
Merge remote-tracking branch 'origin/piyush/docker-play' into ken-fro…
ken-zlai 34da3a4
configure frontend to build using nodejs
ken-zlai 811cb65
create a custom build for docker to use that env file
ken-zlai 6b27bd3
add a quick coming soon to the / route
ken-zlai 115faa3
zipline logo routes to / route
ken-zlai 9e63629
quick header for timeseries data
ken-zlai c7cb4a4
Merge branch 'main' into ken-frontend
ken-zlai cf2e418
remove old frontend stuff from build.sbt
ken-zlai 463eefe
update docker readme
ken-zlai 5ade424
format
ken-zlai b26c672
add link to the heatmap preview
ken-zlai 6a75611
add instructions for how to start the backend server first for dev work
ken-zlai f84133a
add tests for core api functionality
ken-zlai 6c52f28
.env files were ignored in the .gitignore - remove this
ken-zlai 4750136
cleaner way to run docker build
ken-zlai 045858f
Merge branch 'ken-frontend' into frontend-tests
ken-zlai eb11d7b
create tests that verify backend types for model
ken-zlai a6b1a47
remove comments
ken-zlai 1f7426a
Merge branch 'main' into frontend-tests
ken-zlai 5eb7ccb
delete old test file
ken-zlai 2c58662
delete old model file
ken-zlai 83f97d6
fix import
ken-zlai ea9efb0
Merge branch 'main' into frontend-tests
ken-zlai 70578df
Merge branch 'main' into frontend-tests
ken-zlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
import { get } from './api'; | ||
import { error } from '@sveltejs/kit'; | ||
|
||
// Mock the fetch function | ||
const mockFetch = vi.fn(); | ||
global.fetch = mockFetch; | ||
|
||
// Mock the error function from @sveltejs/kit | ||
vi.mock('@sveltejs/kit', () => ({ | ||
error: vi.fn() | ||
})); | ||
|
||
describe('API module', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('get function', () => { | ||
it('should make a GET request and return parsed JSON data', async () => { | ||
const mockResponse = { data: 'test data' }; | ||
mockFetch.mockResolvedValueOnce({ | ||
ok: true, | ||
text: () => Promise.resolve(JSON.stringify(mockResponse)) | ||
}); | ||
|
||
const result = await get('test-path'); | ||
|
||
expect(mockFetch).toHaveBeenCalledWith( | ||
`${import.meta.env.VITE_API_BASE_URL}/api/v1/test-path`, | ||
{ method: 'GET', headers: {} } | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should return an empty object if the response is empty', async () => { | ||
mockFetch.mockResolvedValueOnce({ | ||
ok: true, | ||
text: () => Promise.resolve('') | ||
}); | ||
|
||
const result = await get('empty-path'); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should throw an error if the response is not ok', async () => { | ||
mockFetch.mockResolvedValueOnce({ | ||
ok: false, | ||
status: 404 | ||
}); | ||
|
||
await get('error-path'); | ||
|
||
expect(error).toHaveBeenCalledWith(404); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import * as api from '$lib/api/api'; | ||
import type { ModelsResponse, TimeSeriesResponse, Model } from '$lib/types/Model/Model'; | ||
|
||
describe('Model types', () => { | ||
it('should match ModelsResponse type', async () => { | ||
const result = (await api.get('models')) as ModelsResponse; | ||
|
||
const expectedKeys = ['offset', 'items']; | ||
expect(Object.keys(result)).toEqual(expect.arrayContaining(expectedKeys)); | ||
|
||
// Log a warning if there are additional fields | ||
const additionalKeys = Object.keys(result).filter((key) => !expectedKeys.includes(key)); | ||
if (additionalKeys.length > 0) { | ||
console.warn(`Additional fields found in ModelsResponse: ${additionalKeys.join(', ')}`); | ||
} | ||
|
||
expect(Array.isArray(result.items)).toBe(true); | ||
|
||
if (result.items.length > 0) { | ||
const model = result.items[0]; | ||
const expectedModelKeys: (keyof Model)[] = [ | ||
'name', | ||
'id', | ||
'online', | ||
'production', | ||
'team', | ||
'modelType', | ||
'createTime', | ||
'lastUpdated' | ||
]; | ||
expect(Object.keys(model)).toEqual(expect.arrayContaining(expectedModelKeys)); | ||
|
||
// Log a warning if there are additional fields | ||
const additionalModelKeys = Object.keys(model).filter( | ||
(key) => !expectedModelKeys.includes(key as keyof Model) | ||
); | ||
if (additionalModelKeys.length > 0) { | ||
console.warn(`Additional fields found in Model: ${additionalModelKeys.join(', ')}`); | ||
} | ||
} | ||
}); | ||
|
||
it('should match TimeSeriesResponse type', async () => { | ||
const modelId = '0'; | ||
const result = (await api.get( | ||
`model/${modelId}/timeseries?startTs=1725926400000&endTs=1726106400000&offset=10h&algorithm=psi` | ||
)) as TimeSeriesResponse; | ||
|
||
const expectedKeys = ['id', 'items']; | ||
expect(Object.keys(result)).toEqual(expect.arrayContaining(expectedKeys)); | ||
|
||
// Log a warning if there are additional fields | ||
const additionalKeys = Object.keys(result).filter((key) => !expectedKeys.includes(key)); | ||
if (additionalKeys.length > 0) { | ||
console.warn(`Additional fields found in TimeSeriesResponse: ${additionalKeys.join(', ')}`); | ||
} | ||
|
||
expect(Array.isArray(result.items)).toBe(true); | ||
|
||
if (result.items.length > 0) { | ||
const item = result.items[0]; | ||
const expectedItemKeys = ['value', 'ts', 'label']; | ||
expect(Object.keys(item)).toEqual(expect.arrayContaining(expectedItemKeys)); | ||
|
||
// Log a warning if there are additional fields | ||
const additionalItemKeys = Object.keys(item).filter((key) => !expectedItemKeys.includes(key)); | ||
if (additionalItemKeys.length > 0) { | ||
console.warn( | ||
`Additional fields found in TimeSeriesResponse item: ${additionalItemKeys.join(', ')}` | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/src/routes/models/[slug]/observability/+page.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.