Skip to content

Commit

Permalink
chore(playlist-plugin): use dynamic repeat mode length in toggle calc…
Browse files Browse the repository at this point in the history
…ulation

Replaced hardcoded value '3' to improve maintainability and adapt to changes in RepeatMode.
  • Loading branch information
jboix committed Oct 22, 2024
1 parent 5ac7050 commit 8d5daf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/pillarbox-playlist/src/pillarbox-playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class PillarboxPlaylist extends Plugin {
* If omitted, the repeat mode will cycle in order through: no repeat, repeat all and repeat one.
*/
toggleRepeat(force = undefined) {
this.repeat = force ?? (this.repeat + 1) % 3;
this.repeat = force ?? (this.repeat + 1) % Object.keys(RepeatMode).length;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions packages/pillarbox-playlist/test/pillarbox-playlist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,28 @@ describe('PillarboxPlaylist', () => {
expect(srcSpy).toHaveBeenLastCalledWith(playlist[0].sources);
expect(posterSpy).toHaveBeenLastCalledWith(playlist[0].poster);
});

it('should toggle repeat mode', () => {
pillarboxPlaylist.toggleRepeat(RepeatMode.NO_REPEAT);

pillarboxPlaylist.toggleRepeat();
expect(pillarboxPlaylist.repeat).toBe(RepeatMode.REPEAT_ALL);
expect(pillarboxPlaylist.isNoRepeatMode()).toBeFalsy();
expect(pillarboxPlaylist.isRepeatAllMode()).toBeTruthy();
expect(pillarboxPlaylist.isRepeatOneMode()).toBeFalsy();

pillarboxPlaylist.toggleRepeat();
expect(pillarboxPlaylist.repeat).toBe(RepeatMode.REPEAT_ONE);
expect(pillarboxPlaylist.isNoRepeatMode()).toBeFalsy();
expect(pillarboxPlaylist.isRepeatAllMode()).toBeFalsy();
expect(pillarboxPlaylist.isRepeatOneMode()).toBeTruthy();

pillarboxPlaylist.toggleRepeat();
expect(pillarboxPlaylist.repeat).toBe(RepeatMode.NO_REPEAT);
expect(pillarboxPlaylist.isNoRepeatMode()).toBeTruthy();
expect(pillarboxPlaylist.isRepeatAllMode()).toBeFalsy();
expect(pillarboxPlaylist.isRepeatOneMode()).toBeFalsy();
});
});

describe('shuffle', () => {
Expand Down

0 comments on commit 8d5daf4

Please sign in to comment.