-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into MBMS-78950-remove-prod-flag-from-78949
- Loading branch information
Showing
8 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
54 changes: 54 additions & 0 deletions
54
src/applications/static-pages/situation-updates-banner/createSituationUpdatesBanner.jsx
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,54 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
import { useFeatureToggle } from '~/platform/utilities/feature-toggles'; | ||
import SituationUpdateBanner from './situationUpdateBanner'; | ||
|
||
export const BannerContainer = () => { | ||
const { | ||
TOGGLE_NAMES, | ||
useToggleValue, | ||
useToggleLoadingValue, | ||
} = useFeatureToggle(); | ||
|
||
const alternativeBannersEnabled = useToggleValue( | ||
TOGGLE_NAMES.bannerUseAlternativeBanners, | ||
); | ||
const isLoadingFeatureFlags = useToggleLoadingValue(); | ||
|
||
if (isLoadingFeatureFlags || !alternativeBannersEnabled) { | ||
return null; | ||
} | ||
|
||
const defaultProps = { | ||
id: '1', | ||
bundle: 'situation-updates', | ||
headline: 'Situation update', | ||
alertType: 'warning', | ||
content: | ||
"We're having issues at this location. Please avoid this facility until further notice.", | ||
context: 'global', | ||
showClose: true, | ||
operatingStatusCTA: false, | ||
emailUpdatesButton: false, | ||
findFacilitiesCTA: false, | ||
limitSubpageInheritance: false, | ||
}; | ||
|
||
return <SituationUpdateBanner {...defaultProps} />; | ||
}; | ||
|
||
export default async function createSituationUpdatesBanner(store, widgetType) { | ||
const bannerWidget = document.querySelector( | ||
`[data-widget-type="${widgetType}"]`, | ||
); | ||
|
||
if (bannerWidget) { | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<BannerContainer /> | ||
</Provider>, | ||
bannerWidget, | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/applications/static-pages/situation-updates-banner/situationUpdateBanner.jsx
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,29 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default function SituationUpdateBanner({ | ||
id, | ||
alertType, | ||
headline, | ||
showClose, | ||
content, | ||
}) { | ||
return ( | ||
<va-banner | ||
banner-id={id} | ||
type={alertType} | ||
headline={headline} | ||
show-close={showClose} | ||
> | ||
<p>{content}</p> | ||
</va-banner> | ||
); | ||
} | ||
|
||
SituationUpdateBanner.propTypes = { | ||
alertType: PropTypes.string.isRequired, | ||
content: PropTypes.node.isRequired, | ||
headline: PropTypes.string.isRequired, | ||
id: PropTypes.string.isRequired, | ||
showClose: PropTypes.bool, | ||
}; |
75 changes: 75 additions & 0 deletions
75
...ons/static-pages/situation-updates-banner/tests/createSituationUpdatesBanner.unit.spec.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,75 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import ReactDOM from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import createSituationUpdatesBanner, { | ||
BannerContainer, | ||
} from '../createSituationUpdatesBanner'; | ||
import widgetTypes from '../../widgetTypes'; | ||
|
||
describe('createSituationUpdatesBanner', () => { | ||
let sandbox; | ||
let store; | ||
let widgetContainer; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
store = { | ||
getState: () => ({ | ||
featureToggles: { | ||
loading: false, | ||
bannerUseAlternativeBanners: true, | ||
}, | ||
}), | ||
subscribe: () => {}, | ||
dispatch: sinon.spy(), | ||
}; | ||
|
||
widgetContainer = document.createElement('div'); | ||
widgetContainer.setAttribute( | ||
'data-widget-type', | ||
widgetTypes.SITUATION_UPDATES_BANNER, | ||
); | ||
document.body.appendChild(widgetContainer); | ||
|
||
sandbox.stub(ReactDOM, 'render'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
if (widgetContainer && widgetContainer.parentNode) { | ||
widgetContainer.parentNode.removeChild(widgetContainer); | ||
} | ||
}); | ||
|
||
it('should not render banner when widget container is not found', async () => { | ||
document.body.removeChild(widgetContainer); | ||
await createSituationUpdatesBanner( | ||
store, | ||
widgetTypes.SITUATION_UPDATES_BANNER, | ||
); | ||
expect(ReactDOM.render.called).to.be.false; | ||
}); | ||
|
||
it('should render banner with default props when widget container exists', async () => { | ||
await createSituationUpdatesBanner( | ||
store, | ||
widgetTypes.SITUATION_UPDATES_BANNER, | ||
); | ||
|
||
expect(ReactDOM.render.calledOnce).to.be.true; | ||
|
||
const renderCall = ReactDOM.render.getCall(0); | ||
const [element, container] = renderCall.args; | ||
|
||
expect(container).to.equal(widgetContainer); | ||
|
||
// Check if rendered element is wrapped in Provider | ||
expect(element.type).to.equal(Provider); | ||
|
||
// Check if SituationUpdateBanner is rendered with correct props | ||
const situationBanner = element.props.children; | ||
expect(situationBanner.type).to.equal(BannerContainer); | ||
}); | ||
}); |
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