Repository navigation
fix(extension): restore the hijacking login strip on the laptop new tab #7035
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
7 commits
Select commit
Hold shift + click to select a range
b601bc5
fix(extension): restore the hijacking login strip on the laptop new tab
tsahimatsliah a16b635
fix(extension): move the sign-in title and CTAs into the feed header
tsahimatsliah e0474c7
fix(extension): shorten the sign-in header title
tsahimatsliah f8599aa
fix(extension): keep the sign-in header pinned while the feed scrolls
tsahimatsliah 44a5f6e
fix(extension): send the header sign-in CTAs to the webapp like the c…
tsahimatsliah 28492d7
Merge branch 'main' into fix/extension-hijacking-strip-laptop
tsahimatsliah fdcbb3d
Merge branch 'main' into fix/extension-hijacking-strip-laptop
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import { | ||
| Button, | ||
| ButtonSize, | ||
| ButtonVariant, | ||
| } from '@dailydotdev/shared/src/components/buttons/Button'; | ||
| import { | ||
| Typography, | ||
| TypographyType, | ||
| } from '@dailydotdev/shared/src/components/typography/Typography'; | ||
| import { useAuthContext } from '@dailydotdev/shared/src/contexts/AuthContext'; | ||
| import { loginHref, onboardingHref } from './onboardingHref'; | ||
|
|
||
| interface ExtensionSignInContentProps { | ||
| className?: string; | ||
| } | ||
|
|
||
| // The sign-in title and Log in / Sign up CTAs for logged-out users. Renders | ||
| // nothing until auth resolves, or once the user is logged in. | ||
| export const ExtensionSignInContent = ({ | ||
| className, | ||
| }: ExtensionSignInContentProps): ReactElement | null => { | ||
| const { isAuthReady, isLoggedIn } = useAuthContext(); | ||
|
|
||
| if (!isAuthReady || isLoggedIn) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={classNames( | ||
| 'flex w-full items-center justify-between gap-4', | ||
| className, | ||
| )} | ||
| > | ||
| <Typography | ||
| type={TypographyType.Body} | ||
| bold | ||
| className="min-w-0 flex-1 text-text-primary" | ||
| > | ||
| Sign in to personalize your feed | ||
| </Typography> | ||
| <div className="flex shrink-0 items-center gap-2"> | ||
| <Button | ||
| tag="a" | ||
| href={loginHref} | ||
| variant={ButtonVariant.Secondary} | ||
| size={ButtonSize.Small} | ||
| > | ||
| Log in | ||
| </Button> | ||
| <Button | ||
| tag="a" | ||
| href={onboardingHref} | ||
| variant={ButtonVariant.Primary} | ||
| size={ButtonSize.Small} | ||
| > | ||
| Sign up | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| import React from 'react'; | ||
| import type { ReactNode } from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import type { AuthContextData } from '@dailydotdev/shared/src/contexts/AuthContext'; | ||
| import AuthContext from '@dailydotdev/shared/src/contexts/AuthContext'; | ||
| import { useLaptopLayout } from '@dailydotdev/shared/src/hooks/layout/useLaptopLayout'; | ||
| import loggedUser from '@dailydotdev/shared/__tests__/fixture/loggedUser'; | ||
| import MainFeedPage from './MainFeedPage'; | ||
| import { loginHref, onboardingHref } from './onboardingHref'; | ||
|
|
||
| jest.mock('next/dynamic', () => () => () => null); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/components/MainLayout', () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| topBanner, | ||
| children, | ||
| }: { | ||
| topBanner: ReactNode; | ||
| children: ReactNode; | ||
| }) => ( | ||
| <div> | ||
| <div data-testid="top-banner">{topBanner}</div> | ||
| {children} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/components/MainFeedLayout', () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| pageHeaderContent, | ||
| shortcuts, | ||
| }: { | ||
| pageHeaderContent: ReactNode; | ||
| shortcuts: ReactNode; | ||
| }) => ( | ||
| <div> | ||
| <div data-testid="page-header">{pageHeaderContent}</div> | ||
| <div data-testid="shortcuts">{shortcuts}</div> | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/components/ScrollToTopButton', () => ({ | ||
| __esModule: true, | ||
| default: () => null, | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/hooks/layout/useLaptopLayout', () => ({ | ||
| useLaptopLayout: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/hooks', () => ({ | ||
| ...jest.requireActual('@dailydotdev/shared/src/hooks'), | ||
| useFeedLayout: () => ({ shouldUseListFeedLayout: false }), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/contexts/LogContext', () => ({ | ||
| useLogContext: () => ({ logEvent: jest.fn() }), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/components/GrowthBookProvider', () => ({ | ||
| useFeaturesReadyContext: () => ({ getFeatureValue: jest.fn() }), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/contexts/SettingsContext', () => ({ | ||
| useSettingsContext: () => ({ optOutCompanion: true, showTopSites: false }), | ||
| })); | ||
|
|
||
| jest.mock( | ||
| '@dailydotdev/shared/src/features/shortcuts/hooks/useShortcutLinks', | ||
| () => ({ | ||
| useShortcutLinks: () => ({ shortcutLinks: [] }), | ||
| }), | ||
| ); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/contexts/DndContext', () => ({ | ||
| useDndContext: () => ({ | ||
| isActive: false, | ||
| showDnd: false, | ||
| setShowDnd: jest.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/contexts/FeedContext', () => ({ | ||
| FeedLayoutProvider: ({ children }: { children: ReactNode }) => children, | ||
| })); | ||
|
|
||
| jest.mock('@dailydotdev/shared/src/hooks/feed/useCustomDefaultFeed', () => ({ | ||
| __esModule: true, | ||
| default: () => ({ isCustomDefaultFeed: false }), | ||
| })); | ||
|
|
||
| jest.mock('./ShortcutLinks/ShortcutLinks', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="shortcut-links" />, | ||
| })); | ||
|
|
||
| jest.mock('./ExtensionTopBanners', () => ({ | ||
| ExtensionTopBanners: () => null, | ||
| })); | ||
|
|
||
| jest.mock('../companion/CompanionPopupButton', () => ({ | ||
| CompanionPopupButton: () => null, | ||
| })); | ||
|
|
||
| jest.mock('../companion/useCompanionSettings', () => ({ | ||
| useCompanionSettings: jest.fn(), | ||
| })); | ||
|
|
||
| const mockUseLaptopLayout = useLaptopLayout as jest.MockedFunction< | ||
| typeof useLaptopLayout | ||
| >; | ||
|
|
||
| const loggedOut = { | ||
| user: undefined, | ||
| isLoggedIn: false, | ||
| isAuthReady: true, | ||
| loadingUser: false, | ||
| } as unknown as AuthContextData; | ||
|
|
||
| const loggedIn = { | ||
| user: loggedUser, | ||
| isLoggedIn: true, | ||
| isAuthReady: true, | ||
| loadingUser: false, | ||
| } as unknown as AuthContextData; | ||
|
|
||
| const renderPage = ({ | ||
| auth, | ||
| isLaptop, | ||
| loginStrip, | ||
| }: { | ||
| auth: AuthContextData; | ||
| isLaptop: boolean; | ||
| loginStrip?: ReactNode; | ||
| }) => { | ||
| mockUseLaptopLayout.mockReturnValue(isLaptop); | ||
|
|
||
| return render( | ||
| <AuthContext.Provider value={auth}> | ||
| <MainFeedPage onPageChanged={jest.fn()} loginStrip={loginStrip} /> | ||
| </AuthContext.Provider>, | ||
| ); | ||
| }; | ||
|
|
||
| const loginStrip = <div data-testid="login-strip" />; | ||
|
|
||
| describe('MainFeedPage login strip', () => { | ||
| it('renders the strip above the feed and the sign-in CTAs in the page header on laptop', () => { | ||
| renderPage({ auth: loggedOut, isLaptop: true, loginStrip }); | ||
|
|
||
| expect(screen.getByTestId('top-banner')).toContainElement( | ||
| screen.getByTestId('login-strip'), | ||
| ); | ||
| expect(screen.getByTestId('shortcuts')).toBeEmptyDOMElement(); | ||
|
|
||
| const header = screen.getByTestId('page-header'); | ||
| expect(header).toHaveTextContent('Sign in to personalize your feed'); | ||
| expect(screen.getByRole('link', { name: 'Log in' })).toHaveAttribute( | ||
| 'href', | ||
| loginHref, | ||
| ); | ||
| expect(screen.getByRole('link', { name: 'Sign up' })).toHaveAttribute( | ||
| 'href', | ||
| onboardingHref, | ||
| ); | ||
| }); | ||
|
|
||
| it('renders the strip in the feed shortcuts slot below laptop', () => { | ||
| renderPage({ auth: loggedOut, isLaptop: false, loginStrip }); | ||
|
|
||
| expect(screen.getByTestId('shortcuts')).toContainElement( | ||
| screen.getByTestId('login-strip'), | ||
| ); | ||
| expect(screen.getByTestId('top-banner')).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('keeps the sign-in CTAs out of the header for a logged-in user', () => { | ||
| renderPage({ auth: loggedIn, isLaptop: true, loginStrip }); | ||
|
|
||
| expect(screen.getByTestId('top-banner')).toContainElement( | ||
| screen.getByTestId('login-strip'), | ||
| ); | ||
| expect(screen.getByTestId('page-header')).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('renders the shortcuts row and no sign-in UI on the regular new tab', () => { | ||
| renderPage({ auth: loggedIn, isLaptop: false }); | ||
|
|
||
| expect(screen.queryByTestId('login-strip')).not.toBeInTheDocument(); | ||
| expect(screen.getByTestId('shortcut-links')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('page-header')).toBeEmptyDOMElement(); | ||
| expect( | ||
| screen.queryByText('Sign in to personalize your feed'), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: once these became plain anchors, header clicks stopped showing up in analytics. Before this commit they went through
showLogin({ trigger: AuthTriggers.MainButton }), so the auth flow recorded where the click came from. Now nothing is logged before the browser leaves for the webapp. The cover strip on the same screen logsLogEvent.ClickwithTargetType.LoginButton/SignupButtonandtarget_id: 'hijacking'(HijackingLoginStrip.tsx,logClick), so a sign-up from the cover strip will be counted but one from the header CTAs on that same screen won't.Suggest adding the same
onClickclick log to both anchors, with a separatetarget_id(e.g.'hijacking_header') so the two placements can be compared. Keephrefas is.Reviewed by AI.