-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from fcoronelmakingsense/promotions-banner
feat: add dynamic promotions in public pages
- Loading branch information
Showing
16 changed files
with
314 additions
and
54 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
import { InjectAppServices } from '../../../services/pure-di'; | ||
import Loading from '../../Loading/Loading'; | ||
|
||
const getDefaultBannerData = (intl) => { | ||
const _ = (id, values) => intl.formatMessage({ id: id }, values); | ||
|
||
return { | ||
title: _('default_banner_data.title'), | ||
description: _('default_banner_data.description'), | ||
backgroundUrl: _('default_banner_data.background_url'), | ||
imageUrl: _('default_banner_data.image_url'), | ||
functionality: _('default_banner_data.functionality'), | ||
fontColor: '#000', | ||
}; | ||
}; | ||
|
||
/** | ||
* Promotions | ||
* @param { Object } props | ||
* @param { import('react-intl').InjectedIntl } props.intl | ||
* @param { import('../../services/pure-di').AppServices } props.dependencies | ||
*/ | ||
const Promotions = function({ | ||
intl, | ||
type, | ||
page, | ||
disabledSitesContent, | ||
dependencies: { dopplerSitesClient }, | ||
}) { | ||
const [bannerData, setBannerData] = useState({}); | ||
const [isLoading, setIsLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
if (disabledSitesContent) { | ||
setBannerData(getDefaultBannerData(intl)); | ||
setIsLoading(false); | ||
} else { | ||
const fetchData = async () => { | ||
setIsLoading(true); | ||
const bannerData = await dopplerSitesClient.getBannerData(intl.locale, type, page || ''); | ||
setBannerData( | ||
bannerData.success && bannerData.value ? bannerData.value : getDefaultBannerData(intl), | ||
); | ||
setIsLoading(false); | ||
}; | ||
|
||
fetchData(); | ||
} | ||
}, [disabledSitesContent, dopplerSitesClient, page, intl, type]); | ||
|
||
return ( | ||
<section className="feature-panel" style={{ position: 'relative' }}> | ||
{isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<div | ||
className="feature-panel--bg" | ||
style={{ | ||
backgroundImage: `url(${bannerData.backgroundUrl})`, | ||
color: bannerData.fontColor, | ||
}} | ||
> | ||
<article className="feature-content"> | ||
<h6>{bannerData.functionality}</h6> | ||
<h1>{bannerData.title}</h1> | ||
<p>{bannerData.description}</p> | ||
</article> | ||
<figure className="content-img"> | ||
<img src={bannerData.imageUrl} alt="" /> | ||
</figure> | ||
</div> | ||
)} | ||
</section> | ||
); | ||
}; | ||
|
||
export default InjectAppServices(injectIntl(Promotions)); |
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,84 @@ | ||
import React from 'react'; | ||
import { render, cleanup, waitForDomChange } from '@testing-library/react'; | ||
import 'jest-dom/extend-expect'; | ||
import Promotions from './Promotions'; | ||
import DopplerIntlProvider from '../../../i18n/DopplerIntlProvider.double-with-ids-as-values'; | ||
import { AppServicesProvider } from '../../../services/pure-di'; | ||
import { async } from 'q'; | ||
|
||
const emptyResponse = { success: false, error: new Error('Dummy error') }; | ||
const fullResponse = { | ||
success: true, | ||
value: { | ||
title: 'default_banner_data.title', | ||
description: 'default_banner_data.description', | ||
backgroundUrl: 'default_banner_data.background_url', | ||
imageUrl: 'default_banner_data.image_url', | ||
functionality: 'default_banner_data.functionality', | ||
color: '#fff', | ||
}, | ||
}; | ||
|
||
describe('Promotions Component', () => { | ||
afterEach(cleanup); | ||
it('should sites response fail', async () => { | ||
const dopplerSitesClientDouble = { | ||
getBannerData: async () => emptyResponse, | ||
}; | ||
|
||
const { container, getByText } = render( | ||
<AppServicesProvider | ||
forcedServices={{ | ||
dopplerSitesClient: dopplerSitesClientDouble, | ||
}} | ||
> | ||
<DopplerIntlProvider locale="es"> | ||
<Promotions type="signup" page="example" /> | ||
</DopplerIntlProvider> | ||
</AppServicesProvider>, | ||
); | ||
expect(container.querySelector('.loading-box')).toBeInTheDocument(); | ||
await waitForDomChange(); | ||
expect(getByText('default_banner_data.title')); | ||
}); | ||
|
||
it('should disabled sites content', () => { | ||
const dopplerSitesClientDouble = { | ||
getBannerData: async () => emptyResponse, | ||
}; | ||
|
||
const { getByText } = render( | ||
<AppServicesProvider | ||
forcedServices={{ | ||
dopplerSitesClient: dopplerSitesClientDouble, | ||
}} | ||
> | ||
<DopplerIntlProvider locale="es"> | ||
<Promotions type="signup" page="example" disabledSitesContent /> | ||
</DopplerIntlProvider> | ||
</AppServicesProvider>, | ||
); | ||
expect(getByText('default_banner_data.title')); | ||
}); | ||
|
||
it('should has full data from service', async () => { | ||
const dopplerSitesClientDouble = { | ||
getBannerData: async () => fullResponse, | ||
}; | ||
|
||
const { container, getByText } = render( | ||
<AppServicesProvider | ||
forcedServices={{ | ||
dopplerSitesClient: dopplerSitesClientDouble, | ||
}} | ||
> | ||
<DopplerIntlProvider locale="es"> | ||
<Promotions type="signup" page="example" /> | ||
</DopplerIntlProvider> | ||
</AppServicesProvider>, | ||
); | ||
expect(container.querySelector('.loading-box')).toBeInTheDocument(); | ||
await waitForDomChange(); | ||
expect(getByText(fullResponse.value.title)); | ||
}); | ||
}); |
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
Oops, something went wrong.