diff --git a/orga/app/components/layout/user-logged-menu.gjs b/orga/app/components/layout/user-logged-menu.gjs index 71fd66be5a4..e47a750e47a 100644 --- a/orga/app/components/layout/user-logged-menu.gjs +++ b/orga/app/components/layout/user-logged-menu.gjs @@ -1,8 +1,8 @@ +import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; +import PixStructureSwitcher from '@1024pix/pix-ui/components/pix-structure-switcher'; import { action } from '@ember/object'; import { service } from '@ember/service'; import Component from '@glimmer/component'; -import PixStructureSwitcher from '@1024pix/pix-ui/components/pix-structure-switcher'; -import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; import { t } from 'ember-intl'; export default class UserLoggedMenu extends Component { @@ -25,10 +25,18 @@ export default class UserLoggedMenu extends Component { } return memberships .slice() - .map((membership) => ({ - label: `${membership.organization.get('name')} (${membership.organization.get('externalId')})`, - value: membership.organization.get('id'), - })) + .map((membership) => { + let label = `${membership.organization.get('name')}`; + + if (membership.organization.get('externalId')) { + label = label.concat(` (${membership.organization.get('externalId')})`); + } + + return { + label, + value: membership.organization.get('id'), + }; + }) .sort((a, b) => a.label.localeCompare(b.label)); } diff --git a/orga/tests/integration/components/layout/user-logged-menu-test.js b/orga/tests/integration/components/layout/user-logged-menu-test.js index 34dae84780e..91ec9fa4dd9 100644 --- a/orga/tests/integration/components/layout/user-logged-menu-test.js +++ b/orga/tests/integration/components/layout/user-logged-menu-test.js @@ -24,7 +24,7 @@ module('Integration | Component | Layout::UserLoggedMenu', function () { }), }); organization2 = Object.create({ id: '2', name: 'Organization 2', externalId: 'EXT2' }); - organization3 = Object.create({ id: '3', name: 'Organization 3', externalId: 'EXT3' }); + organization3 = Object.create({ id: '3', name: 'Organization 3' }); loadStub = sinon.stub(); class CurrentUserStub extends Service { @@ -75,7 +75,7 @@ module('Integration | Component | Layout::UserLoggedMenu', function () { // then assert.ok(await screen.findByRole('option', { name: `${organization2.name} (${organization2.externalId})` })); - assert.ok(await screen.findByRole('option', { name: `${organization3.name} (${organization3.externalId})` })); + assert.ok(await screen.findByRole('option', { name: `${organization3.name}` })); }); test('should redirect to authenticated route before reload the current user', async function (assert) { diff --git a/orga/tests/unit/components/user-logged-menu-test.js b/orga/tests/unit/components/user-logged-menu-test.js deleted file mode 100644 index 6f86f24bfe5..00000000000 --- a/orga/tests/unit/components/user-logged-menu-test.js +++ /dev/null @@ -1,41 +0,0 @@ -import { setupTest } from 'ember-qunit'; -import { module, test } from 'qunit'; - -import createGlimmerComponent from '../../helpers/create-glimmer-component'; - -module('Unit | Component | user-logged-menu', (hooks) => { - setupTest(hooks); - - let component; - - hooks.beforeEach(function () { - component = createGlimmerComponent('component:layout/user-logged-menu'); - }); - - module('organizationNameAndExternalId', () => { - test('should return the organization name if the externalId is not defined', function (assert) { - // given - const expectedOrganizationName = 'expectedOrganizationName'; - const currentUser = { organization: { name: expectedOrganizationName } }; - component.currentUser = currentUser; - - // when - const computedOrganizationName = component.organizationNameAndExternalId; - // then - assert.strictEqual(computedOrganizationName, expectedOrganizationName); - }); - - test('should return the organization name and externalId if the externalId is defined', function (assert) { - // given - const expectedOrganizationName = 'expectedOrganizationName'; - const expectedExternalId = 'expectedExternalId'; - const currentUser = { organization: { name: expectedOrganizationName, externalId: expectedExternalId } }; - component.currentUser = currentUser; - - // when - const computedOrganizationName = component.organizationNameAndExternalId; - // then - assert.strictEqual(computedOrganizationName, `${expectedOrganizationName} (${expectedExternalId})`); - }); - }); -});