Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maryia/improvements for stats and tooltip #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ describe('AccumulatorsStats', () => {
expect(screen.getByText(`${CONTRACT_TYPES.STAY_IN} history`)).toBeInTheDocument();
expect(screen.getByText(stay_in_history[0])).toBeInTheDocument();
});
it('should not switch to Break out history when DECCU history is missing', () => {
mock_connect_props.ticks_history_stats.DECCU = {};
render(<AccumulatorsStats />);
expect(screen.getByText(`${CONTRACT_TYPES.STAY_IN} history`)).toBeInTheDocument();
expect(screen.getByText(stay_in_history[0])).toBeInTheDocument();

fireEvent.click(screen.getByTestId('dt_accu_stats_switcher'));
expect(screen.queryByText(`${CONTRACT_TYPES.BREAK_OUT} history`)).not.toBeInTheDocument();
expect(screen.getByText(`${CONTRACT_TYPES.STAY_IN} history`)).toBeInTheDocument();
});
it('should show manual after info icon is clicked', () => {
const { container } = render(<AccumulatorsStats />);
fireEvent.click(container.querySelector('.info'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ const AccumulatorsStats = ({ is_expandable = true, ticks_history_stats = {} }) =
const [is_collapsed, setIsCollapsed] = React.useState(true);
const [is_manual_open, setIsManualOpen] = React.useState(false);
const [displayed_contract_name, setDisplayedContractName] = React.useState(CONTRACT_TYPES.STAY_IN);
const { ACCU, DECCU } = ticks_history_stats;
const widget_title = localize('{{displayed_contract_name}} history', { displayed_contract_name });
const ticks_history =
(displayed_contract_name === CONTRACT_TYPES.STAY_IN
? ticks_history_stats.ACCU?.ticks_stayed_in
: ticks_history_stats.DECCU?.ticks_stayed_in) || [];
(displayed_contract_name === CONTRACT_TYPES.STAY_IN ? ACCU?.ticks_stayed_in : DECCU?.ticks_stayed_in) || [];
const history_text_size = isDesktop() || !is_collapsed ? 'xxs' : 'xxxs';

const rows = ticks_history.reduce((acc, _el, index) => {
Expand All @@ -42,6 +41,8 @@ const AccumulatorsStats = ({ is_expandable = true, ticks_history_stats = {} }) =
}, []);

const handleSwitchBetweenContracts = () => {
// don't switch if ACCU or DECCU history is missing
if (!ACCU?.ticks_stayed_in?.length || !DECCU?.ticks_stayed_in?.length) return;
setDisplayedContractName(Object.values(CONTRACT_TYPES).find(name => name !== displayed_contract_name));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('AccumulatorsProfitLossTooltip', () => {
className: 'profit-loss-tooltip',
};

it('should render with an arrow on the left', () => {
it('should render the right-side tooltip with an arrow on the left', () => {
const wrapper = shallow(<AccumulatorsProfitLossTooltip {...props} />);
expect(wrapper.find('.profit-loss-tooltip').exists()).to.be.true;
expect(wrapper.find('.profit-loss-tooltip__spot-circle').exists()).to.be.true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ const AccumulatorsProfitLossTooltip = ({
const won = profit > 0;
const sign = won ? '+' : '';

const getOppositeArrowPosition = React.useCallback(() => {
const opposite_arrow_position = React.useMemo(() => {
const horizontal = ['left', 'right'];
const vertical = ['top', 'bottom'];
return horizontal.includes(alignment)
? horizontal.find(el => el !== alignment)
: vertical.find(el => el !== alignment);
: ['top', 'bottom'].find(el => el !== alignment);
}, [alignment]);

const onRef = ref => {
Expand All @@ -45,7 +44,7 @@ const AccumulatorsProfitLossTooltip = ({
onMouseEnter={() => !is_tooltip_open && setIsTooltipOpen(true)}
/>
{is_tooltip_open && (
<div className={classNames(`${className}__content`, `arrow-${getOppositeArrowPosition()}`)}>
<div className={classNames(`${className}__content`, `arrow-${opposite_arrow_position}`)}>
<Text size='xxs' className={`${className}__text`}>
{localize('Total profit/loss:')}
</Text>
Expand Down