-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client): Rewrite
AppMenu
to TypeScript (#31533)
- Loading branch information
1 parent
6205ef1
commit 972b5b8
Showing
24 changed files
with
683 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import WarningModal from './WarningModal'; | ||
|
||
import '@testing-library/jest-dom'; | ||
|
||
it('should look good', async () => { | ||
render(<WarningModal text='text' confirmText='confirm' cancelText='cancel' confirm={() => undefined} close={() => undefined} />, { | ||
wrapper: mockAppRoot().build(), | ||
}); | ||
|
||
expect(screen.getByRole('heading')).toHaveTextContent('Are_you_sure'); | ||
expect(screen.getByRole('button', { name: 'cancel' })).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'confirm' })).toBeInTheDocument(); | ||
expect(screen.getByText('text')).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppStatus/AppStatus.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { mockedAppsContext } from '../../../../../../tests/mocks/client/marketplace'; | ||
import { createFakeApp, createFakeLicenseInfo } from '../../../../../../tests/mocks/data'; | ||
import AppStatus from './AppStatus'; | ||
|
||
it('should look good', async () => { | ||
const app = createFakeApp(); | ||
|
||
render(<AppStatus app={app} showStatus isAppDetailsPage />, { | ||
wrapper: mockAppRoot() | ||
.withJohnDoe() | ||
.withEndpoint('GET', '/apps/count', async () => ({ | ||
maxMarketplaceApps: faker.number.int({ min: 0 }), | ||
installedApps: faker.number.int({ min: 0 }), | ||
maxPrivateApps: faker.number.int({ min: 0 }), | ||
totalMarketplaceEnabled: faker.number.int({ min: 0 }), | ||
totalPrivateEnabled: faker.number.int({ min: 0 }), | ||
})) | ||
.withEndpoint('GET', '/v1/licenses.info', async () => ({ | ||
license: createFakeLicenseInfo(), | ||
})) | ||
.wrap(mockedAppsContext) | ||
.build(), | ||
}); | ||
|
||
screen.getByRole('button', { name: 'Request' }).click(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { mockedAppsContext } from '../../../tests/mocks/client/marketplace'; | ||
import { createFakeApp } from '../../../tests/mocks/data'; | ||
import AppMenu from './AppMenu'; | ||
|
||
describe('without app details', () => { | ||
it('should look good', async () => { | ||
const app = createFakeApp(); | ||
|
||
render(<AppMenu app={app} isAppDetailsPage={false} />, { | ||
wrapper: mockAppRoot() | ||
.withEndpoint('GET', '/apps/count', async () => ({ | ||
maxMarketplaceApps: faker.number.int({ min: 0 }), | ||
installedApps: faker.number.int({ min: 0 }), | ||
maxPrivateApps: faker.number.int({ min: 0 }), | ||
totalMarketplaceEnabled: faker.number.int({ min: 0 }), | ||
totalPrivateEnabled: faker.number.int({ min: 0 }), | ||
})) | ||
.wrap(mockedAppsContext) | ||
.build(), | ||
}); | ||
|
||
expect(screen.getByRole('button', { name: 'More_options' })).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { App } from '@rocket.chat/core-typings'; | ||
import { MenuItem, MenuItemContent, MenuSection, MenuV2, Skeleton } from '@rocket.chat/fuselage'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React, { memo } from 'react'; | ||
|
||
import { useHandleMenuAction } from '../../components/GenericMenu/hooks/useHandleMenuAction'; | ||
import type { AppMenuOption } from './hooks/useAppMenu'; | ||
import { useAppMenu } from './hooks/useAppMenu'; | ||
|
||
type AppMenuProps = { | ||
app: App; | ||
isAppDetailsPage: boolean; | ||
}; | ||
|
||
const AppMenu = ({ app, isAppDetailsPage }: AppMenuProps) => { | ||
const t = useTranslation(); | ||
|
||
const { isLoading, isAdminUser, sections } = useAppMenu(app, isAppDetailsPage); | ||
|
||
const itemsList = sections.reduce((acc, { items }) => [...acc, ...items], [] as AppMenuOption[]); | ||
|
||
const onAction = useHandleMenuAction(itemsList); | ||
const disabledKeys = itemsList.filter((item) => item.disabled).map((item) => item.id); | ||
|
||
if (isLoading) { | ||
return <Skeleton variant='rect' height='x28' width='x28' />; | ||
} | ||
|
||
if (!isAdminUser && app?.installed && sections.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<MenuV2 title={t('More_options')} onAction={onAction} disabledKeys={disabledKeys} detached> | ||
{sections.map(({ items }, idx) => ( | ||
<MenuSection key={idx} items={items}> | ||
{items.map((option) => ( | ||
<MenuItem key={option.id}> | ||
<MenuItemContent>{option.content}</MenuItemContent> | ||
</MenuItem> | ||
))} | ||
</MenuSection> | ||
))} | ||
</MenuV2> | ||
); | ||
}; | ||
|
||
export default memo(AppMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.