Fakultas Ilmu Komputer UI

Commit 0a5a7921 authored by Tsamara Esperanti Erwin's avatar Tsamara Esperanti Erwin 🦄
Browse files

Merge branch 'PBI-6-Ray' into 'master'

Pbi 6 ray

See merge request !93
parents 980c3fbe 6314736f
Pipeline #60458 passed with stages
in 30 minutes and 13 seconds
image: node:12.16.3-buster-slim
image: node:12.18.4
stages:
- lint
- test
......
This diff is collapsed.
......@@ -3,7 +3,6 @@ import AuthReducer, { initialState } from "../store/reducers/auth_reducer";
import * as ACTIONS from "../store/actions/actions";
afterEach(cleanup);
test("auth reducer test", () => {
expect(AuthReducer(initialState(), {})).toEqual(initialState());
......
import { cleanup, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import DetailBatch from "../../page/batch/DetailBatch";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test detail loaded batch", async () => {
fetch.mockResponseOnce(
JSON.stringify({
id: "8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "Batch 1",
start_: "2020-04-28",
updated_at: "2020-04-28",
amount: "10000.00"
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailBatch batchId={"8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-batch");
expect(wait.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("page-detail-batch"));
const data = getByTestId("page-detail-batch");
expect(data.textContent).toContain("BATCH");
});
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import { waitFor } from "@testing-library/dom";
import React from "react";
import EditBatch from "../../page/batch/EditBatch";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test edit batch renders", async () => {
fetch
.once(
JSON.stringify({
id: "8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "a",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
})
)
.once(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "Batch 1",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
},
],
})
)
.once(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "Batch 1",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
},
],
})
)
.once(JSON.stringify({}), { statusCode: 200 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<EditBatch />
</AuthContext.Provider>
);
const waitBatch = getByTestId("waiting-edit-batch");
expect(waitBatch.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("edit-batch"));
const name_batch = getByTestId("name-batch-input");
expect(name_batch.value).toEqual("a");
await act(async () => {
await fireEvent.input(name_batch, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-batch"));
});
expect(fetch.mock.calls.length).toEqual(2);
});
test("Test edit batch renders error", async () => {
fetch
.once(
JSON.stringify({
id: "e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "a",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
})
)
.once(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "a",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
},
],
})
)
.once(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
batch_name: "a",
start_date: "2020-04-28",
end_date: "2020-04-28",
shipping_cost: "10000.00"
},
],
})
)
.once(JSON.stringify({}), { status: 400 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<EditBatch />
</AuthContext.Provider>
);
const waitProduk = getByTestId("waiting-edit-batch");
expect(waitProduk.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("edit-batch"));
const name_batch = getByTestId("name-batch-input");
expect(name_batch.value).toEqual("a");
await act(async () => {
await fireEvent.submit(getByTestId("submit-batch"));
});
expect(fetch.mock.calls.length).toEqual(2);
});
import { cleanup, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import ListBatch from "../../page/batch/ListBatch";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test(" Test List Batch", async () => {
fetch.mockResponseOnce(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
batch_name: "Batch 1",
start_date: "2020-10-08",
end_date_time:"2020-10-15",
shipping_cost: 69000
},
],
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListBatch />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
const datatotal = getByTestId("totalongkos");
expect(datatotal.textContent).toContain("Total Ongkos Kirim: Loading...")
const data = getByTestId("tableList");
expect(data.textContent).toContain("Batch 1");
expect(fetch.mock.calls.length).toEqual(2);
});
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import TambahBatch from "../../page/batch/TambahBatch";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test tambah batch renders", async () => {
fetch.once(JSON.stringify({}));
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<TambahBatch />
</AuthContext.Provider>
);
const name_batch = getByTestId("name-batch-input");
const start_date = getByTestId("start-date-input");
const end_date = getByTestId("end-date-input");
await act(async () => {
await fireEvent.input(name_batch, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.input(start_date, { target: { value: "2020-10-08" } });
});
await act(async () => {
await fireEvent.input(end_date, { target: { value: "2020-10-15" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-batch"));
});
expect(fetch.mock.calls.length).toEqual(1);
});
test("Test tambah batch form required", async () => {
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<TambahBatch />
</AuthContext.Provider>
);
await act(async () => {
await fireEvent.submit(getByTestId("submit-batch"));
});
const formBatch = getByTestId("form-batch");
expect(formBatch.textContent).toContain(
"Nama batch tidak boleh kosong"
);
});
test("Test tambah batch error", async () => {
fetch.once(JSON.stringify({}), { status: 400 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<TambahBatch />
</AuthContext.Provider>
);
const name_batch = getByTestId("name-batch-input");
const start_date = getByTestId("start-date-input");
const end_date = getByTestId("end-date-input");
await act(async () => {
await fireEvent.input(name_batch, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.input(start_date, { target: { value: "2020-10-08" } });
});
await act(async () => {
await fireEvent.input(end_date, { target: { value: "2020-10-15" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-batch"));
});
const batch = getByTestId("tambah-batch");
expect(batch.textContent).toContain("Error !, Data tidak dapat disimpan");
expect(fetch.mock.calls.length).toEqual(1);
});
import { cleanup, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import DetailDonasiBarang from "../../page/donasi-barang/DetailDonasiBarang";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test detail loaded donasi", async () => {
fetch.mockResponseOnce(
JSON.stringify({
id: "8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
donation_number: "7NGVBN",
user: "45897cc5-968c-44cf-931d-e646b095fcaf",
user_username: "admin-staging",
program: "6d7462da-6a85-4e2b-9930-69567090a5d5",
program_code: "3MXZ9T",
user_full_name: "Hello",
user_phone_number: "012345",
program_name: "dummy 2",
item: "Alat Tulis",
amount: "10",
donation_status: "001",
readable_donation_status: "Menunggu konfirmasi admin",
created_at: "2020-04-28T21:34:15.565614+07:00",
updated_at: "2020-04-28T21:34:15.565651+07:00",
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailDonasiBarang idDonasi={"8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-donasi");
expect(wait.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("page-detail-donasi"));
const data = getByTestId("page-detail-donasi");
expect(data.textContent).toContain("DETAIL DONASI");
});
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import ListDonasiBarang from "../../page/donasi-barang/ListDonasiBarang";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test List donasi", async () => {
fetch.mockResponseOnce(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
donation_number: "7NGVBN",
user: "45897cc5-968c-44cf-931d-e646b095fcaf",
program: "6d7462da-6a85-4e2b-9930-69567090a5d5",
program_code: "3MXZ9T",
user_username: "admin-staging",
user_full_name: "",
user_phone_number: "",
program_name: "dummy 2",
item: "Alat Tulis",
amount: "10",
donation_status: "001",
readable_donation_status: "Menunggu konfirmasi admin",
user_address: "Jalan Sesama No. 14",
created_at: "2020-04-28T21:34:15.565614+07:00",
updated_at: "2020-04-28T21:34:15.565651+07:00",
},
],
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListDonasiBarang />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
const data = getByTestId("tableList");
expect(data.textContent).toContain("admin-staging");
expect(data.textContent).toContain("dummy 2");
expect(data.textContent).toContain("Dalam Proses");
expect(fetch.mock.calls.length).toEqual(1);
});
test(" Test List transaksi filter", async () => {
fetch.once(
JSON.stringify({
count: 1,
next: null,
previous: null,
results: [
{
id: "8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a",
donation_number: "7NGVBN",
user: "45897cc5-968c-44cf-931d-e646b095fcaf",
program: "6d7462da-6a85-4e2b-9930-69567090a5d5",
program_code: "3MXZ9T",
user_username: "admin-staging",
user_full_name: "",
user_phone_number: "",
program_name: "dummy 2",
item: "Alat Tulis",
amount: "10",
donation_status: "001",
readable_donation_status: "Menunggu konfirmasi admin",
user_address: "Jalan Sesama No. 14",
created_at: "2020-04-28T21:34:15.565614+07:00",
updated_at: "2020-04-28T21:34:15.565651+07:00",
},
],
})
);
const { getByTestId, getByLabelText } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListDonasiBarang />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
const data = getByTestId("tableList");
expect(data.textContent).toContain("admin-staging");
expect(data.textContent).toContain("Dalam Proses");
expect(fetch.mock.calls.length).toEqual(1);
await act(async () => {
await fireEvent.click(getByTestId("filter-button"));
});
await act(async () => {
await fireEvent.input(
getByLabelText("Status Donasi", { target: { value: "001" } })
);
await fireEvent.click(getByTestId("submit-filter"));
});
expect(data.textContent).toContain("admin-staging");
expect(fetch.mock.calls.length).toEqual(2);
});
\ No newline at end of file
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import DetailDonasi from "../../page/donasi/DetailDonasi";
import DetailDonasiUang from "../../page/donasi/DetailDonasiUang";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
......@@ -33,7 +33,7 @@ test("Test detail loaded donasi", async () => {
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<DetailDonasi idDonasi={"8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a"} />
<DetailDonasiUang idDonasi={"8e9a8f94-cb5c-4b2d-b4f1-81ccfb9f1b0a"} />
</AuthContext.Provider>
);
const wait = getByTestId("waiting-detail-donasi");
......
import { act, cleanup, fireEvent, render } from "@testing-library/react";
import AuthContext from "../../utils/contex";
import React from "react";
import ListDonasi from "../../page/donasi/ListDonasi";
import ListDonasiUang from "../../page/donasi/ListDonasiUang";
import { waitFor } from "@testing-library/dom";
beforeEach(() => {
......@@ -40,7 +40,7 @@ test("Test List donasi", async () => {
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListDonasi />
<ListDonasiUang />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
......@@ -81,7 +81,7 @@ test(" Test List transaksi filter", async () => {
);
const { getByTestId, getByLabelText } = render(
<AuthContext.Provider value={{ profile: { token: "tester" } }}>
<ListDonasi />
<ListDonasiUang />
</AuthContext.Provider>
);
await waitFor(() => getByTestId("tableList"));
......
......@@ -33,7 +33,7 @@ test("Test detail program renders", async () => {
await waitFor(() => getByTestId("program"));
const program = getByTestId("program");
expect(program.textContent).toContain("Eddrick");
expect(fetch.mock.calls.length).toEqual(1);
expect(fetch.mock.calls.length).toEqual(2);
});
test("Test mock detail program return error", async () => {
......@@ -72,7 +72,7 @@ test("Test detail program delete", async () => {
await waitFor(() => getByTestId("page"));
const produk = getByTestId("page");
expect(produk.textContent).toContain("dummy 2");
expect(fetch.mock.calls.length).toEqual(1);
expect(fetch.mock.calls.length).toEqual(2);
const btnDeleteModal = getByTestId("button-delete-program-modal");
await act(async () => {
await fireEvent.click(btnDeleteModal);
......@@ -81,7 +81,7 @@ test("Test detail program delete", async () => {
await act(async () => {
await fireEvent.click(btnDelete);
});
expect(fetch.mock.calls.length).toEqual(2);
expect(fetch.mock.calls.length).toEqual(3);
});
test("Test detail produk delete error", async () => {
......@@ -110,7 +110,7 @@ test("Test detail produk delete error", async () => {
await waitFor(() => getByTestId("page"));
const produk = getByTestId("page");
expect(produk.textContent).toContain("Eddrick");
expect(fetch.mock.calls.length).toEqual(1);
expect(fetch.mock.calls.length).toEqual(2);
const btnDeleteModal = getByTestId("button-delete-program-modal");
await act(async () => {
await fireEvent.click(btnDeleteModal);
......@@ -119,8 +119,68 @@ test("Test detail produk delete error", async () => {
await act(async () => {
await fireEvent.click(btnDelete);
});
expect(fetch.mock.calls.length).toEqual(2);
expect(fetch.mock.calls.length).toEqual(3);
expect(produk.textContent).toContain(
"Tidak dapat menghapus program, mohon periksa apakah ada program ini."
);
});
test("Test progress program renders", async () => {
fetch
.once(
JSON.stringify({
id: "6d7462da-6a85-4e2b-9930-69567090a5d5",
code: "3MXZ9T",