diff --git a/packages/manager/apps/web-office/public/translations/dashboard/users/Messages_fr_FR.json b/packages/manager/apps/web-office/public/translations/dashboard/users/Messages_fr_FR.json index aa7079f8161c..27dc83885c96 100644 --- a/packages/manager/apps/web-office/public/translations/dashboard/users/Messages_fr_FR.json +++ b/packages/manager/apps/web-office/public/translations/dashboard/users/Messages_fr_FR.json @@ -15,5 +15,6 @@ "dashboard_users_action_user_change_password": "Changer le mot de passe", "dashboard_users_action_user_edit": "Editer le compte", "dashboard_users_action_user_delete": "Supprimer le compte", - "dashboard_users_order_button_licenses": "Commander plus de licenses" + "dashboard_users_order_button_licenses": "Commander plus de licences", + "dashboard_users_order_button_users": "Ajouter un utilisateur" } diff --git a/packages/manager/apps/web-office/src/pages/dashboard/users/Users.tsx b/packages/manager/apps/web-office/src/pages/dashboard/users/Users.tsx index 386c837a5a49..83b11b29c90a 100644 --- a/packages/manager/apps/web-office/src/pages/dashboard/users/Users.tsx +++ b/packages/manager/apps/web-office/src/pages/dashboard/users/Users.tsx @@ -28,10 +28,6 @@ export default function Users() { isLoading: isLoadingLicenceDetail, } = useOfficeLicenseDetail(); - if (isLoadingUsers || isLoadingLicenceDetail) { - return ; - } - const columns: DatagridColumn[] = [ { id: 'firstName', @@ -113,21 +109,31 @@ export default function Users() {

{t('dashboard_users_download_info')}

{t('dashboard_users_download_id')} - - {columns && ( - ({ - ...column, - label: t(column.label), - }))} - items={dataUsers || []} - totalItems={dataUsers?.length || 0} - className="mt-4" - /> + + {isLoadingUsers || isLoadingLicenceDetail ? ( + + ) : ( + <> + + ({ + ...column, + label: t(column.label), + }))} + items={dataUsers || []} + totalItems={dataUsers?.length || 0} + className="mt-4" + /> + )} ); diff --git a/packages/manager/apps/web-office/src/pages/dashboard/users/__test__/Users.spec.tsx b/packages/manager/apps/web-office/src/pages/dashboard/users/__test__/Users.spec.tsx index 9ef80afb3336..72a5785ba22f 100644 --- a/packages/manager/apps/web-office/src/pages/dashboard/users/__test__/Users.spec.tsx +++ b/packages/manager/apps/web-office/src/pages/dashboard/users/__test__/Users.spec.tsx @@ -2,21 +2,54 @@ import React from 'react'; import { describe, expect, vi } from 'vitest'; import Users from '../Users'; import { render } from '@/utils/test.provider'; -import usersTranslation from '@/public/translations/dashboard/users/Messages_fr_FR.json'; -import { licensesMock, usersMock } from '@/api/_mock_'; +import { + licensesMock, + licensesPrepaidExpandedMock, + usersMock, +} from '@/api/_mock_'; + +const hoistedMock = vi.hoisted(() => ({ + useOfficeUsers: vi.fn(), + useOfficeLicenseDetail: vi.fn(), +})); + +vi.mock('@/hooks', async (importActual) => { + const actual = await importActual(); + return { + ...actual, + useOfficeUsers: hoistedMock.useOfficeUsers, + useOfficeLicenseDetail: hoistedMock.useOfficeLicenseDetail, + }; +}); describe('Users page', () => { - vi.mock('@/hooks', () => { - return { - useOfficeUsers: vi.fn(() => usersMock), - useOfficeLicenseDetail: vi.fn(() => licensesMock), - }; + it('Page for payAsYouGo', () => { + hoistedMock.useOfficeLicenseDetail.mockReturnValue({ + data: licensesMock[0], + isLoading: false, + }); + hoistedMock.useOfficeUsers.mockReturnValue({ + data: usersMock, + isLoading: false, + }); + + const { getByTestId } = render(); + const orderButton = getByTestId('user-or-licenses-order-button'); + expect(orderButton).toHaveAttribute('label', 'Ajouter un utilisateur'); }); - it('Page should display correctly', async () => { - const { findByText } = render(); - expect( - await findByText(usersTranslation.dashboard_users_download_info), - ).toBeVisible(); + it('Page for prepaid', () => { + hoistedMock.useOfficeLicenseDetail.mockReturnValue({ + data: licensesPrepaidExpandedMock[0], + isLoading: false, + }); + hoistedMock.useOfficeUsers.mockReturnValue({ + data: licensesPrepaidExpandedMock[0], + isLoading: false, + }); + + const { getByTestId } = render(); + const orderButton = getByTestId('user-or-licenses-order-button'); + expect(orderButton).toHaveAttribute('label', 'Commander plus de licences'); }); }); diff --git a/packages/manager/apps/web-office/src/utils/test.setup.tsx b/packages/manager/apps/web-office/src/utils/test.setup.tsx index 21c7021685a7..9b891afd92a2 100644 --- a/packages/manager/apps/web-office/src/utils/test.setup.tsx +++ b/packages/manager/apps/web-office/src/utils/test.setup.tsx @@ -54,7 +54,9 @@ vi.mock('@/api/license', async (importActual) => { }), getOfficeLicenseDetails: vi.fn((serviceName) => { return Promise.resolve( - licensesMock.find((license) => license.serviceName === serviceName), + [...licensesMock, ...licensesPrepaidExpandedMock].find( + (license) => license.serviceName === serviceName, + ), ); }), getOfficePrepaidLicenses: vi.fn(() => {