-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat: add component sidebar manage tab [FC-0062] #1275
Changes from all commits
aa337c9
fa81f31
99428bc
98ebc92
8206fc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { setConfig, getConfig } from '@edx/frontend-platform'; | ||
|
||
import { | ||
initializeMocks, | ||
render, | ||
screen, | ||
} from '../../testUtils'; | ||
import { mockLibraryBlockMetadata } from '../data/api.mocks'; | ||
import ComponentManagement from './ComponentManagement'; | ||
|
||
/* | ||
* FIXME: Summarize the reason here | ||
* https://stackoverflow.com/questions/47902335/innertext-is-undefined-in-jest-test | ||
*/ | ||
const getInnerText = (element: Element) => element?.textContent | ||
?.split('\n') | ||
.filter((text) => text && !text.match(/^\s+$/)) | ||
.map((text) => text.trim()) | ||
.join(' '); | ||
|
||
const matchInnerText = (nodeName: string, textToMatch: string) => (_: string, element: Element) => ( | ||
element.nodeName === nodeName && getInnerText(element) === textToMatch | ||
); | ||
|
||
describe('<ComponentManagement />', () => { | ||
it('should render draft status', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Draft')).toBeInTheDocument(); | ||
expect(await screen.findByText('(Never Published)')).toBeInTheDocument(); | ||
expect(screen.getByText(matchInnerText('SPAN', 'Draft saved on June 20, 2024 at 13:54 UTC.'))).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render published status', async () => { | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyPublished} />); | ||
expect(await screen.findByText('Published')).toBeInTheDocument(); | ||
expect(screen.getByText('Published')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(matchInnerText('SPAN', 'Last published on June 21, 2024 at 24:00 UTC by Luke.')), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the tagging info', async () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'true', | ||
}); | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Tags')).toBeInTheDocument(); | ||
// TODO: replace with actual data when implement tag list | ||
expect(screen.queryByText('Tags placeholder')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render draft status', async () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'false', | ||
}); | ||
initializeMocks(); | ||
mockLibraryBlockMetadata.applyMock(); | ||
render(<ComponentManagement usageKey={mockLibraryBlockMetadata.usageKeyNeverPublished} />); | ||
expect(await screen.findByText('Draft')).toBeInTheDocument(); | ||
expect(screen.queryByText('Tags')).not.toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Collapsible, Icon, Stack } from '@openedx/paragon'; | ||
import { Tag } from '@openedx/paragon/icons'; | ||
|
||
import { useLibraryBlockMetadata } from '../data/apiHooks'; | ||
import StatusWidget from '../generic/status-widget'; | ||
import messages from './messages'; | ||
|
||
interface ComponentManagementProps { | ||
usageKey: string; | ||
} | ||
const ComponentManagement = ({ usageKey }: ComponentManagementProps) => { | ||
const intl = useIntl(); | ||
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey); | ||
|
||
if (!componentMetadata) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Stack gap={3}> | ||
<StatusWidget | ||
{...componentMetadata} | ||
/> | ||
{[true, 'true'].includes(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES) | ||
&& ( | ||
<Collapsible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test that enables tagging to verify this code path? It's enough to just check for the presence + absence of "Tags" title, until we get that feature implemented. Would be great if you could check for the Collections title too |
||
defaultOpen | ||
title={( | ||
<Stack gap={1} direction="horizontal"> | ||
<Icon src={Tag} /> | ||
{intl.formatMessage(messages.manageTabTagsTitle)} | ||
</Stack> | ||
)} | ||
className="border-0" | ||
> | ||
Tags placeholder | ||
</Collapsible> | ||
)} | ||
<Collapsible | ||
defaultOpen | ||
title={( | ||
<Stack gap={1} direction="horizontal"> | ||
<Icon src={Tag} /> | ||
{intl.formatMessage(messages.manageTabCollectionsTitle)} | ||
</Stack> | ||
)} | ||
className="border-0" | ||
> | ||
Collections placeholder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is showing the component's Collections out of scope here? Thanks to your suggestions, we should have data available once edx-platform#35469 merges. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will create a follow up tasks to handle the collections. |
||
</Collapsible> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ComponentManagement; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "./status-widget/StatusWidget"; |
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.
Could you add a test for the component published state too?
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.
Done: 98ebc92