-
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.
classroom dashboard widget to list session-shared notes
- Loading branch information
1 parent
57ca49f
commit cb24a98
Showing
6 changed files
with
178 additions
and
6 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
66 changes: 66 additions & 0 deletions
66
...s/lib_classroom/src/components/ClassroomWidgetProvider/widgets/SharedNotes/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,66 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { InfoWidgetModalProvider } from 'lib-components'; | ||
import { render } from 'lib-tests'; | ||
import { DateTime } from 'luxon'; | ||
import React from 'react'; | ||
|
||
import { | ||
classroomMockFactory, | ||
classroomSharedNoteMockFactory, | ||
} from '@lib-classroom/utils/tests/factories'; | ||
import { wrapInClassroom } from '@lib-classroom/utils/wrapInClassroom'; | ||
|
||
import { SharedNotes } from '.'; | ||
|
||
describe('<SharedNotes />', () => { | ||
it('displays a list of available shared notes', () => { | ||
let classroom = classroomMockFactory({ id: '1', started: false }); | ||
const classroomSharedNotes = [ | ||
classroomSharedNoteMockFactory({ | ||
updated_on: | ||
DateTime.fromJSDate(new Date(2022, 1, 29, 11, 0, 0)).toISO() || | ||
undefined, | ||
}), | ||
classroomSharedNoteMockFactory({ | ||
updated_on: | ||
DateTime.fromJSDate(new Date(2022, 1, 15, 11, 0, 0)).toISO() || | ||
undefined, | ||
}), | ||
]; | ||
|
||
const { rerender } = render( | ||
wrapInClassroom( | ||
<InfoWidgetModalProvider value={null}> | ||
<SharedNotes />, | ||
</InfoWidgetModalProvider>, | ||
classroom, | ||
), | ||
); | ||
|
||
expect(screen.getByText('Shared notes')).toBeInTheDocument(); | ||
expect(screen.getByText('No shared note available')).toBeInTheDocument(); | ||
|
||
// simulate updated classroom | ||
classroom = { | ||
...classroom, | ||
shared_notes: classroomSharedNotes, | ||
}; | ||
rerender( | ||
wrapInClassroom( | ||
<InfoWidgetModalProvider value={null}> | ||
<SharedNotes />, | ||
</InfoWidgetModalProvider>, | ||
classroom, | ||
), | ||
); | ||
expect( | ||
screen.queryByText('No shared note available'), | ||
).not.toBeInTheDocument(); | ||
expect( | ||
screen.getByText('Tuesday, March 1, 2022 - 11:00 AM'), | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText('Tuesday, February 15, 2022 - 11:00 AM'), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
...ckages/lib_classroom/src/components/ClassroomWidgetProvider/widgets/SharedNotes/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,78 @@ | ||
import { Box } from 'grommet'; | ||
import { ClassroomSharedNote, FoldableItem, ItemList } from 'lib-components'; | ||
import React from 'react'; | ||
import { useIntl, defineMessages } from 'react-intl'; | ||
|
||
import { useCurrentClassroom } from '@lib-classroom/hooks/useCurrentClassroom'; | ||
|
||
const messages = defineMessages({ | ||
title: { | ||
defaultMessage: 'Shared notes', | ||
description: 'Label for shared notes download in classroom form.', | ||
id: 'component.SharedNotes.title', | ||
}, | ||
info: { | ||
defaultMessage: `All available shared notes can be downloaded here.`, | ||
description: 'Helptext for the widget.', | ||
id: 'component.SharedNotes.info', | ||
}, | ||
noSharedNoteAvailable: { | ||
defaultMessage: 'No shared note available', | ||
description: 'Message when no recordings are available.', | ||
id: 'component.SharedNotes.noSharedNoteAvailable', | ||
}, | ||
downloadSharedNoteLabel: { | ||
defaultMessage: 'Download shared note', | ||
description: 'Label for download recording button.', | ||
id: 'component.SharedNotes.downloadSharedNoteLabel', | ||
}, | ||
}); | ||
|
||
export const SharedNotes = () => { | ||
const classroom = useCurrentClassroom(); | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<FoldableItem | ||
infoText={intl.formatMessage(messages.info)} | ||
initialOpenValue | ||
title={intl.formatMessage(messages.title)} | ||
> | ||
<ItemList | ||
itemList={classroom.shared_notes} | ||
noItemsMessage={intl.formatMessage(messages.noSharedNoteAvailable)} | ||
> | ||
{(sharedNote: ClassroomSharedNote) => ( | ||
<Box | ||
key={sharedNote.id} | ||
direction="row" | ||
align="center" | ||
fill="horizontal" | ||
height="60px" | ||
gap="medium" | ||
pad="small" | ||
> | ||
<a | ||
title={intl.formatMessage(messages.downloadSharedNoteLabel)} | ||
href={sharedNote.shared_note_url} | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
{intl.formatDate(sharedNote.updated_on, { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
weekday: 'long', | ||
}) + | ||
' - ' + | ||
intl.formatDate(sharedNote.updated_on, { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
})} | ||
</a> | ||
</Box> | ||
)} | ||
</ItemList> | ||
</FoldableItem> | ||
); | ||
}; |
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