-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
115 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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
3 changes: 3 additions & 0 deletions
3
src/app/layouts/default/lower-sticky-note/load-lsn-content.js
This file contains 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,3 @@ | ||
import LsnContent from './lsn-content'; | ||
|
||
export default LsnContent; |
32 changes: 0 additions & 32 deletions
32
src/app/layouts/default/lower-sticky-note/lower-sticky-note.js
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/app/layouts/default/lower-sticky-note/lower-sticky-note.tsx
This file contains 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,34 @@ | ||
import React from 'react'; | ||
import {usePutAway, useStickyData} from '../shared'; | ||
import JITLoad from '~/helpers/jit-load'; | ||
import Cookies from 'js-cookie'; | ||
|
||
const cookieKey = 'lower-sticky-note-closed'; | ||
|
||
export default function LowerStickyNote() { | ||
const stickyData = useStickyData(); | ||
const [closed, PutAway] = usePutAway(); | ||
const shouldNotDisplay = | ||
!stickyData || | ||
closed || | ||
stickyData?.mode !== 'banner' || | ||
Boolean(Cookies.get(cookieKey)); | ||
|
||
React.useEffect(() => { | ||
if (closed) { | ||
Cookies.set(cookieKey, 'true', {expires: 7}); | ||
} | ||
}, [closed]); | ||
|
||
if (shouldNotDisplay) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<JITLoad | ||
importFn={() => import('./load-lsn-content.js')} | ||
stickyData={stickyData} | ||
PutAway={PutAway as () => JSX.Element} | ||
/> | ||
); | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/app/layouts/default/microsurvey-popup/microsurvey-popup.tsx
This file contains 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 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 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 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 was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains 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,51 @@ | ||
import React from 'react'; | ||
import {render, screen} from '@testing-library/preact'; | ||
import * as S from '~/layouts/default/shared'; | ||
import LowerStickyNote from '~/layouts/default/lower-sticky-note/lower-sticky-note'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Cookies from 'js-cookie'; | ||
|
||
/* eslint-disable camelcase */ | ||
const stickyData = { | ||
mode: 'banner', | ||
start: '2024-05-10T15:00:00Z', | ||
expires: '2025-10-01T19:58:00Z', | ||
show_popup: false, | ||
header: 'Normal sticky', | ||
body: 'By giving $1, $5, or $10 you can make a meaningful impact...', | ||
link_text: 'Give now', | ||
link: 'https://google.com', | ||
emergency_expires: '2023-01-17T02:00:00Z', | ||
emergency_content: | ||
'The OpenStax offices will be closed January 16 in observance of Martin Luther King, Jr. Day.', | ||
bannerInfo: { | ||
html_message: | ||
'Help students around the world succeed with <strong>contributions of $5, $10 or $20</strong>', | ||
link_text: 'Make a difference now', | ||
link_url: 'https://dev.openstax.org/give', | ||
banner_thumbnail: | ||
'https://assets.openstax.org/oscms-dev/media/original_images/subj-icon-science.png' | ||
} | ||
}; | ||
|
||
/* eslint-disable camelcase */ | ||
describe('lower-sticky-note', () => { | ||
const user = userEvent.setup(); | ||
|
||
it('renders and closes', async () => { | ||
jest.spyOn(S, 'useStickyData').mockReturnValue(stickyData); | ||
render(<LowerStickyNote />); | ||
const closeButton = await screen.findByRole('button'); | ||
|
||
await user.click(closeButton); | ||
Cookies.remove('lower-sticky-note-closed'); | ||
}); | ||
it('renders and closes', async () => { | ||
stickyData.bannerInfo.banner_thumbnail = ''; | ||
jest.spyOn(S, 'useStickyData').mockReturnValue(stickyData); | ||
render(<LowerStickyNote />); | ||
const closeButton = await screen.findByRole('button'); | ||
|
||
await user.click(closeButton); | ||
}); | ||
}); |