Skip to content

Commit

Permalink
added front end unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Sep 4, 2021
1 parent 6ba0488 commit afe31f4
Show file tree
Hide file tree
Showing 22 changed files with 2,369 additions and 50 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_URL='http://localhost:8001/api/v1'
15 changes: 11 additions & 4 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def receive_before_update(mapper, connection, target):
"http://localhost:8000",
"http://localhost:3000",
"http://127.0.0.1:8080",
"http://localhost",
]

app.add_middleware(
Expand Down Expand Up @@ -262,15 +263,21 @@ def update_playlist_id(playlist: schemas.PlaylistId,

@app.get("/api/v1/latest_playlists")
def get_latest_playlists(top_n: int, db: Session = Depends(get_db)):
db_items = db.query(models.Playlist).order_by(desc(
models.Playlist.created)).limit(top_n).all()
try:
db_items = db.query(models.Playlist).order_by(desc(
models.Playlist.created)).limit(top_n).all()
except:
return []
return db_items


@app.get("/api/v1/top_playlists")
def get_top_playlists(top_n: int, db: Session = Depends(get_db)):
db_items = db.query(models.Playlist).order_by(
desc(models.Playlist.av_rating)).limit(top_n).all()
try:
db_items = db.query(models.Playlist).order_by(
desc(models.Playlist.av_rating)).limit(top_n).all()
except:
return []
return db_items


Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^12.1.10",
"bootstrap": "5.0.2",
"bootswatch": "^5.1.0",
Expand Down Expand Up @@ -56,5 +56,8 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:8000"
"proxy": "http://localhost:8000",
"devDependencies": {
"react-test-renderer": "^17.0.2"
}
}
3 changes: 2 additions & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
yarn build
export SQLALCHEMY_DATABASE_URL=sqlite:///:memory:
export CUDA_VISIBLE_DEVICES=""
pipenv run "pytest backend"
export CI=true
yarn test
5 changes: 1 addition & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// TODO
//
// frontend:
// unit tests
// ico file
// fix warnings for unique key
// fix warning about combining h2 and a in Banner
// fix warnings in test
//
// backend:
// handle exceptions in db (e.g., no playlists)
// set seed in noise
// bug in join the dots?

Expand Down
18 changes: 18 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen, fireEvent } from "@testing-library/react";
import React from "react";
import { MemoryRouter } from "react-router-dom";
import App from "./App";

test("Test app routing", async () => {
const { asFragment } = render(<App />, { wrapper: MemoryRouter });
fireEvent.click(screen.getByText("Create playlist"));
expect(asFragment()).toMatchSnapshot();
fireEvent.click(screen.getByText("Top rated playlists"));
expect(asFragment()).toMatchSnapshot();
fireEvent.click(screen.getByText("Latest playlists"));
expect(asFragment()).toMatchSnapshot();
fireEvent.click(screen.getByText("Search playlists"));
expect(asFragment()).toMatchSnapshot();
fireEvent.click(screen.getByText("About"));
expect(asFragment()).toMatchSnapshot();
});
Loading

0 comments on commit afe31f4

Please sign in to comment.