Fakultas Ilmu Komputer UI

Commit f85bb8cf authored by Wan Muhammad Rayhan Arwindra's avatar Wan Muhammad Rayhan Arwindra 🤸🏽
Browse files

Merge branch 'pbi-8' into 'staging'

Pbi 8

See merge request !95
parents 5a836b9b 63d54494
Pipeline #61059 passed with stages
in 11 minutes and 14 seconds
......@@ -21,6 +21,7 @@ test("Test edit produk renders", async () => {
subcategory_name: "Baju Tidur hehe",
description: "celana",
price: "50000.00",
modal: "10000.00",
stock: 17,
image: null,
pre_order: false,
......@@ -113,6 +114,7 @@ test("Test edit produk renders error", async () => {
subcategory_name: "Baju Tidur hehe",
description: "celana",
price: "50000.00",
modal:"10000.00",
stock: 17,
image: null,
pre_order: false,
......
......@@ -28,6 +28,7 @@ test(" Test List produk", async () => {
price: "50000.00",
stock: 9,
image: null,
profit: "100000.00"
},
{
id: "9a0bccaa-70f6-48a8-89fc-5c5994684729",
......@@ -41,6 +42,7 @@ test(" Test List produk", async () => {
price: "50000.00",
stock: 14,
image: null,
profit: "100000.00"
},
],
})
......@@ -53,5 +55,6 @@ test(" Test List produk", async () => {
await waitFor(() => getByTestId("tableList"));
const data = getByTestId("tableList");
expect(data.textContent).toContain("Piyama");
expect(data.textContent).toContain("Rp100.000");
expect(fetch.mock.calls.length).toEqual(1);
});
......@@ -80,6 +80,10 @@ test("Test tambah produk renders", async () => {
await act(async () => {
await fireEvent.input(price_produk, { target: { value: "1" } });
});
const modal_produk = getByTestId("modal-produk-input");
await act(async () => {
await fireEvent.input(modal_produk, {target: { value: "1" } });
});
const stock_produk = getByTestId("stock-produk-input");
await act(async () => {
await fireEvent.input(stock_produk, { target: { value: "1" } });
......@@ -237,6 +241,10 @@ test("Test tambah produk error", async () => {
await act(async () => {
await fireEvent.input(price_produk, { target: { value: "1" } });
});
const modal_produk = getByTestId("modal-produk-input");
await act(async () => {
await fireEvent.input(modal_produk, {target: { value: "1" } });
});
const stock_produk = getByTestId("stock-produk-input");
await act(async () => {
await fireEvent.input(stock_produk, { target: { value: "1" } });
......@@ -255,3 +263,92 @@ test("Test tambah produk error", async () => {
);
expect(fetch.mock.calls.length).toEqual(4);
});
test("Test modal produk required", async () => {
fetch
.once(
JSON.stringify({
count: 4,
next: null,
previous: null,
results: [
{
id: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
name: "Baju",
image: null,
},
{
id: "0664247c-d9ea-4e56-bb02-4b8463f9e14c",
name: "Mainan",
image: null,
},
{
id: "8c2c06e6-0ead-4b9a-8de1-37237fc6bdc9",
name: "Makanan",
image: null,
},
{
id: "b8a9909b-9131-4c2b-bcc5-6bceb18f702c",
name: "Minuman",
image: null,
},
],
})
)
.once(
JSON.stringify({
count: 7,
next: null,
previous: null,
results: [
{
id: "626aa022-50a7-4d3a-b658-79cb0f059b03",
name: "Baju Tidur hehe",
category: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
category_name: "Baju",
image: null,
},
{
id: "ab222bb8-46e4-40bb-bd47-7f546d356de1",
name: "joker baru",
category: "f0c08b4f-7421-4298-89e4-3d4a40ef15b4",
category_name: "Baju",
image: null,
},
],
})
)
.once(JSON.stringify({}), { statusCode: 200 });
const { getByTestId, getByLabelText } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<TambahProduk />
</AuthContext.Provider>
);
const name_produk = getByTestId("name-produk-input");
await act(async () => {
await fireEvent.input(name_produk, { target: { value: "test" } });
});
const desc_produk = getByTestId("desc-produk-input");
await act(async () => {
await fireEvent.input(desc_produk, { target: { value: "test" } });
});
const price_produk = getByTestId("price-produk-input");
await act(async () => {
await fireEvent.input(price_produk, { target: { value: "1" } });
});
const stock_produk = getByTestId("stock-produk-input");
await act(async () => {
await fireEvent.input(stock_produk, { target: { value: "1" } });
});
await act(async () => {
await fireEvent.click(getByLabelText("Biasa"), {
target: { value: "false" },
});
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-produk"));
});
const formCategory = getByTestId("form-produk");
expect(formCategory.textContent).toContain("Modal tidak boleh kosong");
expect(fetch.mock.calls.length).toEqual(3);
});
\ No newline at end of file
......@@ -24,6 +24,7 @@ const FormProduk = ({ onSubmit, initialData = null }) => {
price: initialData["price"],
stock: initialData["stock"],
pre_order: initialData["pre_order"].toString(),
modal: initialData["modal"],
}
: {},
});
......@@ -59,6 +60,7 @@ const FormProduk = ({ onSubmit, initialData = null }) => {
formData.append("description", data["description"]);
formData.append("price", data["price"]);
formData.append("pre_order", data["pre_order"]);
formData.append("modal", data["modal"]);
if (data["image"].length !== 0) formData.append("image", data["image"][0]);
onSubmit(formData);
};
......@@ -180,6 +182,16 @@ const FormProduk = ({ onSubmit, initialData = null }) => {
<ErrorDiv>Tipe Produk tidak boleh kosong</ErrorDiv>
)}
</RowInput>
<RowInput>
<LabelInput htmlFor="modal">Modal/kuantitas </LabelInput>
<InputForm
data-testid="modal-produk-input"
type="number"
name="modal"
ref={register({ required: true })}
/>
{errors.modal && <ErrorDiv>Modal tidak boleh kosong</ErrorDiv>}
</RowInput>
<RowInput>
<LabelInput htmlFor="harga">Harga/kuantitas </LabelInput>
<InputForm
......
......@@ -14,6 +14,8 @@ const ListProduk = () => {
["id", "id"],
["name", "Nama Produk"],
["price", "Harga", stringToCurrency],
["profit", "Keuntungan/Produk", stringToCurrency],
["total_profit", "Keuntungan Total", stringToCurrency],
["", "Stok", preorderStock],
],
link: "",
......
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