Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* LB-778: Don't clear add-to-playlist search input on blur The solution is: cache everything! Cache the search query and prevent it from being cleared, and cache the ACRM results for that query too. Also don't close the results on select so that users can add multiple songs easily. * Playlist search dropdonw: handle 'input-blur' event * Playlist page: add test for search select input blur * Playlist page tests: reproducible snapshot Fix a quirk with fontawesome hash ids that make the snapshots different each time. * Set timezone to GMT when running tests To solve issue with snapshots and date string formatted with toLocaleString. * Update Playlist test snapshot using GMT Using the previous commit's TZ change * Mock timeago in Playlist page tests
- Loading branch information
Showing
5 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
listenbrainz/webserver/static/js/src/__mocks__/playlistPageProps.json
This file contains 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,39 @@ | ||
{ | ||
"currentUser": { | ||
"id": 1, | ||
"name": "iliekcomputers" | ||
}, | ||
"playlist": { | ||
"playlist": { | ||
"creator": "iliekcomputers", | ||
"identifier": "https://listenbrainz.org/playlist/4245ccd3-4f0d-4276-95d6-2e09d87b5546", | ||
"date": "2021-01-04T14:43:58.359215+00:00", | ||
"title": "1980s flashback jams", | ||
"annotation": "Your lame <i>80s</i> music", | ||
"extension": { | ||
"https://musicbrainz.org/doc/jspf#playlist": { | ||
"public": true, | ||
"last_modified_at": "2021-01-18T16:44:22.837342+00:00" | ||
} | ||
}, | ||
"track": [ | ||
{ | ||
"creator": "Endless Boogie", | ||
"extension": { | ||
"https://musicbrainz.org/doc/jspf#track": { | ||
"added_at": "2020-12-24T01:41:44.821939+00:00", | ||
"added_by": "troi-bot", | ||
"artist_identifier": [ | ||
"https://musicbrainz.org/artist/bded3a41-acd7-42ff-9402-cb59e35be8f4" | ||
] | ||
} | ||
}, | ||
"identifier": "https://musicbrainz.org/recording/385f4381-0f6d-47a0-bc56-07570374f650", | ||
"title": "Vibe Killer" | ||
} | ||
] | ||
} | ||
}, | ||
"webSocketsServerUrl": "http://localhost:8081", | ||
"apiUrl": "http://0.0.0.0" | ||
} |
73 changes: 73 additions & 0 deletions
73
listenbrainz/webserver/static/js/src/playlists/Playlist.test.tsx
This file contains 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,73 @@ | ||
import { enableFetchMocks } from "jest-fetch-mock"; | ||
import * as React from "react"; | ||
import { shallow } from "enzyme"; | ||
import * as timeago from "time-ago"; | ||
import PlaylistPage from "./Playlist"; | ||
import * as playlistPageProps from "../__mocks__/playlistPageProps.json"; | ||
|
||
enableFetchMocks(); | ||
|
||
// Font Awesome generates a random hash ID for each icon everytime. | ||
// Mocking Math.random() fixes this | ||
// https://github.com/FortAwesome/react-fontawesome/issues/194#issuecomment-627235075 | ||
jest.spyOn(global.Math, "random").mockImplementation(() => 0); | ||
|
||
const { | ||
apiUrl, | ||
currentUser, | ||
playlist, | ||
webSocketsServerUrl, | ||
} = playlistPageProps; | ||
|
||
const props = { | ||
apiUrl, | ||
playlist: playlist as JSPFObject, | ||
spotify: { | ||
access_token: "heyo", | ||
permission: "streaming" as SpotifyPermission, | ||
}, | ||
currentUser, | ||
webSocketsServerUrl, | ||
}; | ||
|
||
describe("PlaylistPage", () => { | ||
it("renders correctly", () => { | ||
// Mock timeago (returns an elapsed time string) otherwise snapshot won't match | ||
timeago.ago = jest.fn().mockImplementation(() => "1 day ago"); | ||
const wrapper = shallow<PlaylistPage>(<PlaylistPage {...props} />); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
it("does not clear the add-a-track input on blur", async () => { | ||
const wrapper = shallow<PlaylistPage>(<PlaylistPage {...props} />); | ||
const instance = wrapper.instance(); | ||
let searchInput = wrapper.find(".search"); | ||
expect(instance.state.searchInputValue).toEqual(""); | ||
// @ts-ignore | ||
expect(searchInput.props().inputValue).toEqual(""); | ||
|
||
searchInput.simulate("focus"); | ||
instance.handleInputChange("mysearch", { action: "input-change" }); | ||
|
||
expect(instance.state.searchInputValue).toEqual("mysearch"); | ||
searchInput = wrapper.find(".search"); | ||
// @ts-ignore | ||
expect(searchInput.props().inputValue).toEqual("mysearch"); | ||
|
||
// simulate ReactSelect input blur event | ||
searchInput.simulate("blur"); | ||
instance.handleInputChange("", { action: "input-blur" }); | ||
|
||
searchInput = wrapper.find(".search"); | ||
expect(instance.state.searchInputValue).toEqual("mysearch"); | ||
// @ts-ignore | ||
expect(searchInput.props().inputValue).toEqual("mysearch"); | ||
|
||
// simulate ReactSelect menu close event (blur) | ||
instance.handleInputChange("", { action: "menu-close" }); | ||
|
||
searchInput = wrapper.find(".search"); | ||
expect(instance.state.searchInputValue).toEqual("mysearch"); | ||
// @ts-ignore | ||
expect(searchInput.props().inputValue).toEqual("mysearch"); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.