2021-05-04 18:19:30 +03:00

78 lines
2.2 KiB
JavaScript

import React from "react";
import {render, unmountComponentAtNode} from "react-dom";
import {act} from "react-dom/test-utils";
import {TableBody} from "./src/control";
import * as test_data from "./test_users.json"
import axios from "axios";
import MockAdapter from 'axios-mock-adapter'
let container = null;
let table = null;
let load = null;
let engineer_count = null
let agents_count = null
let licences_remaining = null
beforeEach(() => {
table = document.createElement("table");
container = document.createElement("tbody");
container.id = "tbody";
table.appendChild(container);
load = document.createElement("p");
load.id = "loading"
load.innerHTML = "Данные загружаются";
licences_remaining = document.createElement('p')
licences_remaining.id = "licences_remaining"
engineer_count = document.createElement("p")
agents_count = document.createElement("p")
engineer_count.className = "info-quantity-value"
agents_count.className = "info-quantity-value"
document.body.appendChild(table);
document.body.appendChild(engineer_count)
document.body.appendChild(agents_count)
document.body.appendChild(licences_remaining)
document.body.appendChild(load);
jest.useFakeTimers();
});
afterEach(() => {
unmountComponentAtNode(container);
container.remove();
table.remove();
load.remove();
engineer_count.remove()
agents_count.remove()
licences_remaining.remove()
container = null;
table = null;
load = null;
engineer_count = null
agents_count = null
licences_remaining = null
jest.useRealTimers();
});
it("has rows no on mount", () => {
act(() => {
let container = document.createElement("tbody");
render(<TableBody/>, container);
});
expect(container.getElementsByTagName("tr").length).toBe(0);
});
it("has valid number of workplaces",async () => {
let mock = new MockAdapter(axios)
mock.onGet("/api/users").reply(200, test_data)
await act(async () => {
render(<TableBody/>, container)
})
let licences = Number(licences_remaining.textContent.replace(/Свободных мест: /, ''))
expect(licences).toEqual(1)
mock.restore()
})
it ("Pretext must be deleted on render", async () => {
})