Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
IT Project 2020
Group B
pilar-web
Commits
63d54494
Commit
63d54494
authored
Nov 22, 2020
by
Wan Muhammad Rayhan Arwindra
🤸🏽
Browse files
Pbi 8
parent
5a836b9b
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/__test__/produk/EditProduk.test.js
View file @
63d54494
...
...
@@ -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
,
...
...
src/__test__/produk/ListProduk.test.js
View file @
63d54494
...
...
@@ -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
);
});
src/__test__/produk/TambahProduk.test.js
View file @
63d54494
...
...
@@ -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
src/page/produk/FormProduk.jsx
View file @
63d54494
...
...
@@ -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
...
...
src/page/produk/ListProduk.jsx
View file @
63d54494
...
...
@@ -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
:
""
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment