Fakultas Ilmu Komputer UI

Commit 906f6f40 authored by Bunga Amalia Kurniawati's avatar Bunga Amalia Kurniawati 🌺 Committed by Azhar Difa Arnanda
Browse files

PBI-9: Menambahkan kolom kode bank

parent 22155dce
This diff is collapsed.
......@@ -15,6 +15,7 @@ test("Test edit bank renders", async () => {
JSON.stringify({
id: "e1827709-82a3-4a6f-b55c-bb1a229b7036",
bank_name: "bca",
bank_code_number: "222",
bank_account_number: "1234456",
bank_account_name: "test bca",
})
......@@ -31,6 +32,8 @@ test("Test edit bank renders", async () => {
await waitFor(() => getByTestId("edit-bank"));
const name_bank = getByTestId("name-bank-input");
expect(name_bank.value).toEqual("bca");
const code_bank = getByTestId("code-number-input");
expect(code_bank.value).toEqual("222");
expect(fetch.mock.calls.length).toEqual(1);
await act(async () => {
await fireEvent.input(name_bank, { target: { value: "test" } });
......@@ -47,6 +50,7 @@ test("Test edit bank error", async () => {
JSON.stringify({
id: "e1827709-82a3-4a6f-b55c-bb1a229b7036",
bank_name: "bca",
bank_code_number: "222",
bank_account_number: "1234456",
bank_account_name: "test bca",
})
......@@ -63,6 +67,8 @@ test("Test edit bank error", async () => {
await waitFor(() => getByTestId("edit-bank"));
const name_bank = getByTestId("name-bank-input");
expect(name_bank.value).toEqual("bca");
const code_bank = getByTestId("code-number-input");
expect(code_bank.value).toEqual("222");
expect(fetch.mock.calls.length).toEqual(1);
await act(async () => {
await fireEvent.input(name_bank, { target: { value: "test" } });
......@@ -96,5 +102,5 @@ test("Test edit bank required marks", async () => {
expect(waitBank.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("edit-bank"));
const formBank = getByTestId("form-bank");
expect(formBank.textContent).toContain("* Perlu diisi", "Nama bank*", "Nomor rekening*", "Nama pemilik rekening*");
expect(formBank.textContent).toContain("* Perlu diisi", "Nama bank*", "Nomor kode bank*", "Nomor rekening*", "Nama pemilik rekening*");
});
\ No newline at end of file
......@@ -20,12 +20,14 @@ test("Test List Bank", async () => {
{
id: "e1827709-82a3-4a6f-b55c-bb1a229b7036",
bank_name: "bca",
bank_code_number: "222",
bank_account_number: "1234456",
bank_account_name: "test bca",
},
{
id: "3e7974da-47fb-47ed-a83c-525e237a8c41",
bank_name: "bca1",
bank_code_number: "333",
bank_account_number: "1234456",
bank_account_name: "test bca",
},
......@@ -40,5 +42,8 @@ test("Test List Bank", async () => {
await waitFor(() => getByTestId("tableList"));
const data = getByTestId("tableList");
expect(data.textContent).toContain("bca");
expect(data.textContent).toContain("222");
expect(data.textContent).toContain("bca1");
expect(data.textContent).toContain("333");
expect(fetch.mock.calls.length).toEqual(1);
});
......@@ -15,9 +15,13 @@ test("Test tambah bank renders", async () => {
</AuthContext.Provider>
);
const name_bank = getByTestId("name-bank-input");
const code_bank = getByTestId("code-number-input");
await act(async () => {
await fireEvent.input(name_bank, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.input(code_bank, { target: { value: "222" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-bank"));
});
......@@ -31,5 +35,5 @@ test("Test tambah bank required marks", async () => {
</AuthContext.Provider>
);
const formBank = getByTestId("tambah-bank");
expect(formBank.textContent).toContain("* Perlu diisi", "Nama bank*", "Nomor rekening*", "Nama pemilik rekening*");
expect(formBank.textContent).toContain("* Perlu diisi", "Nama bank*", "Nomor kode bank*", "Nomor rekening*", "Nama pemilik rekening*");
});
\ No newline at end of file
......@@ -26,6 +26,7 @@ const EditBank = ({ idBank }) => {
const onSubmit = (data) => {
const formData = new FormData();
formData.append("bank_name", data["bank_name"]);
formData.append("bank_code_number", data["bank_code_number"]);
formData.append("bank_account_number", data["bank_account_number"]);
formData.append("bank_account_name", data["bank_account_name"]);
send(formData);
......
import React from "react";
import { useForm } from "react-hook-form";
import {
ErrorDiv,
RowInput,
InputForm,
LabelInput,
InputSubmitForm,
} from "../../component/html/html";
import { css } from "@emotion/core";
const FormBank = ({ onSubmit, initialData = null }) => {
const { register, handleSubmit, errors } = useForm({
defaultValues:
initialData !== null
? {
bank_name: initialData["bank_name"],
bank_account_number: initialData["bank_account_number"],
bank_account_name: initialData["bank_account_name"],
}
: {},
});
return (
<form
data-testid="form-bank"
onSubmit={handleSubmit(onSubmit)}
css={css`
display: flex;
flex-direction: column;
`}
>
<div
css={css`
font-size: 15px;
color:red;
`}>
* Perlu diisi
</div>
<RowInput>
<LabelInput htmlFor="bank_name">Nama bank
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="name-bank-input"
name="bank_name"
ref={register({ required: true })}
/>
{errors.bank_name && <ErrorDiv>Nama bank tidak boleh kosong</ErrorDiv>}
</RowInput>
<RowInput>
<LabelInput htmlFor="account_number">Nomor rekening
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="account-number-input"
name="bank_account_number"
ref={register({ required: true })}
/>
{errors.bank_account_number && (
<ErrorDiv>Nomor rekening tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<LabelInput htmlFor="account_name">Nama pemilik rekening
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="account-name-input"
name="bank_account_name"
ref={register({ required: true })}
/>
{errors.bank_account_name && (
<ErrorDiv>Nama pemilik rekening tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<InputSubmitForm
type="submit"
data-testid="submit-bank"
value="SUBMIT"
css={css`
height: 100%;
`}
/>
</RowInput>
</form>
);
};
export default FormBank;
import React from "react";
import { useForm } from "react-hook-form";
import {
ErrorDiv,
RowInput,
InputForm,
LabelInput,
InputSubmitForm,
} from "../../component/html/html";
import { css } from "@emotion/core";
const FormBank = ({ onSubmit, initialData = null }) => {
const { register, handleSubmit, errors } = useForm({
defaultValues:
initialData !== null
? {
bank_name: initialData["bank_name"],
bank_code_number: initialData["bank_code_number"],
bank_account_number: initialData["bank_account_number"],
bank_account_name: initialData["bank_account_name"],
}
: {},
});
return (
<form
data-testid="form-bank"
onSubmit={handleSubmit(onSubmit)}
css={css`
display: flex;
flex-direction: column;
`}
>
<div
css={css`
font-size: 15px;
color:red;
`}>
* Perlu diisi
</div>
<RowInput>
<LabelInput htmlFor="bank_name">Nama bank
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="name-bank-input"
name="bank_name"
ref={register({ required: true })}
/>
{errors.bank_name && <ErrorDiv>Nama bank tidak boleh kosong</ErrorDiv>}
</RowInput>
<RowInput>
<LabelInput htmlFor="code_number">Nomor kode bank
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="code-number-input"
name="bank_code_number"
ref={register({ required: true })}
/>
{errors.bank_code_number && (
<ErrorDiv>Nomor kode bank tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<LabelInput htmlFor="account_number">Nomor rekening
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="account-number-input"
name="bank_account_number"
ref={register({ required: true })}
/>
{errors.bank_account_number && (
<ErrorDiv>Nomor rekening tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<LabelInput htmlFor="account_name">Nama pemilik rekening
<span css={css`color:red`}>*</span></LabelInput>
<InputForm
data-testid="account-name-input"
name="bank_account_name"
ref={register({ required: true })}
/>
{errors.bank_account_name && (
<ErrorDiv>Nama pemilik rekening tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<InputSubmitForm
type="submit"
data-testid="submit-bank"
value="SUBMIT"
css={css`
height: 100%;
`}
/>
</RowInput>
</form>
);
};
export default FormBank;
......@@ -11,6 +11,7 @@ const ListBank = () => {
keyValuePairs: [
["id", "id"],
["bank_name", "Nama Bank"],
["bank_code_number", "Nomor Kode Bank"],
["bank_account_number", "Nomor Rekening"],
["bank_account_name", "Nama Pemilik Rekening"],
],
......
......@@ -15,12 +15,9 @@ const TambahBank = () => {
const onSubmit = (data) => {
const formData = new FormData();
formData.append("bank_name", data["bank_name"]);
formData.append("bank_code_number", data["bank_code_number"]);
formData.append("bank_account_number", data["bank_account_number"]);
formData.append("bank_account_name", data["bank_account_name"]);
console.log(data);
for (let pair in formData.entries()){
console.log(pair[0] + ' ' + pair[1]);
}
send(formData);
};
return (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment