From 7221562bbaaa1379d785779a4c464fbcb4c49b68 Mon Sep 17 00:00:00 2001 From: Tushar Verma Date: Sat, 31 Oct 2026 16:47:56 +0530 Subject: [PATCH 1/2] Add StudioContentNodeIcon and use it in channel details Total resources --- .../shared/utils/__tests__/colors.spec.js | 25 +++++++ .../frontend/shared/utils/colors.js | 26 +++++++ .../shared/views/StudioContentNodeIcon.vue | 70 +++++++++++++++++++ .../__tests__/StudioContentNodeIcon.spec.js | 26 +++++++ .../__tests__/StudioDetailsPanel.spec.js | 18 +++++ .../views/details/StudioDetailsPanel.vue | 6 +- 6 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 contentcuration/contentcuration/frontend/shared/utils/__tests__/colors.spec.js create mode 100644 contentcuration/contentcuration/frontend/shared/utils/colors.js create mode 100644 contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue create mode 100644 contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js diff --git a/contentcuration/contentcuration/frontend/shared/utils/__tests__/colors.spec.js b/contentcuration/contentcuration/frontend/shared/utils/__tests__/colors.spec.js new file mode 100644 index 0000000000..551962a5b2 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/utils/__tests__/colors.spec.js @@ -0,0 +1,25 @@ +import { themePalette, themeTokens } from 'kolibri-design-system/lib/styles/theme'; +import { getContentKindColor } from '../colors'; + +describe('getContentKindColor', () => { + const tokens = themeTokens(); + const palette = themePalette(); + + it.each([ + ['video', tokens.watch], + ['audio', tokens.listen], + ['document', tokens.read], + ['slideshow', tokens.read], + ['exercise', tokens.practice], + ['html5', tokens.explore], + ['h5p', tokens.explore], + ['zim', tokens.explore], + ['topic', palette.grey.v_400], + ])('returns the KDS color for %s', (kind, expected) => { + expect(getContentKindColor(kind)).toBe(expected); + }); + + it.each(['unsupported', undefined, null, ''])('falls back to grey for %s', kind => { + expect(getContentKindColor(kind)).toBe(palette.grey.v_400); + }); +}); diff --git a/contentcuration/contentcuration/frontend/shared/utils/colors.js b/contentcuration/contentcuration/frontend/shared/utils/colors.js new file mode 100644 index 0000000000..068b361753 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/utils/colors.js @@ -0,0 +1,26 @@ +import { themePalette, themeTokens } from 'kolibri-design-system/lib/styles/theme'; +import { ContentKindsNames } from 'shared/leUtils/ContentKinds'; + +/** + * Returns the KDS background color for a content node kind. + * Falls back to a neutral grey for unknown/unsupported kinds. + * + * @param {string} kind - content node kind (e.g. 'video', 'topic') + * @returns {string} color value + */ +export function getContentKindColor(kind) { + const palette = themePalette(); + const tokens = themeTokens(); + const colors = { + [ContentKindsNames.TOPIC]: palette.grey.v_400, + [ContentKindsNames.VIDEO]: tokens.watch, + [ContentKindsNames.AUDIO]: tokens.listen, + [ContentKindsNames.DOCUMENT]: tokens.read, + [ContentKindsNames.SLIDESHOW]: tokens.read, + [ContentKindsNames.EXERCISE]: tokens.practice, + [ContentKindsNames.H5P]: tokens.explore, + [ContentKindsNames.HTML5]: tokens.explore, + [ContentKindsNames.ZIM]: tokens.explore, + }; + return colors[kind] || palette.grey.v_400; +} diff --git a/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue b/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue new file mode 100644 index 0000000000..e6c9bb42c0 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue @@ -0,0 +1,70 @@ + + + + + + + diff --git a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js new file mode 100644 index 0000000000..49d72f1148 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js @@ -0,0 +1,26 @@ +import { render } from '@testing-library/vue'; +import VueRouter from 'vue-router'; +import StudioContentNodeIcon from '../StudioContentNodeIcon.vue'; + +const renderComponent = (props = {}) => + render(StudioContentNodeIcon, { props, routes: new VueRouter() }); + +describe('StudioContentNodeIcon', () => { + it.each(['topic', 'video', 'audio', 'exercise', 'document', 'slideshow', 'html5', 'zim'])( + 'renders an icon for %s', + kind => { + const { container } = renderComponent({ kind }); + expect(container.querySelector('svg')).toBeInTheDocument(); + }, + ); + + it('renders nothing for an unsupported kind', () => { + const { container } = renderComponent({ kind: 'unsupported' }); + expect(container.querySelector('svg')).not.toBeInTheDocument(); + }); + + it('is marked to be captured as an image in PDF exports', () => { + const { container } = renderComponent({ kind: 'video' }); + expect(container.querySelector('[capture-as-image]')).toBeInTheDocument(); + }); +}); diff --git a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js index 9c03e95b26..bf5f3d4a2f 100644 --- a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js +++ b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js @@ -115,4 +115,22 @@ describe('StudioDetailsPanel', () => { expect(placeholders.length).toBeGreaterThan(0); }); }); + describe('total resources', () => { + it('lists each content kind with its translated label and count', () => { + renderComponent({ + details: { + ...fullChannel, + kind_count: [ + { kind_id: 'video', count: 30 }, + { kind_id: 'exercise', count: 12 }, + ], + }, + loading: false, + }); + expect(screen.getByText('Video')).toBeInTheDocument(); + expect(screen.getByText('30')).toBeInTheDocument(); + expect(screen.getByText('Exercise')).toBeInTheDocument(); + expect(screen.getByText('12')).toBeInTheDocument(); + }); + }); }); diff --git a/contentcuration/contentcuration/frontend/shared/views/details/StudioDetailsPanel.vue b/contentcuration/contentcuration/frontend/shared/views/details/StudioDetailsPanel.vue index 2ea3acd384..fc7eb1c94d 100644 --- a/contentcuration/contentcuration/frontend/shared/views/details/StudioDetailsPanel.vue +++ b/contentcuration/contentcuration/frontend/shared/views/details/StudioDetailsPanel.vue @@ -106,7 +106,7 @@ >
- @@ -445,7 +445,7 @@ metadataTranslationMixin, } from '../../mixins'; import { CategoriesLookup, LevelsLookup } from '../../constants'; - import ContentNodeIcon from '../ContentNodeIcon'; + import StudioContentNodeIcon from '../StudioContentNodeIcon'; import ExpandableList from '../ExpandableList'; import StudioChip from '../StudioChip'; import StudioLargeLoader from '../StudioLargeLoader'; @@ -495,7 +495,7 @@ name: 'StudioDetailsPanel', components: { StudioLargeLoader, - ContentNodeIcon, + StudioContentNodeIcon, ExpandableList, StudioCopyToken, StudioDetailsRow, From ceb40ecc4d0b35110287c17283fae58a74eecace Mon Sep 17 00:00:00 2001 From: Tushar Verma Date: Wed, 11 Nov 2026 18:00:18 +0000 Subject: [PATCH 2/2] Map h5p icon, match chip size and tighten StudioContentNodeIcon tests --- .../shared/utils/__tests__/icons.spec.js | 27 ++++++++++ .../frontend/shared/utils/colors.js | 7 --- .../frontend/shared/utils/icons.js | 4 ++ .../shared/views/StudioContentNodeIcon.vue | 18 ++++--- .../__tests__/StudioContentNodeIcon.spec.js | 54 +++++++++++++++++-- .../__tests__/StudioDetailsPanel.spec.js | 18 +++++-- 6 files changed, 105 insertions(+), 23 deletions(-) create mode 100644 contentcuration/contentcuration/frontend/shared/utils/__tests__/icons.spec.js diff --git a/contentcuration/contentcuration/frontend/shared/utils/__tests__/icons.spec.js b/contentcuration/contentcuration/frontend/shared/utils/__tests__/icons.spec.js new file mode 100644 index 0000000000..12d3f7b753 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/utils/__tests__/icons.spec.js @@ -0,0 +1,27 @@ +import { getContentKindIcon } from '../icons'; + +describe('getContentKindIcon', () => { + it.each([ + ['topic', 'topic'], + ['video', 'video'], + ['audio', 'audio'], + ['slideshow', 'slideshow'], + ['exercise', 'exercise'], + ['document', 'document'], + ['html5', 'html5'], + ['h5p', 'html5'], + ['zim', 'html5'], + ['unsupported', 'error'], + ])('maps %s to %s', (kind, icon) => { + expect(getContentKindIcon(kind)).toBe(icon); + }); + + it('uses the empty-topic icon only when a topic is empty', () => { + expect(getContentKindIcon('topic', true)).toBe('emptyTopic'); + expect(getContentKindIcon('h5p', true)).toBe('html5'); + }); + + it('throws when a kind has no mapping', () => { + expect(() => getContentKindIcon('missing')).toThrow('Icon not found for content kind: missing'); + }); +}); diff --git a/contentcuration/contentcuration/frontend/shared/utils/colors.js b/contentcuration/contentcuration/frontend/shared/utils/colors.js index 068b361753..9df21bf388 100644 --- a/contentcuration/contentcuration/frontend/shared/utils/colors.js +++ b/contentcuration/contentcuration/frontend/shared/utils/colors.js @@ -1,13 +1,6 @@ import { themePalette, themeTokens } from 'kolibri-design-system/lib/styles/theme'; import { ContentKindsNames } from 'shared/leUtils/ContentKinds'; -/** - * Returns the KDS background color for a content node kind. - * Falls back to a neutral grey for unknown/unsupported kinds. - * - * @param {string} kind - content node kind (e.g. 'video', 'topic') - * @returns {string} color value - */ export function getContentKindColor(kind) { const palette = themePalette(); const tokens = themeTokens(); diff --git a/contentcuration/contentcuration/frontend/shared/utils/icons.js b/contentcuration/contentcuration/frontend/shared/utils/icons.js index cd07955e3c..508d193098 100644 --- a/contentcuration/contentcuration/frontend/shared/utils/icons.js +++ b/contentcuration/contentcuration/frontend/shared/utils/icons.js @@ -9,8 +9,12 @@ const CONTENT_KIND_ICONS = { [ContentKindsNames.SLIDESHOW]: 'slideshow', [ContentKindsNames.EXERCISE]: 'exercise', [ContentKindsNames.DOCUMENT]: 'document', + [ContentKindsNames.H5P]: 'html5', [ContentKindsNames.HTML5]: 'html5', [ContentKindsNames.ZIM]: 'html5', + // Not a content kind. Base Vuetify uses error_outline; KDS has no such token. + // Unknown kinds still throw below. + unsupported: 'error', }; export function getContentKindIcon(kind, isEmpty = false) { diff --git a/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue b/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue index e6c9bb42c0..21add31e2c 100644 --- a/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue +++ b/contentcuration/contentcuration/frontend/shared/views/StudioContentNodeIcon.vue @@ -40,11 +40,7 @@ }, computed: { icon() { - try { - return getContentKindIcon(this.kind, this.isEmpty); - } catch (e) { - return null; - } + return getContentKindIcon(this.kind, this.isEmpty); }, backgroundColor() { return getContentKindColor(this.kind); @@ -57,14 +53,24 @@ diff --git a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js index 49d72f1148..ea42e17b6c 100644 --- a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js +++ b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioContentNodeIcon.spec.js @@ -1,22 +1,66 @@ import { render } from '@testing-library/vue'; +import Vue from 'vue'; import VueRouter from 'vue-router'; +import KIcon from 'kolibri-design-system/lib/KIcon'; import StudioContentNodeIcon from '../StudioContentNodeIcon.vue'; +import { getContentKindColor } from 'shared/utils/colors'; +import { getContentKindIcon } from 'shared/utils/icons'; const renderComponent = (props = {}) => render(StudioContentNodeIcon, { props, routes: new VueRouter() }); +const renderIcon = icon => render(KIcon, { props: { icon }, routes: new VueRouter() }); + +function iconShape(container) { + const paths = [...container.querySelectorAll('svg path')].map(path => path.getAttribute('d')); + expect(paths.length).toBeGreaterThan(0); + return paths.join('|'); +} + describe('StudioContentNodeIcon', () => { - it.each(['topic', 'video', 'audio', 'exercise', 'document', 'slideshow', 'html5', 'zim'])( - 'renders an icon for %s', + it.each(['topic', 'video', 'audio', 'exercise', 'document', 'slideshow', 'html5', 'h5p', 'zim'])( + 'renders the %s icon on its content-kind background', kind => { const { container } = renderComponent({ kind }); - expect(container.querySelector('svg')).toBeInTheDocument(); + const chip = container.querySelector('.studio-content-node-icon'); + + expect(chip).toHaveStyle({ backgroundColor: getContentKindColor(kind) }); + expect(iconShape(container)).toBe(iconShape(renderIcon(getContentKindIcon(kind)).container)); }, ); - it('renders nothing for an unsupported kind', () => { + it('uses the html5 glyph for h5p', () => { + const h5p = iconShape(renderComponent({ kind: 'h5p' }).container); + const html5 = iconShape(renderComponent({ kind: 'html5' }).container); + const video = iconShape(renderComponent({ kind: 'video' }).container); + + expect(h5p).toBe(html5); + expect(h5p).not.toBe(video); + }); + + it('renders the error icon for an unsupported kind', () => { const { container } = renderComponent({ kind: 'unsupported' }); - expect(container.querySelector('svg')).not.toBeInTheDocument(); + const chip = container.querySelector('.studio-content-node-icon'); + + expect(chip).toHaveStyle({ backgroundColor: getContentKindColor('unsupported') }); + expect(iconShape(container)).toBe(iconShape(renderIcon('error').container)); + }); + + it('does not swallow a missing icon mapping', () => { + const errorHandler = jest.fn(); + const previous = Vue.config.errorHandler; + Vue.config.errorHandler = errorHandler; + + try { + renderComponent({ kind: 'missing' }); + + expect(errorHandler).toHaveBeenCalled(); + expect(errorHandler.mock.calls[0][0]).toEqual( + expect.objectContaining({ message: 'Icon not found for content kind: missing' }), + ); + } finally { + Vue.config.errorHandler = previous; + } }); it('is marked to be captured as an image in PDF exports', () => { diff --git a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js index bf5f3d4a2f..282232f950 100644 --- a/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js +++ b/contentcuration/contentcuration/frontend/shared/views/__tests__/StudioDetailsPanel.spec.js @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/vue'; +import { render, screen, within } from '@testing-library/vue'; import VueRouter from 'vue-router'; import ContentLevels from 'kolibri-constants/labels/Levels'; import Categories from 'kolibri-constants/labels/Subjects'; @@ -123,14 +123,22 @@ describe('StudioDetailsPanel', () => { kind_count: [ { kind_id: 'video', count: 30 }, { kind_id: 'exercise', count: 12 }, + { kind_id: 'h5p', count: 7 }, ], }, loading: false, }); - expect(screen.getByText('Video')).toBeInTheDocument(); - expect(screen.getByText('30')).toBeInTheDocument(); - expect(screen.getByText('Exercise')).toBeInTheDocument(); - expect(screen.getByText('12')).toBeInTheDocument(); + + [ + ['Video', '30'], + ['Exercise', '12'], + ['H5P App', '7'], + ].forEach(([label, count]) => { + const row = screen.getByText(label).closest('.resource-item'); + expect(row).not.toBeNull(); + expect(within(row).getByText(count)).toBeInTheDocument(); + expect(row.querySelector('.studio-content-node-icon svg')).toBeInTheDocument(); + }); }); }); });