-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add a widget for managing thumbnail #1568
Merged
+1,794
−25
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
33701f4
🍱(front) add SVGs to the project
roro-lv 7b94e05
✨(front) update advertising to display uploaded thumbnail
roro-lv c5f0b8a
✨(front) add components needed for uploading thumbnail
roro-lv 6a071fb
✨(front) add a widget for instructor to upload thumbnail
roro-lv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
114 changes: 114 additions & 0 deletions
114
.../DashboardVideoLiveControlPane/customs/DashboardVideoLiveConfirmationModal/index.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,114 @@ | ||
import { act, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { wrapInIntlProvider } from 'utils/tests/intl'; | ||
import { DashboardVideoLiveConfirmationModal } from '.'; | ||
|
||
const mockModalOnCloseOrCancel = jest.fn(); | ||
const mockModalConfirm = jest.fn(); | ||
const genericTitle = 'A generic title'; | ||
const genericContent = | ||
'A generic content, which has for purpose to represent an example of an average string used in this modal. It has too be not too short, but also not too long.'; | ||
|
||
describe('<DashboardVideoLiveConfirmationModal />', () => { | ||
beforeEach(() => { | ||
/* | ||
make sure to remove all body children, grommet layer gets rendered twice, known issue | ||
https://github.com/grommet/grommet/issues/5200 | ||
*/ | ||
document.body.innerHTML = ''; | ||
document.body.appendChild(document.createElement('div')); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('renders the modal and closes it with esc key', () => { | ||
render( | ||
wrapInIntlProvider( | ||
<DashboardVideoLiveConfirmationModal | ||
text={genericContent} | ||
title={genericTitle} | ||
onModalCloseOrCancel={mockModalOnCloseOrCancel} | ||
onModalConfirm={mockModalConfirm} | ||
/>, | ||
), | ||
); | ||
screen.getByText(genericTitle); | ||
screen.getByText(genericContent); | ||
screen.getByRole('button', { name: '' }); | ||
screen.getByRole('button', { name: 'Confirm' }); | ||
screen.getByRole('button', { name: 'Cancel' }); | ||
act(() => { | ||
userEvent.keyboard('{esc}'); | ||
}); | ||
expect(mockModalOnCloseOrCancel).toHaveBeenCalledTimes(1); | ||
expect(mockModalConfirm).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders the modal and closes it with close button', () => { | ||
render( | ||
wrapInIntlProvider( | ||
<DashboardVideoLiveConfirmationModal | ||
text={genericContent} | ||
title={genericTitle} | ||
onModalCloseOrCancel={mockModalOnCloseOrCancel} | ||
onModalConfirm={mockModalConfirm} | ||
/>, | ||
), | ||
); | ||
screen.getByRole('button', { name: 'Confirm' }); | ||
screen.getByRole('button', { name: 'Cancel' }); | ||
const closeButton = screen.getByRole('button', { name: '' }); | ||
act(() => { | ||
userEvent.click(closeButton); | ||
}); | ||
expect(mockModalOnCloseOrCancel).toHaveBeenCalledTimes(1); | ||
expect(mockModalConfirm).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders the modal and closes it with cancel button', () => { | ||
render( | ||
wrapInIntlProvider( | ||
<DashboardVideoLiveConfirmationModal | ||
text={genericContent} | ||
title={genericTitle} | ||
onModalCloseOrCancel={mockModalOnCloseOrCancel} | ||
onModalConfirm={mockModalConfirm} | ||
/>, | ||
), | ||
); | ||
screen.getByText(genericTitle); | ||
screen.getByText(genericContent); | ||
screen.getByRole('button', { name: '' }); | ||
screen.getByRole('button', { name: 'Confirm' }); | ||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }); | ||
act(() => { | ||
userEvent.click(cancelButton); | ||
}); | ||
expect(mockModalOnCloseOrCancel).toHaveBeenCalledTimes(1); | ||
expect(mockModalConfirm).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders the modal and clicks on confirm button', () => { | ||
render( | ||
wrapInIntlProvider( | ||
<DashboardVideoLiveConfirmationModal | ||
text={genericContent} | ||
title={genericTitle} | ||
onModalCloseOrCancel={mockModalOnCloseOrCancel} | ||
onModalConfirm={mockModalConfirm} | ||
/>, | ||
), | ||
); | ||
screen.getByText(genericTitle); | ||
screen.getByText(genericContent); | ||
screen.getByRole('button', { name: '' }); | ||
screen.getByRole('button', { name: 'Cancel' }); | ||
const confirmButton = screen.getByRole('button', { name: 'Confirm' }); | ||
act(() => { | ||
userEvent.click(confirmButton); | ||
}); | ||
expect(mockModalOnCloseOrCancel).not.toHaveBeenCalled(); | ||
expect(mockModalConfirm).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...nents/DashboardVideoLiveControlPane/customs/DashboardVideoLiveConfirmationModal/index.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,100 @@ | ||
import { Box, Button, Layer, ResponsiveContext, Text } from 'grommet'; | ||
import { normalizeColor } from 'grommet/utils'; | ||
import React from 'react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import styled from 'styled-components'; | ||
|
||
import { RoundCrossSVG } from 'components/SVGIcons/RoundCrossSVG'; | ||
import { theme } from 'utils/theme/theme'; | ||
|
||
const messages = defineMessages({ | ||
confirmButtonLabel: { | ||
defaultMessage: 'Confirm', | ||
description: 'Label of the confirming button', | ||
id: 'components.DashboardVideoLiveConfirmationModal.confirmButtonLabel', | ||
}, | ||
cancelButtonLabel: { | ||
defaultMessage: 'Cancel', | ||
description: 'Label of the cancelling button', | ||
id: 'components.DashboardVideoLiveConfirmationModal.cancelButtonLabel', | ||
}, | ||
}); | ||
|
||
const StyledTitleText = styled(Text)` | ||
font-family: 'Roboto-Medium'; | ||
`; | ||
|
||
const StyledText = styled(Text)` | ||
line-height: 20px; | ||
`; | ||
|
||
interface DashboardVideoLiveConfirmationModalProps { | ||
text: string; | ||
title: string; | ||
onModalCloseOrCancel: () => void; | ||
onModalConfirm: () => void; | ||
} | ||
|
||
export const DashboardVideoLiveConfirmationModal = ({ | ||
text, | ||
title, | ||
onModalCloseOrCancel, | ||
onModalConfirm, | ||
}: DashboardVideoLiveConfirmationModalProps) => { | ||
const intl = useIntl(); | ||
const size = React.useContext(ResponsiveContext); | ||
|
||
return ( | ||
<Layer | ||
onEsc={onModalCloseOrCancel} | ||
onClickOutside={onModalCloseOrCancel} | ||
responsive={false} | ||
style={{ | ||
width: size === 'small' ? '95%' : '500px', | ||
border: `1px solid ${normalizeColor('blue-active', theme)}`, | ||
}} | ||
> | ||
<Box background="bg-info" direction="column" round="6px"> | ||
<Box | ||
direction="row-reverse" | ||
pad={{ horizontal: 'small', top: 'small' }} | ||
> | ||
<Button | ||
onClick={onModalCloseOrCancel} | ||
plain | ||
style={{ display: 'block', padding: 0 }} | ||
> | ||
<RoundCrossSVG height="20px" iconColor="blue-active" width="20px" /> | ||
</Button> | ||
</Box> | ||
<Box | ||
direction="column" | ||
gap="medium" | ||
pad={{ horizontal: 'large', bottom: '30px' }} | ||
> | ||
<StyledTitleText color="blue-active" size="1.5rem" truncate> | ||
{title} | ||
</StyledTitleText> | ||
<StyledText color="blue-active" size="1rem"> | ||
{text} | ||
</StyledText> | ||
<Box direction="row" gap="medium"> | ||
<Button | ||
primary | ||
label={intl.formatMessage(messages.confirmButtonLabel)} | ||
onClick={onModalConfirm} | ||
/> | ||
<Button | ||
secondary | ||
label={intl.formatMessage(messages.cancelButtonLabel)} | ||
onClick={onModalCloseOrCancel} | ||
style={{ | ||
color: normalizeColor('blue-active', theme), | ||
}} | ||
/> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Layer> | ||
); | ||
}; |
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
29 changes: 29 additions & 0 deletions
29
...veControlPane/widgets/DashboardVideoLiveWidgetThumbnail/ThumbnailDisplayer/index.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,29 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { thumbnailMockFactory } from 'utils/tests/factories'; | ||
import { wrapInIntlProvider } from 'utils/tests/intl'; | ||
import { ThumbnailDisplayer } from '.'; | ||
|
||
jest.mock('data/appData', () => ({ | ||
appData: {}, | ||
})); | ||
|
||
describe('<ThumbnailDisplayer />', () => { | ||
it('renders ThumbnailDisplayer', () => { | ||
const mockedThumbnail = thumbnailMockFactory(); | ||
render( | ||
wrapInIntlProvider( | ||
<ThumbnailDisplayer urlsThumbnail={mockedThumbnail.urls} />, | ||
), | ||
); | ||
|
||
const img = screen.getByRole('img', { name: 'Live video thumbnail' }); | ||
expect(img.getAttribute('src')).toEqual( | ||
'https://example.com/default_thumbnail/144', | ||
); | ||
expect(img.getAttribute('srcset')).toEqual( | ||
'https://example.com/default_thumbnail/144 256w, https://example.com/default_thumbnail/240 426w, https://example.com/default_thumbnail/480 854w, https://example.com/default_thumbnail/720 1280w, https://example.com/default_thumbnail/1080 1920w', | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's huge difference. Are you sure about this values ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For info, this component comes from the PR on the shared live media : https://github.com/openfun/marsha/blob/9f991d654dfb754566af8ca8dd71c93ec49becd7/src/frontend/components/DashboardVideoLiveControlPane/customs/DashboardVideoLiveConfirmationModal/index.tsx
I think the values are correct because this is what I wanted : a almost full page modal when the screen is small, a medium fixed sized modal otherwise