diff --git a/react/AppSections/__snapshots__/index.spec.jsx.snap b/react/AppSections/__snapshots__/index.spec.jsx.snap index 0475d21e14..97758b875a 100644 --- a/react/AppSections/__snapshots__/index.spec.jsx.snap +++ b/react/AppSections/__snapshots__/index.spec.jsx.snap @@ -1075,11 +1075,6 @@ exports[`AppsSection component should render dropdown filter on mobile if no nav "type": "webapp", "value": "partners", }, - Object { - "label": "Additional apps", - "secondary": false, - "value": "shortcuts", - }, Object { "label": "Services", "secondary": false, @@ -1481,11 +1476,6 @@ exports[`AppsSection component should render dropdown filter on tablet if no nav "type": "webapp", "value": "partners", }, - Object { - "label": "Additional apps", - "secondary": false, - "value": "shortcuts", - }, Object { "label": "Services", "secondary": false, diff --git a/react/AppSections/categories.js b/react/AppSections/categories.js index 3b5ba43b32..28a5a2b5a8 100644 --- a/react/AppSections/categories.js +++ b/react/AppSections/categories.js @@ -109,7 +109,9 @@ export const generateOptionsFromApps = (apps, options = {}) => { }) ) } - if (type === APP_TYPE.FILE) { + + const categories = Object.keys(catApps) + if (type === APP_TYPE.FILE && categories.length > 0) { allCategoryOptions.push( addLabel({ value: 'shortcuts', @@ -117,7 +119,8 @@ export const generateOptionsFromApps = (apps, options = {}) => { }) ) } - const categoryOptions = Object.keys(catApps).map(cat => { + + const categoryOptions = categories.map(cat => { return addLabel({ value: cat, type: type, diff --git a/react/AppSections/categories.spec.js b/react/AppSections/categories.spec.js index 83a1c3a80b..4c440b8664 100644 --- a/react/AppSections/categories.spec.js +++ b/react/AppSections/categories.spec.js @@ -10,7 +10,14 @@ import { I18nContext } from '../jestLib/I18n' import mockApps from '../mocks/apps' const i18nContext = I18nContext({ - locale: en + locale: { + ...en, + app_categories: { + ...en.app_categories, + foo: 'Foo', + bar: 'Bar' + } + } }) const tMock = i18nContext.t @@ -104,7 +111,6 @@ describe('generateOptionsFromApps', () => { type: 'webapp', value: 'others' }, - { label: 'Additional apps', secondary: false, value: 'shortcuts' }, { label: 'Services', secondary: false, @@ -157,11 +163,6 @@ describe('generateOptionsFromApps', () => { type: 'webapp', value: 'others' }, - { - label: 'Additional apps', - secondary: false, - value: 'shortcuts' - }, { label: 'Services', secondary: false, @@ -199,4 +200,90 @@ describe('generateOptionsFromApps', () => { catUtils.generateOptionsFromApps(null, { includeAll: false, addLabel }) ).toEqual([]) }) + + it('should return additional apps categories when there more than one', () => { + const appsWithAdditionlOnes = [ + ...mockApps, + { + _id: 'shortcutA', + name: 'Shortcut A', + categories: ['foo'], + type: 'file', + _type: 'io.cozy.files' + }, + { + _id: 'shortcutB', + name: 'Shortcut B', + categories: ['bar'], + type: 'file', + _type: 'io.cozy.files' + } + ] + + expect( + catUtils.generateOptionsFromApps(appsWithAdditionlOnes, { + includeAll: false, + addLabel + }) + ).toEqual([ + { + label: 'The essentials', + secondary: false, + type: 'webapp', + value: 'cozy' + }, + { + label: 'Partners', + secondary: false, + type: 'webapp', + value: 'partners' + }, + { + label: 'Others', + secondary: false, + type: 'webapp', + value: 'others' + }, + { + label: 'Additional apps', + secondary: false, + value: 'shortcuts' + }, + { + label: 'Bar', + secondary: true, + type: 'file', + value: 'bar' + }, + { + label: 'Foo', + secondary: true, + type: 'file', + value: 'foo' + }, + { + label: 'Services', + secondary: false, + value: 'konnectors' + }, + { + label: 'Mobile and Internet', + secondary: true, + type: 'konnector', + value: 'isp' + }, + { + label: 'Telecom', + secondary: true, + type: 'konnector', + value: 'telecom' + }, + { + label: 'Transportation', + secondary: true, + type: 'konnector', + value: 'transport' + } + ]) + }) })