feat(web): show created and removed counts after zone import

This commit is contained in:
2026-08-19 18:37:56 +07:00
parent 4d05271f10
commit d6d91f8826
4 changed files with 26 additions and 3 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import { API_ROOT } from "@/lib/config"
import type {
AuthState,
Account, CreateAccountInput, Template, CreateTemplateInput,
Domain, CreateDomainInput, ChangesetResponse, ApplyRequest,
Domain, CreateDomainInput, ImportResult, ChangesetResponse, ApplyRequest,
Schedule, Channel, CreateChannelInput, CheckRun, RecordDTO,
} from "./types"
@@ -70,7 +70,7 @@ export const api = {
deleteDomain: (projectId: string, id: string) =>
req<void>(projectPath(projectId, `/domains/${id}`), { method: "DELETE" }),
importZones: (projectId: string, accountId: string) =>
req<Domain[]>(projectPath(projectId, `/accounts/${accountId}/import`), { method: "POST" }),
req<ImportResult>(projectPath(projectId, `/accounts/${accountId}/import`), { method: "POST" }),
setDomainTemplate: (projectId: string, id: string, templateId: string | null) =>
req<Domain>(projectPath(projectId, `/domains/${id}`), { method: "PATCH", body: JSON.stringify({ templateId }) }),
+1
View File
@@ -29,6 +29,7 @@ export interface CreateDomainInput {
zoneId: string
templateId?: string | null
}
export interface ImportResult { created: Domain[]; removed: Domain[] }
export interface Schedule { intervalSeconds: number; enabled: boolean }
+18 -1
View File
@@ -62,7 +62,7 @@ test("отрисовывает домены и ссылку на diff-стран
})
test("кнопка импорта вызывает api.importZones с выбранной учёткой", async () => {
const importSpy = vi.spyOn(api, "importZones").mockResolvedValue([])
const importSpy = vi.spyOn(api, "importZones").mockResolvedValue({ created: [], removed: [] })
const user = userEvent.setup()
renderPage()
@@ -76,6 +76,23 @@ test("кнопка импорта вызывает api.importZones с выбра
await waitFor(() => expect(importSpy).toHaveBeenCalledWith(PROJECT_ID, "acc2"))
})
test("после импорта показывает, сколько зон создано и сколько удалено", async () => {
vi.spyOn(api, "importZones").mockResolvedValue({
created: [
{ id: "d1", providerAccountId: "a1", zoneName: "new.example.com.", zoneId: "z1" },
],
removed: [
{ id: "d2", providerAccountId: "a1", zoneName: "gone.example.com.", zoneId: "z9" },
],
})
const user = userEvent.setup()
renderPage()
await user.click(await screen.findByRole("button", { name: /импортировать зоны/i }))
expect(await screen.findByText(/создано 1, удалено 1/i)).toBeInTheDocument()
})
test("привязка шаблона в строке домена вызывает api.setDomainTemplate", async () => {
const setTemplateSpy = vi.spyOn(api, "setDomainTemplate").mockResolvedValue(domains[0])
const user = userEvent.setup()
+5
View File
@@ -102,6 +102,11 @@ export function DomainsPage() {
{importZones.isError && (
<span className="font-dns text-xs text-destructive">{importZones.error.message}</span>
)}
{importZones.isSuccess && (
<span className="font-dns text-xs text-muted-foreground">
Создано {importZones.data.created.length}, удалено {importZones.data.removed.length}
</span>
)}
</div>
{setTemplate.isError && (