|
| 1 | +import { randomUUID } from "crypto"; |
| 2 | +import { render, waitFor } from "@testing-library/react"; |
| 3 | +import * as React from "react"; |
| 4 | + |
| 5 | +import { Kind } from "../../lib/api/core/types.pb"; |
| 6 | +import { Provider } from "../../lib/objects"; |
| 7 | +import { |
| 8 | + createCoreMockClient, |
| 9 | + withContext, |
| 10 | + withTheme, |
| 11 | +} from "../../lib/test-utils"; |
| 12 | +import ProviderDetail from "../ProviderDetail"; |
| 13 | + |
| 14 | +describe("ProviderDetail", () => { |
| 15 | + beforeEach(() => { |
| 16 | + jest.spyOn(console, "error").mockImplementation(); |
| 17 | + }); |
| 18 | + |
| 19 | + const responseObject = { |
| 20 | + payload: |
| 21 | + '{"apiVersion":"notification.toolkit.fluxcd.io/v1beta2","kind":"Provider","metadata":{"creationTimestamp":"2025-02-14T16:27:55Z","generation":1,"labels":{"kustomize.toolkit.fluxcd.io/name":"flux-system","kustomize.toolkit.fluxcd.io/namespace":"flux-system"},"managedFields":[{"apiVersion":"notification.toolkit.fluxcd.io/v1beta3","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{"f:kustomize.toolkit.fluxcd.io/name":{},"f:kustomize.toolkit.fluxcd.io/namespace":{}}},"f:spec":{"f:secretRef":{"f:name":{}},"f:type":{}}},"manager":"kustomize-controller","operation":"Apply","time":"2025-02-14T17:19:51Z"}],"name":"discord-bot","namespace":"flux-system","resourceVersion":"189450782","uid":"6ef27ec3-4e7c-45b9-906f-4777de2c0c0f"},"spec":{"secretRef":{"name":"discord-webhook"},"type":"discord"}}\n', |
| 22 | + clusterName: "Default", |
| 23 | + tenant: "", |
| 24 | + uid: randomUUID(), |
| 25 | + inventory: [], |
| 26 | + info: "", |
| 27 | + health: null, |
| 28 | + }; |
| 29 | + |
| 30 | + const provider = new Provider(responseObject); |
| 31 | + |
| 32 | + const objects = [ |
| 33 | + { |
| 34 | + payload: |
| 35 | + '{"apiVersion":"notification.toolkit.fluxcd.io/v1beta2","kind":"Alert","metadata":{"creationTimestamp":"2025-02-14T16:27:55Z","generation":1,"labels":{"kustomize.toolkit.fluxcd.io/name":"flux-system","kustomize.toolkit.fluxcd.io/namespace":"flux-system"},"managedFields":[{"apiVersion":"notification.toolkit.fluxcd.io/v1beta3","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{"f:kustomize.toolkit.fluxcd.io/name":{},"f:kustomize.toolkit.fluxcd.io/namespace":{}}},"f:spec":{"f:eventMetadata":{"f:cluster":{},"f:env":{},"f:region":{}},"f:eventSeverity":{},"f:eventSources":{},"f:inclusionList":{},"f:providerRef":{"f:name":{}},"f:summary":{}}},"manager":"kustomize-controller","operation":"Apply","time":"2025-02-14T17:19:51Z"}],"name":"discord-error","namespace":"flux-system","resourceVersion":"189450780","uid":"7edf429a-5550-47d4-affc-f512fda2d057"},"spec":{"eventSeverity":"info","eventSources":[{"kind":"GitRepository","name":"*"},{"kind":"Kustomization","name":"*"}],"inclusionList":[".*failed.*"],"providerRef":{"name":"discord-bot"},"summary":"An error occurred during reconciliation"}}\n', |
| 36 | + clusterName: "Default", |
| 37 | + tenant: "", |
| 38 | + uid: randomUUID(), |
| 39 | + inventory: [], |
| 40 | + info: "", |
| 41 | + health: null, |
| 42 | + }, |
| 43 | + { |
| 44 | + payload: |
| 45 | + '{"apiVersion":"notification.toolkit.fluxcd.io/v1beta2","kind":"Alert","metadata":{"creationTimestamp":"2025-02-14T16:27:55Z","generation":1,"labels":{"kustomize.toolkit.fluxcd.io/name":"flux-system","kustomize.toolkit.fluxcd.io/namespace":"flux-system"},"managedFields":[{"apiVersion":"notification.toolkit.fluxcd.io/v1beta3","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{"f:kustomize.toolkit.fluxcd.io/name":{},"f:kustomize.toolkit.fluxcd.io/namespace":{}}},"f:spec":{"f:eventMetadata":{"f:cluster":{},"f:env":{},"f:region":{}},"f:eventSeverity":{},"f:eventSources":{},"f:inclusionList":{},"f:providerRef":{"f:name":{}},"f:summary":{}}},"manager":"kustomize-controller","operation":"Apply","time":"2025-02-14T17:19:51Z"}],"name":"discord-info","namespace":"flux-system","resourceVersion":"189450781","uid":"c82c6df2-ee90-4258-97f8-bd1a8861478c"},"spec":{"eventSeverity":"info","eventSources":[{"kind":"Kustomization","name":"*"}],"inclusionList":[".*passed.*"],"providerRef":{"name":"discord-bot"},"summary":"A reconciliation has been completed successfully"}}\n', |
| 46 | + clusterName: "Default", |
| 47 | + tenant: "", |
| 48 | + uid: randomUUID(), |
| 49 | + inventory: [], |
| 50 | + info: "", |
| 51 | + health: null, |
| 52 | + }, |
| 53 | + ]; |
| 54 | + |
| 55 | + it("renders", async () => { |
| 56 | + const client = createCoreMockClient({ |
| 57 | + ListObjects: ({ kind }) => { |
| 58 | + const fullResponse = { objects: [], errors: [] }; |
| 59 | + if (kind === Kind.Alert) fullResponse.objects = objects; |
| 60 | + return fullResponse; |
| 61 | + }, |
| 62 | + }); |
| 63 | + render( |
| 64 | + withTheme( |
| 65 | + withContext(<ProviderDetail provider={provider} />, "/alerts", { |
| 66 | + api: client, |
| 67 | + }), |
| 68 | + ), |
| 69 | + ); |
| 70 | + await waitFor(() => { |
| 71 | + const rows = document.querySelectorAll("tbody tr"); |
| 72 | + expect(rows.length).toEqual(objects.length); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments