Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/taxonomy/tag-list/TagListTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SubTagsExpanded = ({ taxonomyId, parentTagValue }) => {
<ul style={{ listStyleType: 'none' }}>
{subTagsData.data.results.map(tagData => (
<li key={tagData.id} style={{ paddingLeft: `${(tagData.depth - 1) * 30}px` }}>
{tagData.value} <span className="text-secondary-500">{tagData.childCount > 0 ? `(${tagData.childCount})` : null}</span>
{tagData.value} <span className="text-secondary-500">{tagData.descendantCount > 0 ? `(${tagData.descendantCount})` : null}</span>
</li>
))}
</ul>
Expand All @@ -48,14 +48,15 @@ OptionalExpandLink.propTypes = DataTable.ExpandRow.propTypes;
const TagValue = ({ row }) => (
<>
<span>{row.original.value}</span>
<span className="text-secondary-500">{` (${row.original.childCount})`}</span>
<span className="text-secondary-500">{` (${row.original.descendantCount})`}</span>
</>
);
TagValue.propTypes = {
row: Proptypes.shape({
original: Proptypes.shape({
value: Proptypes.string.isRequired,
childCount: Proptypes.number.isRequired,
descendantCount: Proptypes.number.isRequired,
}).isRequired,
}).isRequired,
};
Expand Down
17 changes: 11 additions & 6 deletions src/taxonomy/tag-list/TagListTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IntlProvider } from '@edx/frontend-platform/i18n';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { initializeMockApp } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { render, waitFor } from '@testing-library/react';
import { render, waitFor, within } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import MockAdapter from 'axios-mock-adapter';

Expand Down Expand Up @@ -35,22 +35,25 @@ const mockTagsResponse = {
results: [
{
...tagDefaults,
value: 'two level tag 1',
value: 'root tag 1',
child_count: 1,
descendant_count: 14,
_id: 1001,
sub_tags_url: '/request/to/load/subtags/1',
},
{
...tagDefaults,
value: 'two level tag 2',
value: 'root tag 2',
child_count: 1,
descendant_count: 10,
_id: 1002,
sub_tags_url: '/request/to/load/subtags/2',
},
{
...tagDefaults,
value: 'two level tag 3',
value: 'root tag 3',
child_count: 1,
descendant_count: 5,
_id: 1003,
sub_tags_url: '/request/to/load/subtags/3',
},
Expand All @@ -75,7 +78,7 @@ const subTagsResponse = {
},
],
};
const subTagsUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000&parent_tag=two+level+tag+1';
const subTagsUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000&parent_tag=root+tag+1';

describe('<TagListTable />', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -112,10 +115,12 @@ describe('<TagListTable />', () => {
axiosMock.onGet(rootTagsListUrl).reply(200, mockTagsResponse);
const result = render(<RootWrapper />);
await waitFor(() => {
expect(result.getByText('two level tag 1')).toBeInTheDocument();
expect(result.getByText('root tag 1')).toBeInTheDocument();
});
const rows = result.getAllByRole('row');
expect(rows.length).toBe(3 + 1); // 3 items plus header
expect(within(rows[0]).getAllByRole('columnheader')[0].textContent).toEqual('Tag name');
expect(within(rows[1]).getAllByRole('cell')[0].textContent).toEqual('root tag 1 (14)');
});

it('should render page correctly with subtags', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/taxonomy/tag-list/data/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/**
* @typedef {Object} TagData
* @property {number} childCount
* @property {number} descendantCount
* @property {number} depth
* @property {string} externalId
* @property {number} id
Expand Down