-
Notifications
You must be signed in to change notification settings - Fork 267
WS-2008-account-header #13649
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
WS-2008-account-header #13649
Changes from all commits
d6ff225
595001c
b2bd0ee
79a4ac4
d818b76
65368d7
a7dc537
4356d8f
2b850a5
f1804ce
dcc0911
01da157
bf350dc
10ed611
6eba149
c3ff93b
38adffe
f100a9f
3c0fa84
4218832
3c25708
45b4191
322fc8a
63710fc
560359d
e107e75
5e8cb9f
1356f8e
8d0775b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # AccountHeader | ||
|
|
||
| Displays the account entry point in the header. | ||
|
|
||
| ## Behaviour | ||
| - Shows **“Sign in”** when the user is signed out | ||
| - Shows **“For you”** when the user is signed in | ||
|
|
||
| ## Data source | ||
| - Uses `AccountContext` to determine signed-in state | ||
|
|
||
| ## Storybook | ||
| - `Signed Out` | ||
| - `Signed In` | ||
|
|
||
| This is an initial MVP version. Styling and IDCTA integration will follow in later tickets. |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||
| import ThemeProvider from '#app/components/ThemeProvider'; | ||||
| import { ServiceContextProvider } from '#app/contexts/ServiceContext'; | ||||
| import { AccountContext } from '#app/contexts/AccountContext'; | ||||
| import AccountHeader from '.'; | ||||
|
|
||||
| type WithProvidersArgs = { | ||||
| isSignedIn: boolean; | ||||
| }; | ||||
|
|
||||
|
||||
SantaZena marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Theme } from '@emotion/react'; | ||
|
|
||
| const styles = { | ||
| wrapper: { | ||
| marginInlineStart: 'auto', | ||
| width: '100%', | ||
| display: 'flex', | ||
| justifyContent: 'flex-end', | ||
| paddingInlineStart: '1rem', | ||
| }, | ||
|
|
||
| link: ({ palette }: Theme) => ({ | ||
| color: palette.WHITE, | ||
| textDecoration: 'none', | ||
|
|
||
| '&:hover, &:focus': { | ||
| textDecoration: 'underline', | ||
| }, | ||
| }), | ||
| }; | ||
|
|
||
| export default styles; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import Cookie from 'js-cookie'; | ||
| import { screen } from '@testing-library/react'; | ||
| import { render } from '#app/components/react-testing-library-with-providers'; | ||
| import { IdctaConfig } from '#app/models/types/account'; | ||
| import AccountHeader from '.'; | ||
|
|
||
| const idctaConfig: IdctaConfig = { | ||
| 'id-availability': 'GREEN', | ||
| unavailable_url: 'https://example.com/unavailable', | ||
| signin_url: 'https://example.com/signin', | ||
| register_url: 'https://example.com/register', | ||
| settings_url: 'https://example.com/settings', | ||
| signout_url: 'https://example.com/signout', | ||
| foryou_url: 'https://example.com/foryou', | ||
| identity: { | ||
| idSignedInCookieName: 'ckns_id', | ||
| }, | ||
| }; | ||
|
|
||
| const renderWithProviders = () => | ||
| render(<AccountHeader />, { | ||
| service: 'ws', | ||
| idctaConfig, | ||
| }); | ||
|
|
||
| describe('AccountHeader', () => { | ||
| afterEach(() => { | ||
| Cookie.remove('ckns_id'); | ||
| }); | ||
|
|
||
| it('shows Sign in when signed out', async () => { | ||
| renderWithProviders(); | ||
|
|
||
| const link = await screen.findByRole('link', { name: 'Sign In' }); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| expect.stringContaining('https://example.com/signin'), | ||
| ); | ||
| }); | ||
|
|
||
| it('shows For you when signed in', async () => { | ||
| Cookie.set('ckns_id', '1'); | ||
|
|
||
| renderWithProviders(); | ||
|
|
||
| const link = await screen.findByRole('link', { name: 'For you' }); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| expect.stringContaining('https://example.com/foryou'), | ||
| ); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { use } from 'react'; | ||
| import { AccountContext } from '#contexts/AccountContext'; | ||
| import { ServiceContext } from '#contexts/ServiceContext'; | ||
| import Text from '#app/components/Text'; | ||
| import styles from './index.styles'; | ||
|
|
||
| const AccountHeader = () => { | ||
| const { isSignedIn, signInUrl, forYouUrl } = use(AccountContext); | ||
| const { translations } = use(ServiceContext); | ||
|
|
||
| const href = isSignedIn ? forYouUrl : signInUrl; | ||
SantaZena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!href) return null; | ||
|
|
||
| const label = isSignedIn | ||
| ? (translations?.account?.forYou ?? 'For you') | ||
| : (translations?.account?.signIn ?? 'Sign In'); | ||
|
|
||
| return ( | ||
| <div css={styles.wrapper}> | ||
| <Text as="a" css={styles.link} href={href}> | ||
HarveyPeachey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {label} | ||
| </Text> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AccountHeader; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,10 @@ export const service: DefaultServiceConfig = { | |
| instructions: 'You can download and view today’s news.', | ||
| title: 'File Download', | ||
| }, | ||
| account: { | ||
| signIn: 'Sign In', | ||
| forYou: 'For you', | ||
|
Comment on lines
+106
to
+107
|
||
| }, | ||
| gist: 'सारांश', | ||
| error: { | ||
| 404: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.