-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
50 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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { CredentialsDataSPI } from '@/modules/credentials/core/domain'; | ||
import { Result } from 'oxide.ts'; | ||
import { BackendError } from '@/modules/common/error'; | ||
|
||
export async function validateCredentials( | ||
credentialsDataSPI: CredentialsDataSPI, | ||
profileName: string | ||
) { | ||
): Promise<Result<boolean, BackendError>> { | ||
return credentialsDataSPI.validateCredentials(profileName); | ||
} |
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
85 changes: 49 additions & 36 deletions
85
src/sections/profiles/components/test-credentials-button.test.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 |
---|---|---|
@@ -1,55 +1,68 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import TestCredentialsButton from './test-credentials-button'; | ||
import { clearMocks, mockIPC } from '@tauri-apps/api/mocks'; | ||
import { SWRConfig } from 'swr'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { TooltipProvider } from '@/components/ui/tooltip'; | ||
import { validateCredentials } from '@/modules/credentials/application/validateCredentials'; | ||
import { Ok } from 'oxide.ts'; | ||
import { DIContextProvider } from '@/context/di-context'; | ||
|
||
jest.mock('@/modules/credentials/application/validateCredentials', () => ({ | ||
...jest.requireActual( | ||
'@/modules/credentials/application/validateCredentials' | ||
), | ||
validateCredentials: jest.fn(), | ||
})); | ||
|
||
const mockValidateCredentials = validateCredentials as jest.MockedFunction< | ||
typeof validateCredentials | ||
>; | ||
|
||
describe('<TestCredentialsButton />', () => { | ||
afterEach(() => { | ||
clearMocks(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should render shield alert icon when profile credentials are invalid', async () => { | ||
mockIPC((cmd) => { | ||
if (cmd === 'validate_credentials') { | ||
return false; | ||
} | ||
jest.isolateModules(async () => { | ||
mockValidateCredentials.mockResolvedValue(Ok(false)); | ||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<TooltipProvider> | ||
<DIContextProvider> | ||
<TestCredentialsButton profile='prof1' /> | ||
</DIContextProvider> | ||
</TooltipProvider> | ||
</SWRConfig> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
await userEvent.click(button); | ||
|
||
const shieldSvg = button.querySelector('svg'); | ||
expect(shieldSvg).toHaveClass('lucide-shield-alert'); | ||
}); | ||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<TooltipProvider> | ||
<TestCredentialsButton profile='prof1' /> | ||
</TooltipProvider> | ||
</SWRConfig> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
await userEvent.click(button); | ||
|
||
const shieldSvg = button.querySelector('svg'); | ||
expect(shieldSvg).toHaveClass('lucide-shield-alert'); | ||
}); | ||
|
||
it('should render shield check icon when profile credentials are valid', async () => { | ||
mockIPC((cmd) => { | ||
if (cmd === 'validate_credentials') { | ||
return true; | ||
} | ||
jest.isolateModules(async () => { | ||
mockValidateCredentials.mockResolvedValue(Ok(true)); | ||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<TooltipProvider> | ||
<DIContextProvider> | ||
<TestCredentialsButton profile='prof1' /> | ||
</DIContextProvider> | ||
</TooltipProvider> | ||
</SWRConfig> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
await userEvent.click(button); | ||
|
||
const shieldSvg = button.querySelector('svg'); | ||
expect(shieldSvg).toHaveClass('lucide-shield-check'); | ||
}); | ||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<TooltipProvider> | ||
<TestCredentialsButton profile='prof1' /> | ||
</TooltipProvider> | ||
</SWRConfig> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
await userEvent.click(button); | ||
|
||
const shieldSvg = button.querySelector('svg'); | ||
expect(shieldSvg).toHaveClass('lucide-shield-check'); | ||
}); | ||
}); |