-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Unit test for AppDetailsPage.tsx
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
apps/meteor/client/views/marketplace/AppDetailsPage/AppDetailsPage.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,66 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import AppDetailsPage from './AppDetailsPage'; | ||
import { AppClientOrchestratorInstance } from '../../../apps/orchestrator'; | ||
import { useAppInfo } from '../hooks/useAppInfo'; | ||
|
||
jest.mock('../hooks/useAppInfo', () => ({ | ||
useAppInfo: jest.fn(), | ||
})); | ||
|
||
jest.mock('@rocket.chat/ui-contexts', () => ({ | ||
useTranslation: () => (key: string) => key, | ||
useRouter: () => ({ navigate: jest.fn() }), | ||
useToastMessageDispatch: () => jest.fn(), | ||
usePermission: () => true, | ||
useRouteParameter: jest.fn(() => null), | ||
})); | ||
|
||
jest.mock('../../../apps/orchestrator', () => ({ | ||
AppClientOrchestratorInstance: { | ||
setAppSettings: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('AppDetailsPage', () => { | ||
beforeEach(() => { | ||
(useAppInfo as jest.Mock).mockReturnValue({ | ||
id: 'app123', | ||
name: 'Test App', | ||
installed: true, | ||
settings: { | ||
setting1: { id: 'setting1', value: 'old-value', packageValue: 'default-value' }, | ||
}, | ||
privacyPolicySummary: '', | ||
permissions: [], | ||
tosLink: '', | ||
privacyLink: '', | ||
}); | ||
(AppClientOrchestratorInstance.setAppSettings as jest.Mock).mockReset(); | ||
}); | ||
|
||
it('should remove loading state on Save button, reset form, and hide the button after successful save', async () => { | ||
(AppClientOrchestratorInstance.setAppSettings as jest.Mock).mockResolvedValueOnce({}); | ||
|
||
render(<AppDetailsPage id='app123' />); | ||
|
||
const saveButton = screen.getByRole('button', { name: /Save_changes/i }); | ||
|
||
expect(saveButton).not.toBeDisabled(); | ||
|
||
await userEvent.click(saveButton); | ||
|
||
await waitFor(() => { | ||
expect(saveButton).toBeDisabled(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(saveButton).not.toBeDisabled(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByRole('button', { name: /Save_changes/i })).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |