diff --git a/listenbrainz/webserver/static/js/src/RecentListens.test.tsx b/listenbrainz/webserver/static/js/src/RecentListens.test.tsx index 92d5303c67..1db3fb87ea 100644 --- a/listenbrainz/webserver/static/js/src/RecentListens.test.tsx +++ b/listenbrainz/webserver/static/js/src/RecentListens.test.tsx @@ -137,9 +137,50 @@ describe("receiveNewListen", () => {}); describe("receiveNewPlayingNow", () => {}); -describe("handleCurrentListenChange", () => {}); +describe("handleCurrentListenChange", () => { + it("sets the state correctly", () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + const listen: Listen = { + listened_at: 0, + track_metadata: { + artist_name: "George Erza", + track_name: "Shotgun", + }, + }; + instance.handleCurrentListenChange(listen); + + expect(wrapper.state().currentListen).toMatchObject(listen); + }); +}); + +describe("isCurrentListen", () => { + it("returns true if currentListen and passed listen is same", () => { + const wrapper = shallow(); + const instance = wrapper.instance(); -describe("isCurrentListen", () => {}); + const listen: Listen = { + listened_at: 0, + track_metadata: { + artist_name: "Coldplay", + track_name: "Up & Up", + }, + }; + wrapper.setState({ currentListen: listen }); + + expect(instance.isCurrentListen(listen)).toBe(true); + }); + + it("returns false if currentListen is not set", () => { + const wrapper = shallow(); + const instance = wrapper.instance(); + + wrapper.setState({ currentListen: undefined }); + + expect(instance.isCurrentListen({} as Listen)).toBeFalsy(); + }); +}); describe("getRecentListensForFollowList", () => {}); diff --git a/listenbrainz/webserver/static/js/src/RecentListens.tsx b/listenbrainz/webserver/static/js/src/RecentListens.tsx index 54f67ac3b1..28040fc023 100644 --- a/listenbrainz/webserver/static/js/src/RecentListens.tsx +++ b/listenbrainz/webserver/static/js/src/RecentListens.tsx @@ -45,7 +45,7 @@ export interface RecentListensProps { export interface RecentListensState { alerts: Array; canPlayMusic?: boolean; - currentListen: Listen; + currentListen?: Listen; direction: SpotifyPlayDirection; followList: Array; listId?: number; @@ -72,7 +72,6 @@ export default class RecentListens extends React.Component< this.state = { alerts: [], listens: props.listens || [], - currentListen: {} as Listen, mode: props.mode, followList: props.followList || [], playingNowByUser: {}, @@ -227,7 +226,7 @@ export default class RecentListens extends React.Component< isCurrentListen = (listen: Listen): boolean => { const { currentListen } = this.state; - return currentListen && _.isEqual(listen, currentListen); + return Boolean(currentListen && _.isEqual(listen, currentListen)); }; getRecentListensForFollowList = async () => {