Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(harvest): Add dismissable alert when running
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/cozy-harvest-lib/src/__mocks__/cozy-ui/transpiled/react/Icons/ArrowUp.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 @@ | ||
export default () => null |
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
55 changes: 55 additions & 0 deletions
55
packages/cozy-harvest-lib/src/components/cards/RunningAlert.spec.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,55 @@ | ||
import { render, fireEvent } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import { RunningAlert } from './RunningAlert' | ||
|
||
// Mock the isFlagshipApp function for easier testing | ||
const mockIsFlagshipApp = jest.fn() | ||
|
||
jest.mock('cozy-device-helper', () => ({ | ||
isFlagshipApp: (): unknown => mockIsFlagshipApp() | ||
})) | ||
|
||
// Mock the translation hook with distinct strings | ||
jest.mock('cozy-ui/transpiled/react/I18n', () => ({ | ||
useI18n: (): { | ||
t: jest.Mock | ||
} => ({ t: jest.fn().mockImplementation(key => key as string) }) | ||
})) | ||
|
||
describe('RunningAlert', () => { | ||
it('renders correctly when isFlagshipApp returns true', () => { | ||
mockIsFlagshipApp.mockReturnValue(true) | ||
|
||
const { getByText } = render(<RunningAlert />) | ||
|
||
// We're now using the translation keys as text | ||
expect( | ||
getByText('card.launchTrigger.runningAlert.title') | ||
).toBeInTheDocument() | ||
expect( | ||
getByText('card.launchTrigger.runningAlert.body') | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('does not render when isFlagshipApp returns false', () => { | ||
mockIsFlagshipApp.mockReturnValue(false) | ||
|
||
const { queryByText } = render(<RunningAlert />) | ||
|
||
// We're now using the translation key as text | ||
expect(queryByText('card.launchTrigger.runningAlert.title')).toBeNull() | ||
}) | ||
|
||
it('hides the alert when the button is clicked', () => { | ||
mockIsFlagshipApp.mockReturnValue(true) | ||
|
||
const { getByText, queryByText } = render(<RunningAlert />) | ||
|
||
// We're now using the translation key as text for the button | ||
fireEvent.click(getByText('card.launchTrigger.runningAlert.button')) | ||
|
||
// We're now using the translation key as text | ||
expect(queryByText('card.launchTrigger.runningAlert.title')).toBeNull() | ||
}) | ||
}) |
35 changes: 35 additions & 0 deletions
35
packages/cozy-harvest-lib/src/components/cards/RunningAlert.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,35 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { isFlagshipApp } from 'cozy-device-helper' | ||
import Alert from 'cozy-ui/transpiled/react/Alert' | ||
import AlertTitle from 'cozy-ui/transpiled/react/AlertTitle' | ||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import ArrowUp from 'cozy-ui/transpiled/react/Icons/ArrowUp' | ||
|
||
export const RunningAlert = (): JSX.Element | null => { | ||
const { t } = useI18n() | ||
const [isVisible, setIsVisible] = useState(isFlagshipApp()) | ||
const handleClose = (): void => setIsVisible(false) | ||
|
||
return isVisible ? ( | ||
<Alert | ||
action={ | ||
<Button | ||
variant="text" | ||
size="small" | ||
label={t('card.launchTrigger.runningAlert.button')} | ||
onClick={handleClose} | ||
/> | ||
} | ||
block | ||
className="u-mt-1" | ||
icon={<Icon icon={ArrowUp} />} | ||
> | ||
<AlertTitle>{t('card.launchTrigger.runningAlert.title')}</AlertTitle> | ||
|
||
{t('card.launchTrigger.runningAlert.body')} | ||
</Alert> | ||
) : null | ||
} |
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