Added more tests
This commit is contained in:
parent
716af21f48
commit
2f15d74a56
@ -6,7 +6,7 @@ import * as test_data from "./test_users.json"
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import MockAdapter from "axios-mock-adapter";
|
import MockAdapter from "axios-mock-adapter";
|
||||||
|
|
||||||
let mock;
|
let mock = null
|
||||||
let container = null
|
let container = null
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mock = new MockAdapter(axios);
|
mock = new MockAdapter(axios);
|
||||||
@ -23,7 +23,7 @@ afterEach(() => {
|
|||||||
container = null;
|
container = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has only main table row without axios request", () => {
|
it("has no rows without axios request", () => {
|
||||||
act(() => {
|
act(() => {
|
||||||
render(<Table/>, container);
|
render(<Table/>, container);
|
||||||
});
|
});
|
||||||
@ -67,12 +67,14 @@ it("show valid number for engineers and light agents", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("called one request on mount", async () => {
|
it("called one request on mount", async () => {
|
||||||
let req = jest.spyOn(Table.prototype, "get_users")
|
let requests = jest.spyOn(Table.prototype, "getUsers")
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
render(<Table/>, container)
|
render(<Table/>, container)
|
||||||
})
|
})
|
||||||
expect(req).toHaveBeenCalledTimes(1)
|
expect(requests).toHaveBeenCalledTimes(1)
|
||||||
|
requests.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("checkbox count equals users from db count", async () => {
|
it("checkbox count equals users from db count", async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
render(<Table/>, container)
|
render(<Table/>, container)
|
||||||
@ -82,3 +84,15 @@ it("checkbox count equals users from db count", async () => {
|
|||||||
let users = test_data.users
|
let users = test_data.users
|
||||||
expect(checkboxes.length).toEqual(users.length)
|
expect(checkboxes.length).toEqual(users.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("requests occur every one minute", async () => {
|
||||||
|
jest.useFakeTimers()
|
||||||
|
let requests = jest.spyOn(Table.prototype, "getUsers")
|
||||||
|
await act(async () => {
|
||||||
|
render(<Table/>, container)
|
||||||
|
})
|
||||||
|
jest.advanceTimersByTime(60000)
|
||||||
|
expect(requests).toHaveBeenCalledTimes(2)
|
||||||
|
jest.useRealTimers()
|
||||||
|
requests.mockRestore()
|
||||||
|
})
|
||||||
|
@ -120,7 +120,7 @@ export class Table extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async get_users() {
|
async getUsers() {
|
||||||
await axios.get("/api/users").then((response) => {
|
await axios.get("/api/users").then((response) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
users: response.data.users,
|
users: response.data.users,
|
||||||
@ -137,12 +137,12 @@ export class Table extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.get_users().then(() => {})
|
this.getUsers().then(() => {})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.log(reason)
|
console.log(reason)
|
||||||
});
|
});
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
this.get_users().catch(reason => {
|
this.getUsers().catch(reason => {
|
||||||
console.log(reason)
|
console.log(reason)
|
||||||
})
|
})
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user