Compare commits
2 Commits
codex/refa
...
codex/refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68f4dff852 | ||
|
|
a85e583720 |
@@ -141,11 +141,6 @@
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx": {
|
||||
"no-restricted-imports": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx": {
|
||||
"jsx_a11y/tabindex-no-positive": {
|
||||
"count": 3
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import MailAndCodeAuth from '../mail-and-code-auth'
|
||||
|
||||
const pushMock = vi.fn()
|
||||
const replaceMock = vi.fn()
|
||||
const setCountdownLeftTimeMock = vi.fn()
|
||||
const sendWebAppEMailLoginCodeMock = vi.fn()
|
||||
const searchParams = new URLSearchParams({
|
||||
redirect_url: encodeURIComponent('/chatbot/test-app'),
|
||||
})
|
||||
|
||||
vi.mock('@/next/navigation', () => ({
|
||||
useRouter: () => ({ push: pushMock, replace: replaceMock }),
|
||||
useSearchParams: () => searchParams,
|
||||
}))
|
||||
|
||||
vi.mock('@/context/i18n', () => ({
|
||||
useLocale: () => 'en-US',
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/signin/storage', () => ({
|
||||
COUNT_DOWN_TIME_MS: 60_000,
|
||||
useSetCountdownLeftTime: () => setCountdownLeftTimeMock,
|
||||
}))
|
||||
|
||||
vi.mock('@/service/common', () => ({
|
||||
sendWebAppEMailLoginCode: (...args: unknown[]) => sendWebAppEMailLoginCodeMock(...args),
|
||||
}))
|
||||
|
||||
describe('MailAndCodeAuth', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
sendWebAppEMailLoginCodeMock.mockResolvedValue({ result: 'success', data: 'token-abc' })
|
||||
})
|
||||
|
||||
it('submits from the email field through the native form', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<MailAndCodeAuth />)
|
||||
|
||||
const emailInput = screen.getByRole('textbox', { name: 'login.email' })
|
||||
const submitButton = screen.getByRole('button', { name: 'login.signup.verifyMail' })
|
||||
|
||||
expect(emailInput).toHaveAttribute('name', 'email')
|
||||
expect(emailInput).toHaveAttribute('autocomplete', 'email')
|
||||
expect(emailInput).toHaveAttribute('spellcheck', 'false')
|
||||
expect(submitButton).toHaveAttribute('type', 'submit')
|
||||
|
||||
await user.tab()
|
||||
expect(emailInput).toHaveFocus()
|
||||
await user.type(emailInput, 'user@example.com{Enter}')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendWebAppEMailLoginCodeMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
expect(pushMock).toHaveBeenCalledWith(expect.stringContaining('/webapp-signin/check-code?'))
|
||||
})
|
||||
})
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Button } from '@langgenius/dify-ui/button'
|
||||
import { Field, FieldControl, FieldLabel } from '@langgenius/dify-ui/field'
|
||||
import { Form } from '@langgenius/dify-ui/form'
|
||||
import { toast } from '@langgenius/dify-ui/toast'
|
||||
import { noop } from 'es-toolkit/function'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { resolveWebAppLoginRedirect } from '@/app/(shareLayout)/webapp-signin/login-redirect'
|
||||
import Input from '@/app/components/base/input'
|
||||
import { COUNT_DOWN_TIME_MS, useSetCountdownLeftTime } from '@/app/components/signin/storage'
|
||||
import { emailRegex } from '@/config'
|
||||
import { useLocale } from '@/context/i18n'
|
||||
@@ -64,33 +64,37 @@ export default function MailAndCodeAuth() {
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={noop}>
|
||||
<input type="text" className="hidden" />
|
||||
<div className="mb-2">
|
||||
<label htmlFor="email" className="my-2 system-md-semibold text-text-secondary">
|
||||
<Form
|
||||
onFormSubmit={() => {
|
||||
void handleGetEMailVerificationCode()
|
||||
}}
|
||||
>
|
||||
<Field name="email" className="mb-2 block">
|
||||
<FieldLabel className="my-2 py-0 system-md-semibold! text-text-secondary">
|
||||
{t(($) => $.email, { ns: 'login' })}
|
||||
</label>
|
||||
</FieldLabel>
|
||||
<div className="mt-1">
|
||||
<Input
|
||||
id="email"
|
||||
<FieldControl
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
spellCheck={false}
|
||||
value={email}
|
||||
placeholder={t(($) => $.emailPlaceholder, { ns: 'login' }) as string}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
onValueChange={setEmail}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<Button
|
||||
type="submit"
|
||||
loading={loading}
|
||||
disabled={loading || !email}
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
onClick={handleGetEMailVerificationCode}
|
||||
>
|
||||
{t(($) => $['signup.verifyMail'], { ns: 'login' })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Field>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
||||
import CodeGenerateBtn from '../code-generator-button'
|
||||
|
||||
vi.mock('@/app/components/app/configuration/config/code-generator/get-code-generator-res', () => ({
|
||||
GetCodeGeneratorResModal: () => <div role="dialog" aria-label="code generator" />,
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/workflow/hooks-store', () => ({
|
||||
useHooksStore: (selector: (state: { configsMap: { flowId: string } }) => unknown) =>
|
||||
selector({ configsMap: { flowId: 'flow-1' } }),
|
||||
}))
|
||||
|
||||
describe('CodeGenerateBtn', () => {
|
||||
it('should open the code generator from the named action', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<CodeGenerateBtn nodeId="node-1" codeLanguages={CodeLanguage.python3} />)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'appDebug.operation.automatic' }))
|
||||
|
||||
expect(screen.getByRole('dialog', { name: 'code generator' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -5,9 +5,9 @@ import type { GenRes } from '@/service/debug'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import * as React from 'react'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { GetCodeGeneratorResModal } from '@/app/components/app/configuration/config/code-generator/get-code-generator-res'
|
||||
import { ActionButton } from '@/app/components/base/action-button'
|
||||
import { Generator } from '@/app/components/base/icons/src/vender/other'
|
||||
import { AppModeEnum } from '@/types/app'
|
||||
import { useHooksStore } from '../../../hooks-store'
|
||||
|
||||
@@ -26,7 +26,6 @@ const CodeGenerateBtn: FC<Props> = ({
|
||||
codeLanguages,
|
||||
onGenerated,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const [showAutomatic, setShowAutomatic] = useState(false)
|
||||
const handleAutomaticRes = useCallback(
|
||||
(res: GenRes) => {
|
||||
@@ -39,12 +38,8 @@ const CodeGenerateBtn: FC<Props> = ({
|
||||
|
||||
return (
|
||||
<div className={cn(className)}>
|
||||
<ActionButton
|
||||
aria-label={t(($) => $['operation.automatic'], { ns: 'appDebug' })}
|
||||
className="hover:bg-[#155EFF]/8"
|
||||
onClick={() => setShowAutomatic(true)}
|
||||
>
|
||||
<span aria-hidden className="i-custom-vender-other-generator size-4 text-primary-600" />
|
||||
<ActionButton className="hover:bg-[#155EFF]/8" onClick={() => setShowAutomatic(true)}>
|
||||
<Generator className="size-4 text-primary-600" />
|
||||
</ActionButton>
|
||||
{showAutomatic && (
|
||||
<GetCodeGeneratorResModal
|
||||
|
||||
Reference in New Issue
Block a user