-
Notifications
You must be signed in to change notification settings - Fork 302
fix(cards): free the impressions slot and fit the feed action bar to the min card width #6394
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b65475d
fix(post): hide the award button when nobody can be awarded
tsahimatsliah 450527a
fix(cards): fit the feed action bar to the 272px min card width
tsahimatsliah 3be24bd
chore(storybook): pages for the feed action bar width contract
tsahimatsliah ef8c729
Merge branch 'main' into claude/award-button-visibility-c29508
tsahimatsliah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
packages/shared/src/components/cards/common/ActionButtons.spec.tsx
This file contains hidden or 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,88 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { QueryClient } from '@tanstack/react-query'; | ||
| import ActionButtons from './ActionButtons'; | ||
| import type { ActionButtonsVariant } from './ActionButtons'; | ||
| import post from '../../../../__tests__/fixture/post'; | ||
| import { TestBootProvider } from '../../../../__tests__/helpers/boot'; | ||
| import { usePostImpressions } from '../../../hooks/post/usePostImpressions'; | ||
| import { useEngagementBarV2 } from '../../../hooks/useEngagementBarV2'; | ||
| import { useViewSize } from '../../../hooks/useViewSize'; | ||
|
|
||
| jest.mock('../../../hooks/post/usePostImpressions', () => ({ | ||
| usePostImpressions: jest.fn(), | ||
| })); | ||
|
|
||
| // jsdom reports every media query as unmatched, so the viewport is forced: | ||
| // the award gate must behave the same on both sides of the laptop breakpoint. | ||
| jest.mock('../../../hooks/useViewSize', () => ({ | ||
| ...jest.requireActual('../../../hooks/useViewSize'), | ||
| useViewSize: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../../hooks/post/usePostImpressionsModal', () => ({ | ||
| usePostImpressionsModal: () => jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../../hooks/useEngagementBarV2', () => ({ | ||
| useEngagementBarV2: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../post/PostAwardAction', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="award-action" />, | ||
| })); | ||
|
|
||
| const mockImpressions = (enabled: boolean) => | ||
| jest.mocked(usePostImpressions).mockReturnValue({ | ||
| enabled, | ||
| showImpressions: enabled, | ||
| impressions: enabled ? 1000 : 0, | ||
| }); | ||
|
|
||
| const renderComponent = (variant: ActionButtonsVariant) => | ||
| render( | ||
| <TestBootProvider client={new QueryClient()}> | ||
| <ActionButtons post={post} variant={variant} /> | ||
| </TestBootProvider>, | ||
| ); | ||
|
|
||
| const variants: ActionButtonsVariant[] = ['grid', 'list', 'signal']; | ||
|
|
||
| describe.each([ | ||
| [false, false], | ||
| [false, true], | ||
| [true, false], | ||
| [true, true], | ||
| ])('ActionButtons (v2: %s, laptop: %s)', (isV2, isLaptop) => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| jest.mocked(useEngagementBarV2).mockReturnValue(isV2); | ||
| jest.mocked(useViewSize).mockReturnValue(isLaptop); | ||
| }); | ||
|
|
||
| it.each(variants)( | ||
| 'hides the award action on a %s card when impressions are enabled', | ||
| (variant) => { | ||
| mockImpressions(true); | ||
|
|
||
| renderComponent(variant); | ||
|
|
||
| expect(screen.queryByTestId('award-action')).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole('button', { name: 'Impressions' }), | ||
| ).toBeInTheDocument(); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(variants)( | ||
| 'keeps the award action on a %s card when impressions are disabled', | ||
| (variant) => { | ||
| mockImpressions(false); | ||
|
|
||
| renderComponent(variant); | ||
|
|
||
| expect(screen.getByTestId('award-action')).toBeInTheDocument(); | ||
| }, | ||
| ); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
packages/shared/src/components/cards/common/actionCounter.ts
This file contains hidden or 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,10 @@ | ||
| import { ButtonSize } from '../../buttons/common'; | ||
| import { IconSize } from '../../Icon'; | ||
|
|
||
| // Six actions with counters have to fit the 272px min card width on their | ||
| // intrinsic widths alone, because buttons never shrink (global flex-shrink: 0). | ||
| export const FEED_ACTION_BUTTON_SIZE = ButtonSize.XSmall; | ||
| export const FEED_ACTION_ICON_SIZE = IconSize.Size16; | ||
|
|
||
| export const actionCounterClassName = 'tabular-nums typo-footnote'; | ||
| export const actionCounterLabelClassName = '!pl-0.5 pr-0.5'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.