CEC-231 Bulk car selection control (#38)
* Bulk car selection control * Tweak control alignment
This commit is contained in:
@@ -226,6 +226,6 @@ const validateCreateCarUpdates = (data) => {
|
||||
}
|
||||
|
||||
if (!data.vins || data.vins.length === 0) {
|
||||
throw new Error("Car ids required");
|
||||
throw new Error("Cars are required");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -273,7 +273,7 @@ describe("UpdatesContext", () => {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId("busy").innerHTML).toBe("false")
|
||||
);
|
||||
checkState("false", "Car ids required", null);
|
||||
checkState("false", "Cars are required", null);
|
||||
});
|
||||
|
||||
it("with-good-data", async () => {
|
||||
|
||||
@@ -29,6 +29,8 @@ export const VehicleProvider = ({ children }) => {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [vehicles, setVehicles] = useState([]);
|
||||
const [totalVehicles, setTotalVehicles] = useState(0);
|
||||
const [models, setModels] = useState([]);
|
||||
const [years, setYears] = useState([]);
|
||||
|
||||
const getVehicles = async (search, token) => {
|
||||
try {
|
||||
@@ -60,14 +62,40 @@ export const VehicleProvider = ({ children }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getModels = async (token) => {
|
||||
try {
|
||||
setBusy(true);
|
||||
const result = await api.getModels(token);
|
||||
if (result.error) throw new Error(`Get models error. ${result.message}`);
|
||||
setModels(result.data);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getYears = async (token) => {
|
||||
try {
|
||||
setBusy(true);
|
||||
const result = await api.getYears(token);
|
||||
if (result.error) throw new Error(`Get years error. ${result.message}`);
|
||||
setYears(result.data);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<VehicleContext.Provider
|
||||
value={{
|
||||
busy,
|
||||
vehicles,
|
||||
totalVehicles,
|
||||
models,
|
||||
years,
|
||||
getVehicles,
|
||||
addVehicle,
|
||||
getModels,
|
||||
getYears,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -2,6 +2,8 @@ import React from "react";
|
||||
|
||||
let busy = false;
|
||||
let vehicles = [];
|
||||
let models = ["Ocean", "PEAR"];
|
||||
let years = [2023, 2024];
|
||||
let totalVehicles = 0;
|
||||
let error = null;
|
||||
|
||||
@@ -13,8 +15,16 @@ export const useVehicleContext = () => ({
|
||||
busy,
|
||||
vehicles,
|
||||
totalVehicles,
|
||||
models,
|
||||
years,
|
||||
getVehicles: jest.fn(() => vehicles),
|
||||
addVehicle: jest.fn(),
|
||||
getModels: jest.fn(() => {
|
||||
models = ["Ocean", "PEAR"];
|
||||
}),
|
||||
getYears: jest.fn(() => {
|
||||
years = [2023, 2024];
|
||||
}),
|
||||
});
|
||||
|
||||
export const setBusy = (val) => {
|
||||
|
||||
Reference in New Issue
Block a user