From c65630bb2917b1cd7d764f8d80cf271028f254c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 15 Feb 2024 16:58:06 -0300 Subject: [PATCH 1/3] feat: add export library tags menu --- .../studio-header-wrapper/messages.js | 5 ++++ .../studio-header-wrapper/specs/utils.spec.js | 23 +++++++++++++++++++ .../studio-header-wrapper/utils.js | 7 ++++++ 3 files changed, 35 insertions(+) diff --git a/src/library-authoring/studio-header-wrapper/messages.js b/src/library-authoring/studio-header-wrapper/messages.js index 804a0e12..b702c754 100644 --- a/src/library-authoring/studio-header-wrapper/messages.js +++ b/src/library-authoring/studio-header-wrapper/messages.js @@ -27,6 +27,11 @@ const messages = defineMessages({ defaultMessage: 'Import', description: 'Text for the import course in the settings menu.', }, + 'library.header.settings.exportTags': { + id: 'library.header.settings.exportTags', + defaultMessage: 'Export Tags', + description: 'Download library content tags as CSV', + }, 'library.header.nav.help.title': { id: 'library.header.nav.help.title', defaultMessage: 'Online help', diff --git a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js index e02d2972..d65dca6e 100644 --- a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js +++ b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js @@ -1,3 +1,4 @@ +import { getConfig, setConfig } from '@edx/frontend-platform'; import { LOADING_STATUS } from '../../common'; import { getMainMenuDropdown, getOutlineLink } from '../utils'; @@ -32,4 +33,26 @@ describe('studio header wrapper utils', () => { expect(dropdownArray).toHaveLength(0); }); }); + it('should show the export tags sub item when the flag is true', () => { + const libraryId = 'testId'; + const loadingStatus = LOADING_STATUS.LOADED; + setConfig({ + ...getConfig(), + ENABLE_TAGGING_TAXONOMY_PAGES: 'true', + }); + const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, { formatMessage: jest.fn() }); + expect(dropdownArray).toHaveLength(1); + expect(dropdownArray[0].items.some(item => item.title === 'Export Tags')); + }); + it('should not show the export tags sub item when the flag is false', () => { + const libraryId = 'testId'; + const loadingStatus = LOADING_STATUS.LOADED; + setConfig({ + ...getConfig(), + ENABLE_TAGGING_TAXONOMY_PAGES: 'false', + }); + const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, { formatMessage: jest.fn() }); + expect(dropdownArray).toHaveLength(1); + expect(dropdownArray[0].items.every(item => item.title !== 'Export Tags')); + }); }); diff --git a/src/library-authoring/studio-header-wrapper/utils.js b/src/library-authoring/studio-header-wrapper/utils.js index 4535dd11..cca51e87 100644 --- a/src/library-authoring/studio-header-wrapper/utils.js +++ b/src/library-authoring/studio-header-wrapper/utils.js @@ -1,3 +1,4 @@ +import { getConfig } from '@edx/frontend-platform'; import { LOADING_STATUS, ROUTES } from '../common'; import messages from './messages'; @@ -23,6 +24,12 @@ export const getMainMenuDropdown = (loadingStatus, libraryId, intl) => { href: ROUTES.Detail.ACCESS_SLUG(libraryId), title: intl.formatMessage(messages['library.header.settings.access']), }, + ...(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES === 'true' ? [ + { + href: `${getConfig().STUDIO_BASE_URL}/api/content_tagging/v1/object_tags/${libraryId}/export/`, + title: intl.formatMessage(messages['library.header.settings.exportTags']), + }, + ] : []), { href: ROUTES.Detail.IMPORT_SLUG(libraryId), title: intl.formatMessage(messages['library.header.settings.import']), From 2d2fe7e84e72ac5eae6539ca49dcbaddbc0447b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 16 Feb 2024 10:49:25 -0300 Subject: [PATCH 2/3] test: check menu titles instead of count --- .../studio-header-wrapper/specs/utils.spec.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js index d65dca6e..54f3a883 100644 --- a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js +++ b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js @@ -2,6 +2,10 @@ import { getConfig, setConfig } from '@edx/frontend-platform'; import { LOADING_STATUS } from '../../common'; import { getMainMenuDropdown, getOutlineLink } from '../utils'; +const intl = { + formatMessage: jest.fn(message => message.defaultMessage), +}; + describe('studio header wrapper utils', () => { describe('getOutlineLink', () => { it('should return /library/:libraryId', () => { @@ -33,6 +37,7 @@ describe('studio header wrapper utils', () => { expect(dropdownArray).toHaveLength(0); }); }); + it('should show the export tags sub item when the flag is true', () => { const libraryId = 'testId'; const loadingStatus = LOADING_STATUS.LOADED; @@ -40,9 +45,15 @@ describe('studio header wrapper utils', () => { ...getConfig(), ENABLE_TAGGING_TAXONOMY_PAGES: 'true', }); - const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, { formatMessage: jest.fn() }); + const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, intl); expect(dropdownArray).toHaveLength(1); - expect(dropdownArray[0].items.some(item => item.title === 'Export Tags')); + const subItemTitles = dropdownArray[0].items.map(item => item.title); + expect(subItemTitles).toEqual([ + 'Details', + 'User access', + 'Export Tags', + 'Import', + ]); }); it('should not show the export tags sub item when the flag is false', () => { const libraryId = 'testId'; @@ -51,8 +62,13 @@ describe('studio header wrapper utils', () => { ...getConfig(), ENABLE_TAGGING_TAXONOMY_PAGES: 'false', }); - const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, { formatMessage: jest.fn() }); + const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, intl); expect(dropdownArray).toHaveLength(1); - expect(dropdownArray[0].items.every(item => item.title !== 'Export Tags')); + const subItemTitles = dropdownArray[0].items.map(item => item.title); + expect(subItemTitles).toEqual([ + 'Details', + 'User access', + 'Import', + ]); }); }); From b7af48662d7218036194d8a05924ac9444f4b77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 16 Feb 2024 15:27:27 -0300 Subject: [PATCH 3/3] fix: remove flag check --- .../studio-header-wrapper/specs/utils.spec.js | 46 ++++--------------- .../studio-header-wrapper/utils.js | 10 ++-- 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js index 54f3a883..95f70dad 100644 --- a/src/library-authoring/studio-header-wrapper/specs/utils.spec.js +++ b/src/library-authoring/studio-header-wrapper/specs/utils.spec.js @@ -1,4 +1,3 @@ -import { getConfig, setConfig } from '@edx/frontend-platform'; import { LOADING_STATUS } from '../../common'; import { getMainMenuDropdown, getOutlineLink } from '../utils'; @@ -24,11 +23,18 @@ describe('studio header wrapper utils', () => { }); }); describe('getMainMenuDropdown', () => { - it('should return an array of length 1', () => { + it('should return an array of length 1 and correct items', () => { const libraryId = 'testId'; const loadingStatus = LOADING_STATUS.LOADED; - const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, { formatMessage: jest.fn() }); + const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, intl); expect(dropdownArray).toHaveLength(1); + const subItemTitles = dropdownArray[0].items.map(item => item.title); + expect(subItemTitles).toEqual([ + 'Details', + 'User access', + 'Export Tags', + 'Import', + ]); }); it('should return an empty array', () => { const libraryId = 'testId'; @@ -37,38 +43,4 @@ describe('studio header wrapper utils', () => { expect(dropdownArray).toHaveLength(0); }); }); - - it('should show the export tags sub item when the flag is true', () => { - const libraryId = 'testId'; - const loadingStatus = LOADING_STATUS.LOADED; - setConfig({ - ...getConfig(), - ENABLE_TAGGING_TAXONOMY_PAGES: 'true', - }); - const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, intl); - expect(dropdownArray).toHaveLength(1); - const subItemTitles = dropdownArray[0].items.map(item => item.title); - expect(subItemTitles).toEqual([ - 'Details', - 'User access', - 'Export Tags', - 'Import', - ]); - }); - it('should not show the export tags sub item when the flag is false', () => { - const libraryId = 'testId'; - const loadingStatus = LOADING_STATUS.LOADED; - setConfig({ - ...getConfig(), - ENABLE_TAGGING_TAXONOMY_PAGES: 'false', - }); - const dropdownArray = getMainMenuDropdown(loadingStatus, libraryId, intl); - expect(dropdownArray).toHaveLength(1); - const subItemTitles = dropdownArray[0].items.map(item => item.title); - expect(subItemTitles).toEqual([ - 'Details', - 'User access', - 'Import', - ]); - }); }); diff --git a/src/library-authoring/studio-header-wrapper/utils.js b/src/library-authoring/studio-header-wrapper/utils.js index cca51e87..3cb9f133 100644 --- a/src/library-authoring/studio-header-wrapper/utils.js +++ b/src/library-authoring/studio-header-wrapper/utils.js @@ -24,12 +24,10 @@ export const getMainMenuDropdown = (loadingStatus, libraryId, intl) => { href: ROUTES.Detail.ACCESS_SLUG(libraryId), title: intl.formatMessage(messages['library.header.settings.access']), }, - ...(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES === 'true' ? [ - { - href: `${getConfig().STUDIO_BASE_URL}/api/content_tagging/v1/object_tags/${libraryId}/export/`, - title: intl.formatMessage(messages['library.header.settings.exportTags']), - }, - ] : []), + { + href: `${getConfig().STUDIO_BASE_URL}/api/content_tagging/v1/object_tags/${libraryId}/export/`, + title: intl.formatMessage(messages['library.header.settings.exportTags']), + }, { href: ROUTES.Detail.IMPORT_SLUG(libraryId), title: intl.formatMessage(messages['library.header.settings.import']),