Cypress Umgebung ok
This commit is contained in:
129
__tests__/components/modules/Kue705FO.test.tsx
Normal file
129
__tests__/components/modules/Kue705FO.test.tsx
Normal file
@@ -0,0 +1,129 @@
|
||||
import React from "react";
|
||||
import { render, fireEvent, screen } from "@testing-library/react";
|
||||
import configureStore from "redux-mock-store";
|
||||
import { Provider } from "react-redux";
|
||||
import "@testing-library/jest-dom";
|
||||
import Kue705FO from "../../../components/modules/Kue705FO";
|
||||
|
||||
// Mocks für externe Abhängigkeiten
|
||||
jest.mock("chart.js/auto", () => ({
|
||||
default: {
|
||||
register: jest.fn(),
|
||||
},
|
||||
Chart: jest.fn().mockImplementation(() => ({
|
||||
destroy: jest.fn(),
|
||||
update: jest.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
jest.mock("chartjs-plugin-zoom", () => ({}));
|
||||
|
||||
// Initialzustand für Redux
|
||||
const mockStore = configureStore([]);
|
||||
const initialState = {
|
||||
variables: {
|
||||
kuePSTmMinus96V: [0],
|
||||
kueCableBreak: [0],
|
||||
kueGroundFault: [0],
|
||||
kueAlarm1: [0],
|
||||
kueAlarm2: [0],
|
||||
kueOverflow: [0],
|
||||
kueVersion: [419],
|
||||
tdrActive: [1],
|
||||
},
|
||||
auth: {
|
||||
isAdminLoggedIn: true, // Füge dies hinzu
|
||||
},
|
||||
};
|
||||
|
||||
// Standard-Props
|
||||
const defaultProps = {
|
||||
isolationswert: 200,
|
||||
schleifenwiderstand: 5.6,
|
||||
modulName: "TestModul",
|
||||
kueOnline: 1,
|
||||
slotIndex: 0,
|
||||
tdrLocation: [2.5],
|
||||
};
|
||||
|
||||
describe("Kue705FO Integration Tests", () => {
|
||||
let store: ReturnType<typeof mockStore>;
|
||||
|
||||
beforeEach(() => {
|
||||
store = mockStore(initialState);
|
||||
});
|
||||
|
||||
it("should render correctly with default props", () => {
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Kue705FO {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
// Überprüfen, ob die Basis-Darstellung korrekt ist
|
||||
expect(screen.getByText("KÜ705-FO")).toBeInTheDocument();
|
||||
expect(screen.getByText("TestModul")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should toggle between TDR and Schleife modes", () => {
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Kue705FO {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
// Überprüfen, ob Schleife aktiv ist
|
||||
expect(screen.getByText("Schleifenwiderstand [kOhm]")).toBeInTheDocument();
|
||||
expect(screen.getByText("5.6 KOhm")).toBeInTheDocument();
|
||||
|
||||
// TDR-Button klicken
|
||||
fireEvent.click(screen.getByText("TDR"));
|
||||
|
||||
// Überprüfen, ob TDR aktiv ist
|
||||
expect(screen.getByText("Entfernung [Km]")).toBeInTheDocument();
|
||||
expect(screen.getByText("2.5 Km")).toBeInTheDocument();
|
||||
|
||||
// Zurück zu Schleife wechseln
|
||||
fireEvent.click(screen.getByText("Schleife"));
|
||||
expect(screen.getByText("Schleifenwiderstand [kOhm]")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should open and close the settings modal", () => {
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Kue705FO {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
// Modal öffnen
|
||||
fireEvent.click(screen.getByText("⚙"));
|
||||
expect(screen.getByText("KUE Einstellung - Slot 1")).toBeInTheDocument();
|
||||
|
||||
// Modal schließen
|
||||
fireEvent.click(screen.getByRole("button", { name: /x/i }));
|
||||
expect(
|
||||
screen.queryByText("KUE Einstellung - Slot 1")
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should disable TDR button when tdrActive is 0", () => {
|
||||
// Zustand aktualisieren
|
||||
store = mockStore({
|
||||
...initialState,
|
||||
variables: {
|
||||
...initialState.variables,
|
||||
tdrActive: [0],
|
||||
},
|
||||
});
|
||||
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Kue705FO {...defaultProps} />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
// TDR-Button sollte deaktiviert sein
|
||||
const tdrButton = screen.getByText("TDR");
|
||||
expect(tdrButton).toBeDisabled();
|
||||
});
|
||||
});
|
||||
7
__tests__/example.test.ts
Normal file
7
__tests__/example.test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// __tests__/example.test.ts
|
||||
describe('Basic Test', () => {
|
||||
it('should pass', () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user