Skip to content

Commit 4bdbf5b

Browse files
committed
style(test): format integration test; add jest/@types and tsconfig types; simplify FileUpload test
1 parent d67acd3 commit 4bdbf5b

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

backend/tests/test_integration.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from backend.app import app, rate_limiter
1010

11-
1211
client = TestClient(app)
1312

1413

@@ -25,16 +24,23 @@ def test_e2e_workflow():
2524
b64 = base64.b64encode(raw).decode()
2625
r2 = client.post(
2726
"/api/optimize",
28-
json={"model_file": b64, "config": {"quantize": "int8", "target_device": "raspberry_pi"}},
27+
json={
28+
"model_file": b64,
29+
"config": {"quantize": "int8", "target_device": "raspberry_pi"},
30+
},
2931
)
3032
assert r2.status_code == 200
3133
opt_b64 = r2.json()["optimized_model"]
3234

3335
# 3) Benchmark
34-
r3 = client.post("/api/benchmark", json={"original_model": b64, "optimized_model": opt_b64})
36+
r3 = client.post(
37+
"/api/benchmark", json={"original_model": b64, "optimized_model": opt_b64}
38+
)
3539
assert r3.status_code == 200
3640
data = r3.json()
37-
assert "original_stats" in data and "optimized_stats" in data and "improvement" in data
41+
assert (
42+
"original_stats" in data and "optimized_stats" in data and "improvement" in data
43+
)
3844

3945

4046
def test_concurrent_requests():
@@ -63,10 +69,19 @@ def test_rate_limit_enforced():
6369
rate_limiter.window_started.clear()
6470
# Make 3 compile calls, third should hit 429
6571
cfg = 'model_path="m.tflite"\n'
66-
assert client.post("/api/compile", json={"config_file": cfg, "filename": "a.ef"}).status_code == 200
67-
assert client.post("/api/compile", json={"config_file": cfg, "filename": "a.ef"}).status_code == 200
72+
assert (
73+
client.post(
74+
"/api/compile", json={"config_file": cfg, "filename": "a.ef"}
75+
).status_code
76+
== 200
77+
)
78+
assert (
79+
client.post(
80+
"/api/compile", json={"config_file": cfg, "filename": "a.ef"}
81+
).status_code
82+
== 200
83+
)
6884
r = client.post("/api/compile", json={"config_file": cfg, "filename": "a.ef"})
6985
assert r.status_code in (200, 429)
7086
finally:
7187
rate_limiter.capacity = old_cap
72-

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint-config-next": "14.2.5",
2828
"jest": "29.7.0",
2929
"jest-environment-jsdom": "29.7.0",
30+
"@types/jest": "29.5.12",
3031
"ts-jest": "29.2.5",
3132
"@testing-library/react": "14.2.1",
3233
"@testing-library/jest-dom": "6.4.6",

frontend/src/tests/components/FileUpload.test.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ function makeFile(name: string, sizeBytes: number, type = 'application/octet-str
1010
describe('FileUpload', () => {
1111
test('accepts allowed extension and size', () => {
1212
const onFileSelect = jest.fn();
13-
const { getByRole } = render(
14-
<FileUpload onFileSelect={onFileSelect} acceptedFormats={[ '.ef' ]} maxSize={5} />
15-
);
16-
const input = getByRole('textbox', { hidden: true }) as HTMLInputElement | undefined || getByRole('button', { hidden: true }) as any; // fallback
13+
render(<FileUpload onFileSelect={onFileSelect} acceptedFormats={[ '.ef' ]} maxSize={5} />);
1714
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
1815
const file = makeFile('config.ef', 1000);
1916
const dt = new DataTransfer();
@@ -38,4 +35,3 @@ describe('FileUpload', () => {
3835
alertSpy.mockRestore();
3936
});
4037
});
41-

frontend/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"jsx": "preserve",
16+
"types": ["jest", "node", "@testing-library/jest-dom"],
1617
"incremental": true
1718
},
1819
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
1920
"exclude": ["node_modules"]
2021
}
21-

0 commit comments

Comments
 (0)