Skip to content

Commit

Permalink
Merge branch 'develop' into fix/fixed-add-patient-page-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoonchild authored Jun 7, 2024
2 parents 3e1aa7e + 90b97d9 commit 70e4b62
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 102 deletions.
1 change: 0 additions & 1 deletion sanitas_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"axios": "^1.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.1",
"zustand": "^4.5.2"
},
Expand Down
4 changes: 3 additions & 1 deletion sanitas_frontend/src/components/Input/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import React from "react";
* @param {string} [props.placeholder] - A placeholder text shown in the input.
* @returns {React.Element} The React Input element.
*/
export default function BaseInput({ type, value, onChange, placeholder }) {
function BaseInput({ type, value, onChange, placeholder }) {
return <input type={type} value={value} onChange={onChange} placeholder={placeholder} />;
}

export default BaseInput;
4 changes: 3 additions & 1 deletion sanitas_frontend/src/components/Input/date.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import React from "react";
* @param {string} [props.placeholder] - A placeholder text shown in the date input.
* @returns {React.Element} The React Date Input element.
*/
export default function DateInput({ value, onChange, placeholder }) {
function DateInput({ value, onChange, placeholder }) {
return <input type="date" value={value} onChange={onChange} placeholder={placeholder} />;
}

export default DateInput;
3 changes: 1 addition & 2 deletions sanitas_frontend/src/components/Input/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BaseInput from "./base.jsx";
import DateInput from "./date.jsx";
import RadioInput from "./radio.jsx";
import SearchInput from "./search.jsx";

export { BaseInput, DateInput, RadioInput, SearchInput };
export { BaseInput, DateInput, RadioInput };
4 changes: 3 additions & 1 deletion sanitas_frontend/src/components/Input/radio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import React from "react";
* @param {string} props.label - The label text displayed next to the radio button.
* @returns {React.Element} A labeled radio button element.
*/
export default function RadioInput({ name, checked, onChange, label }) {
function RadioInput({ name, checked, onChange, label }) {
return (
<label>
<input type="radio" name={name} checked={checked} onChange={onChange} />
{label}
</label>
);
}

export default RadioInput;
50 changes: 0 additions & 50 deletions sanitas_frontend/src/components/Input/search.jsx

This file was deleted.

39 changes: 8 additions & 31 deletions sanitas_frontend/src/views/SearchPatientView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function SearchPatientView({ searchPatientsApiCall, useStore }) {

const [queryReturnedEmpty, setQueryReturnedEmpty] = useState(false);
const [error, setError] = useState("");
const [searchTypeWasCUI, setSearchTypeWasCUI] = useState(false);
const navigate = useNavigate();

const showErrorMessage = (message) => setError(`ERROR: ${message}`);
Expand All @@ -39,23 +38,8 @@ export default function SearchPatientView({ searchPatientsApiCall, useStore }) {
{ value: "Carnet", label: "Carnet Estudiante" },
{ value: "NumeroColaborador", label: "Código Colaborador" },
{ value: "Nombres", label: "Nombres y Apellidos" },
{ value: "CUI", label: "CUI" },
];

const handleInputChange = (e) => {
let value = e.target.value;
if (type === "Nombres") {
value = value.replace(/\d/g, "");
} else if (type != "Nombres") {
value = value.replace(/\D/g, "");
}

if (type === "CUI") {
value = value.slice(0, 13);
}
setSearchQuery(value, type);
};

const searchBtnClick = async () => {
hideErrorMessage();
if (emptyQuery) {
Expand All @@ -64,7 +48,6 @@ export default function SearchPatientView({ searchPatientsApiCall, useStore }) {
}

const result = await searchPatientsApiCall(query, type);
setSearchTypeWasCUI(type === "CUI");
if (result.error) {
const { error } = result;
if (error.cause) {
Expand Down Expand Up @@ -113,26 +96,20 @@ export default function SearchPatientView({ searchPatientsApiCall, useStore }) {
<BaseInput
type="text"
value={query}
onChange={handleInputChange}
onChange={(e) => setSearchQuery(e.target.value, type)}
placeholder="Ingrese su búsqueda..."
/>
<Button text="Buscar" onClick={searchBtnClick} disabled={emptyQuery} />
</div>
<p style={{ color: "red" }}>{error}</p>
{queryReturnedEmpty
&& (!searchTypeWasCUI
? (
<div>
<p>¡Parece que el paciente no existe!</p>
<p>Prueba buscarlo por CUI.</p>
</div>
)
: (
<div>
<p>Ingresa la información del paciente aquí.</p>
<Button text="Puedes añadir uno nuevo aquí." onClick={onAddNewPatientClick} />
</div>
))}
? (
<div>
<p>Parece que el paciente no existe!</p>
<Button text="Puedes añadir uno nuevo aquí" onClick={onAddNewPatientClick} />
</div>
)
: null}
<div>
{...patients.map((p) => (
<div key={p.id}>
Expand Down
24 changes: 9 additions & 15 deletions sanitas_frontend/src/views/SearchPatientView/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Search Patient view ui tests", () => {
expect(apiCall).toHaveBeenCalledTimes(0);
});

test("On search calls function", async () => {
test("On search calls function", () => {
const apiCall = vi.fn(() => ({
result: [],
}));
Expand All @@ -36,13 +36,10 @@ describe("Search Patient view ui tests", () => {
const searchElem = dom.getByPlaceholderText("Ingrese su búsqueda...");
const searchBtn = dom.getByText("Buscar");

fireEvent.change(searchElem, { target: { value: "3284834428" } });
fireEvent.change(searchElem, { target: { value: "asdflkjlk" } });
fireEvent.click(searchBtn);

// Use waitFor to ensure the async call has time to complete
await waitFor(() => {
expect(apiCall).toHaveBeenCalledOnce();
});
expect(apiCall).toHaveBeenCalledOnce();
});

test("Display a button to see patient", async () => {
Expand All @@ -65,19 +62,16 @@ describe("Search Patient view ui tests", () => {
const searchElem = dom.getByPlaceholderText("Ingrese su búsqueda...");
const searchBtn = dom.getByText("Buscar");

fireEvent.change(searchElem, { target: { value: "2348234890" } });
fireEvent.change(searchElem, { target: { value: "asdflkj" } });
fireEvent.click(searchBtn);

expect(apiCall).toHaveBeenCalledOnce();

// The function below throws if 0 or 2+ elements are found.
await waitFor(
() => {
expect(dom.getByText("Ver")).toBeVisible();
},
{
timeout: 500,
},
);
await waitFor(() => {
expect(dom.getByText("Ver")).toBeVisible();
}, {
timeout: 500,
});
});
});

0 comments on commit 70e4b62

Please sign in to comment.