Skip to content

Commit

Permalink
Display track bug (#1110)
Browse files Browse the repository at this point in the history
* Resolved Duration Bug

* Writing test for PlayerBar controller
  • Loading branch information
Yahyakiani authored Nov 29, 2021
1 parent 0dcd647 commit d657404
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { render } from '@testing-library/react';
import { SemanticICONS } from 'semantic-ui-react/dist/commonjs/generic';
import { AnyProps, setupI18Next, TestStoreProvider } from '../../../test/testUtils';
import PlayerBarContainer from '.';

describe('PlayerBar container', () => {
beforeAll(() => {
setupI18Next();
});

it('should display no time stamp if rendertrackDuration is false', () => {
const component = mountComponent({
renderTrackDuration: false
});

expect(component.getByText('00:00')).toBeNull;
});

const mountComponent = (initialStore?: AnyProps) => {
const component = render(<TestStoreProvider
initialState={initialStore ?? {
renderTrackDuration: true,
timePlayed: '-3:14',
timeToEnd: '2:43',
fill: 66,
track: 'Test song',
artist: 'Test artist',
cover: 'https://i.imgur.com/4euOws2.jpg',
volume: 60,
queue: { queueItems: [] },
playOptions: [
{ icon: ('repeat' as SemanticICONS), enabled: false, name: 'Repeat' },
{ icon: ('magic' as SemanticICONS), name: 'Autoradio' },
{ icon: ('random' as SemanticICONS), enabled: false, name: 'Shuffle' }
],
isMuted: false
}
}
>
<PlayerBarContainer />
</TestStoreProvider>);
return component;
};
});
8 changes: 8 additions & 0 deletions packages/app/app/containers/PlayerBarContainer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export const useToggleOptionCallback = (
[name, settings, toggleOption]
);

export const useTrackDurationProp = () => {
const settings = useSelector(settingsSelector);
const trackDurationSetting = _.get(settings, 'trackDuration', false);
return {
'renderTrackDuration': trackDurationSetting
};
};

export const useVolumeControlsProps = () => {
const { t } = useTranslation('option-control');
const dispatch = useDispatch();
Expand Down
6 changes: 5 additions & 1 deletion packages/app/app/containers/PlayerBarContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ import { PlayerBar } from '@nuclear/ui';
import {
usePlayerControlsProps,
useSeekbarProps,
useTrackDurationProp,
useTrackInfoProps,
useVolumeControlsProps
} from './hooks';


const PlayerBarContainer = () => {
const seekbarProps = useSeekbarProps();
const playerControlsProps = usePlayerControlsProps();
const trackInfoProps = useTrackInfoProps();
const volumeControlsProps = useVolumeControlsProps();
const trackDurationProp = useTrackDurationProp();


return (
<PlayerBar
{...seekbarProps}
{...playerControlsProps}
{...trackInfoProps}
{...volumeControlsProps}
renderTrackDuration
{...trackDurationProp}
/>
);
};
Expand Down

0 comments on commit d657404

Please sign in to comment.