Skip to content

Commit 1773c33

Browse files
committed
feat: Add created entry in history log
1 parent ece3b9e commit 1773c33

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

src/library-authoring/generic/history-log/HistoryLog.test.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,33 @@ describe('<HistoryComponentLog />', () => {
136136
mockLibraryBlockPublishHistory.data = originalData;
137137
});
138138

139+
it('renders draft entry with "created" action', async () => {
140+
const user = userEvent.setup();
141+
const originalData = mockLibraryBlockDraftHistory.data;
142+
mockLibraryBlockDraftHistory.data = [
143+
{
144+
changedBy: {
145+
username: 'creator_user',
146+
profileImageUrls: {
147+
full: 'icon/mock/path',
148+
large: 'icon/mock/path',
149+
medium: 'icon/mock/path',
150+
small: 'icon/mock/path',
151+
},
152+
},
153+
changedAt: '2026-03-16T11:00:00Z',
154+
title: 'New Component',
155+
itemType: 'html',
156+
action: 'created',
157+
},
158+
] as any;
159+
renderComponent(mockLibraryBlockCreationEntry.usageKey);
160+
const trigger = await findByDeepTextContent(/Introduction to Testing 1 is a draft/i);
161+
await user.click(trigger);
162+
expect(await findByDeepTextContent(/creator_user created.*New Component/i)).toBeInTheDocument();
163+
mockLibraryBlockDraftHistory.data = originalData;
164+
});
165+
139166
it('renders publish group without collapsible and without contributor count when contributors is empty', async () => {
140167
const originalData = mockLibraryBlockPublishHistory.data;
141168
mockLibraryBlockPublishHistory.data = [
@@ -192,6 +219,33 @@ describe('<HistoryContainerLog />', () => {
192219
expect(screen.queryByText(/published/i)).not.toBeInTheDocument();
193220
});
194221

222+
it('renders draft entry with "created" action', async () => {
223+
const user = userEvent.setup();
224+
const originalData = mockLibraryContainerDraftHistory.data;
225+
mockLibraryContainerDraftHistory.data = [
226+
{
227+
changedBy: {
228+
username: 'creator_user',
229+
profileImageUrls: {
230+
full: 'icon/mock/path',
231+
large: 'icon/mock/path',
232+
medium: 'icon/mock/path',
233+
small: 'icon/mock/path',
234+
},
235+
},
236+
changedAt: '2026-03-16T11:00:00Z',
237+
title: 'New Unit',
238+
itemType: 'unit',
239+
action: 'created',
240+
},
241+
] as any;
242+
renderContainerComponent(mockLibraryContainerDraftHistory.containerKey);
243+
const trigger = await findByDeepTextContent(/Test Unit is a draft/i);
244+
await user.click(trigger);
245+
expect(await findByDeepTextContent(/creator_user created.*New Unit/i)).toBeInTheDocument();
246+
mockLibraryContainerDraftHistory.data = originalData;
247+
});
248+
195249
it('always renders the created group', async () => {
196250
renderContainerComponent(mockLibraryContainerDraftHistory.containerKey);
197251
expect(await findByDeepTextContent(/author created.*Introduction to Testing Unit 1/i)).toBeInTheDocument();

src/library-authoring/generic/history-log/HistoryLogGroup.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,24 @@ const HistoryLogGroupEntries = ({
105105
}: HistoryLogGroupEntriesProps) => {
106106
const intl = useIntl();
107107

108+
const getEntryMessage = (entry: LibraryHistoryEntry) => {
109+
switch (entry.action) {
110+
case 'edited':
111+
return messages.historyEditEntry;
112+
case 'renamed':
113+
return messages.historyRenameEntry;
114+
case 'created':
115+
return messages.historyCreatedEntry;
116+
default:
117+
return messages.historyEditEntry;
118+
}
119+
};
120+
108121
return (
109122
<Stack gap={0}>
110123
<div className="history-log-vert" />
111124
{entries.map((entry) => {
112-
const entryMessage = entry.action === 'edited'
113-
? messages.historyEditEntry
114-
: messages.historyRenameEntry;
125+
const entryMessage = getEntryMessage(entry);
115126

116127
return (
117128
<div key={entry.changedAt}>

src/library-authoring/generic/history-log/messages.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const messages = defineMessages({
3636
defaultMessage: '{user} renamed {icon} {displayName}',
3737
description: 'Rename entry of the history log.',
3838
},
39+
historyCreatedEntry: {
40+
id: 'course-authoring.library-authoring.history.created-entry',
41+
defaultMessage: '{user} created {icon} {displayName}',
42+
description: 'Created entry of the history log.',
43+
},
44+
historyDeletedEntry: {
45+
id: 'course-authoring.library-authoring.history.deleted-entry',
46+
defaultMessage: '{user} deleted {icon} {displayName}',
47+
description: 'Deleted entry of the history log.',
48+
},
3949
historyEntryDefaultUser: {
4050
id: 'course-authoring.library-authoring.history.default-user',
4151
defaultMessage: 'Author',

0 commit comments

Comments
 (0)