Fakultas Ilmu Komputer UI

Commit bd46a3cf authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[RED] Add test for riwayat acara donor

parent 18eab632
import moment from "moment"
import { idGeneratorFactory } from "../utils/number"
const idGenerator = idGeneratorFactory(1)
export const acaraDonorFactory = override => ({
id: idGenerator(),
status: "false",
alamat_institusi: "Pacilkom",
alamat_lokasi_donor: "Sekre Pacil",
email_kantor: "pacil@cs.ui.ac.id",
email_koor: "pacilia@gmail.com",
kategori: "Terbuka",
kecamatan: "Beji",
keterangan: "",
nama_institusi: "Pacilkom",
nama_koor: "dr. Pacilia",
no_telp_kantor: "08165342342",
no_telp_koor: "08167021743",
perkiraan_jumlah_donor: 455,
waktu_berakhir: moment()
.add(1, "hours")
.format(),
waktu_mulai: moment()
.add(2, "hours")
.format(),
...override,
})
......@@ -2,15 +2,18 @@ import { fireEvent, screen, waitFor } from "@testing-library/react"
import React from "react"
import {
getAgendaDonor,
getRiwayatAcaraDonor,
getRiwayatDonor,
getUserProfile,
getFormulirDaftarDonor,
} from "../api"
import { renderAuthenticated } from "../utils/test-util"
import { acaraDonorFactory } from "./acara-donor.factory"
import { jadwalDonorFactory } from "./jadwal-donor.factory"
import ProfilePage from "./profile"
getAgendaDonor.mockResolvedValue({ data: [] })
getUserProfile.mockResolvedValue({ data: { profile: {} } })
getRiwayatAcaraDonor.mockResolvedValue({ data: { count: 0, results: [] } })
getRiwayatDonor.mockResolvedValue({ data: { count: 0, results: [] } })
describe(`Kartu Donor`, () => {
......@@ -267,3 +270,120 @@ describe("Riwayat Donor", () => {
)
})
})
describe("Riwayat Acara Donor", () => {
it("shows descriptive message when there is no riwayat acara donor", async () => {
getRiwayatAcaraDonor.mockResolvedValueOnce({
data: {
count: 0,
results: [],
},
})
renderAuthenticated(<ProfilePage />)
expect(
await screen.findByText(/Belum ada riwayat acara donor/i)
).toBeInTheDocument()
await waitFor(() =>
expect(screen.queryByText("Loading...")).not.toBeInTheDocument()
)
})
it("shows riwayat acara donor on success", async () => {
getRiwayatAcaraDonor.mockResolvedValue({
data: {
count: 1,
results: [
{
id: 1,
status: "false",
alamat_institusi: "Pacilkom",
alamat_lokasi_donor: "Sekre Pacil",
email_kantor: "pacil@cs.ui.ac.id",
email_koor: "pacilia@gmail.com",
kategori: "Terbuka",
kecamatan: "Beji",
keterangan: "",
nama_institusi: "Pacilkom",
nama_koor: "dr. Pacilia",
no_telp_kantor: "08165342342",
no_telp_koor: "08167021743",
perkiraan_jumlah_donor: 455,
waktu_berakhir: "2020-06-02T10:00:00+07:00",
waktu_mulai: "2020-06-02T12:00:00+07:00",
},
],
},
})
renderAuthenticated(<ProfilePage />)
await screen.findByText("Lokasi")
expect(screen.getByText("Sekre Pacil"))
expect(screen.getByText("2 Juni 2020, (10:00 - 12:00)"))
expect(screen.getByText("Ditolak"))
await waitFor(() =>
expect(screen.queryByText("Loading...")).not.toBeInTheDocument()
)
})
it("has clickable pagination", async () => {
const acara_donor1 = acaraDonorFactory({
alamat_lokasi_donor: "Yuli Pacil",
})
const acara_donor4 = acaraDonorFactory({
alamat_lokasi_donor: "Belyos Pacil",
})
getRiwayatAcaraDonor
.mockResolvedValueOnce({
data: {
count: 4,
results: [acara_donor1, acaraDonorFactory(), acaraDonorFactory()],
},
})
.mockResolvedValueOnce({
data: {
count: 4,
results: [acara_donor4],
},
})
.mockResolvedValueOnce({
data: {
count: 4,
results: [acara_donor4, acaraDonorFactory(), acaraDonorFactory()],
},
})
.mockResolvedValueOnce({
data: {
count: 4,
results: [acara_donor4],
},
})
renderAuthenticated(<ProfilePage />)
expect(await screen.findByText("Yuli Pacil")).toBeInTheDocument()
fireEvent.click(screen.getByText("Halaman 2 riwayat acara donor"))
expect(await screen.findByText("Belyos Pacil")).toBeInTheDocument()
fireEvent.click(screen.getByText("Halaman sebelumnya riwayat acara donor"))
expect(await screen.findByText("Yuli Pacil")).toBeInTheDocument()
fireEvent.click(screen.getByText("Halaman selanjutnya riwayat acara donor"))
expect(await screen.findByText("Gedung baru Fasilkom")).toBeInTheDocument()
await waitFor(() =>
expect(screen.queryByText("Loading...")).not.toBeInTheDocument()
)
})
it("shows retry button on error and can be retried", async () => {
getRiwayatDonor
.mockRejectedValueOnce(new Error("Network error"))
.mockResolvedValueOnce({
data: {
count: 1,
results: [acaraDonorFactory({ alamat_lokasi_donor: "Yuli Pacil" })],
},
})
renderAuthenticated(<ProfilePage />)
expect(await screen.findByText(/Coba lagi/i)).toBeInTheDocument()
fireEvent.click(screen.getByText(/Coba lagi/i))
expect(await screen.findByText("Yuli Pacil")).toBeInTheDocument()
await waitFor(() =>
expect(screen.queryByText("Loading...")).not.toBeInTheDocument()
)
})
})
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