-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🍱(front) add ViewersList and its related components
Add a new component ViewersList, which is in charge of displaying the viewers list, and the on stage management buttons, depending on if the user is an instructor or not. This commit also add all necessaries components needed for ViewersList to work properly.
- Loading branch information
Showing
13 changed files
with
658 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+4.93 KB
...s-viewers-list-header-component-and-compares-it-with-previous-render-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
src/frontend/components/ViewersList/components/ViewersListHeader/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,14 @@ | ||
import React from 'react'; | ||
import { screen } from '@testing-library/react'; | ||
|
||
import { renderImageSnapshot } from 'utils/tests/imageSnapshot'; | ||
import { ViewersListHeader } from '.'; | ||
|
||
describe('<ViewersListHeader />', () => { | ||
it('renders ViewersListHeader component and compares it with previous render.', async () => { | ||
await renderImageSnapshot( | ||
<ViewersListHeader margin={{ bottom: '6px' }} text="An example text" />, | ||
); | ||
screen.getByText('An example text'); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
src/frontend/components/ViewersList/components/ViewersListHeader/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,38 @@ | ||
import React from 'react'; | ||
import { Box, BoxProps, Text } from 'grommet'; | ||
import styled from 'styled-components'; | ||
|
||
const StyledTextHeader = styled(Text)` | ||
font-family: 'Roboto-Regular'; | ||
letter-spacing: -0.2px; | ||
`; | ||
|
||
interface ViewersListHeaderProps extends BoxProps { | ||
text: string; | ||
} | ||
|
||
export const ViewersListHeader = ({ | ||
text, | ||
...boxProps | ||
}: ViewersListHeaderProps) => { | ||
return ( | ||
<Box align="start" {...boxProps}> | ||
<Box | ||
align="center" | ||
border={{ | ||
color: 'blue-active', | ||
size: 'xsmall', | ||
}} | ||
pad={{ | ||
horizontal: 'small', | ||
vertical: '2px', | ||
}} | ||
round="14px" | ||
> | ||
<StyledTextHeader color="blue-active" size="0.625rem" weight="normal"> | ||
{text} | ||
</StyledTextHeader> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
Binary file added
BIN
+4.86 KB
...st-item-component-for-a-student-and-compares-it-with-previous-render-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.12 KB
...tem-component-for-an-instructor-and-compares-it-with-previous-render-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
src/frontend/components/ViewersList/components/ViewersListItem/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,21 @@ | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { renderImageSnapshot } from 'utils/tests/imageSnapshot'; | ||
import { ViewersListItem } from '.'; | ||
|
||
describe('<ViewersListItem />', () => { | ||
it('renders ViewersListItem component, for a student, and compares it with previous render.', async () => { | ||
await renderImageSnapshot( | ||
<ViewersListItem isInstructor={false} name={'An example name'} />, | ||
); | ||
screen.getByText('An example name'); | ||
}); | ||
|
||
it('renders ViewersListItem component, for an instructor, and compares it with previous render.', async () => { | ||
await renderImageSnapshot( | ||
<ViewersListItem isInstructor={true} name={'An example name'} />, | ||
); | ||
screen.getByText('An example name'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/frontend/components/ViewersList/components/ViewersListItem/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,33 @@ | ||
import { Box, Text } from 'grommet'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { ChatAvatar } from 'components/Chat/SharedChatComponents/ChatAvatar'; | ||
|
||
const StyledText = styled(Text)` | ||
font-family: 'Roboto-Medium'; | ||
letter-spacing: 0.07px; | ||
`; | ||
|
||
interface ViewersListItemProps { | ||
isInstructor: boolean; | ||
name: string; | ||
} | ||
|
||
export const ViewersListItem = ({ | ||
isInstructor, | ||
name, | ||
}: ViewersListItemProps) => { | ||
return ( | ||
<Box align="center" direction="row" gap="10px"> | ||
<ChatAvatar isInstructor={isInstructor} /> | ||
<StyledText | ||
color="blue-active" | ||
size="0.75rem" | ||
weight={isInstructor ? 'bold' : 'normal'} | ||
> | ||
{name} | ||
</StyledText> | ||
</Box> | ||
); | ||
}; |
38 changes: 38 additions & 0 deletions
38
src/frontend/components/ViewersList/components/ViewersListItemContainer/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,38 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { normalizeColor } from 'grommet/utils'; | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import { theme } from 'utils/theme/theme'; | ||
import { ViewersListItemContainer } from '.'; | ||
|
||
const GenericChild = () => <p>Some text</p>; | ||
|
||
describe('<ViewersListItemContainer />', () => { | ||
it('renders ViewersListItemContainer, with a child', () => { | ||
render( | ||
<ViewersListItemContainer> | ||
<GenericChild /> | ||
</ViewersListItemContainer>, | ||
); | ||
screen.getByText('Some text'); | ||
}); | ||
|
||
it('checks hover style is applied', async () => { | ||
const tree = renderer | ||
.create( | ||
<ViewersListItemContainer> | ||
<GenericChild /> | ||
</ViewersListItemContainer>, | ||
) | ||
.toJSON(); | ||
|
||
expect(tree).toHaveStyleRule( | ||
'background', | ||
normalizeColor('bg-marsha', theme), | ||
{ | ||
modifier: ':hover', | ||
}, | ||
); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/frontend/components/ViewersList/components/ViewersListItemContainer/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,26 @@ | ||
import { Box } from 'grommet'; | ||
import { normalizeColor } from 'grommet/utils'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { theme } from 'utils/theme/theme'; | ||
|
||
const StyledItemContainer = styled(Box)` | ||
&:hover { | ||
background: ${normalizeColor('bg-marsha', theme)}; | ||
} | ||
`; | ||
|
||
export const ViewersListItemContainer = ({ | ||
children, | ||
}: React.PropsWithChildren<{}>) => ( | ||
<StyledItemContainer | ||
align="center" | ||
justify="between" | ||
direction="row" | ||
gap="small" | ||
pad={{ horizontal: 'medium', vertical: 'xsmall' }} | ||
> | ||
{children} | ||
</StyledItemContainer> | ||
); |
21 changes: 21 additions & 0 deletions
21
src/frontend/components/ViewersList/components/ViewersListTextButton/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,21 @@ | ||
import { act, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { ViewersListTextButton } from '.'; | ||
|
||
const mockOnClick = jest.fn(); | ||
|
||
describe('<ViewersListTextButton />', () => { | ||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
it('renders ViewersListTextButton component and clicks on it', () => { | ||
render( | ||
<ViewersListTextButton onClick={mockOnClick} text="An example text" />, | ||
); | ||
screen.getByText('An example text'); | ||
const button = screen.getByRole('button', { name: 'An example text' }); | ||
act(() => userEvent.click(button)); | ||
expect(mockOnClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
src/frontend/components/ViewersList/components/ViewersListTextButton/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,36 @@ | ||
import { Button, Text } from 'grommet'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const StyledButton = styled(Button)` | ||
align-items: center; | ||
display: flex; | ||
height: 20px; | ||
padding: 0px 10px; | ||
`; | ||
|
||
const StyledTextButton = styled(Text)` | ||
color: white; | ||
font-family: 'Roboto-Bold'; | ||
`; | ||
|
||
interface ViewersListTextButtonProps { | ||
onClick: () => void; | ||
text: string; | ||
} | ||
|
||
export const ViewersListTextButton = ({ | ||
onClick, | ||
text, | ||
}: ViewersListTextButtonProps) => { | ||
return ( | ||
<StyledButton | ||
a11yTitle={text} | ||
color="blue-active" | ||
label={<StyledTextButton size="0.625rem">{text}</StyledTextButton>} | ||
onClick={onClick} | ||
primary | ||
title={text} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.