Fakultas Ilmu Komputer UI

Commit 55c6e9c1 authored by Jeffrey's avatar Jeffrey
Browse files

Merge branch 'coldfix-sprint_4' into 'staging'

Coldfix sprint 4

See merge request !62
parents 57446729 63ddb169
Pipeline #47233 passed with stages
in 6 minutes and 53 seconds
......@@ -41,6 +41,7 @@ staging:
script:
- npm install
- CI=false npm run build
- cp _redirects dist
- npm install netlify-cli -g --unsafe-perm
- netlify deploy --dir dist --prod
only:
......
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 EditProduk from "../../page/program/EditProgram";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(cleanup);
test("Test edit program renders", async () => {
fetch.once(
JSON.stringify({
id: "6d7462da-6a85-4e2b-9930-69567090a5d5",
code: "3MXZ9T",
name: "dummy 2",
description: "yeyyy",
start_date_time: null,
end_date_time: null,
location: "Depok",
speaker: "Eddrick",
poster_image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/programs/1_txtcYocQEGtOFN33ZCTDbw.png",
})
);
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<EditProduk />
</AuthContext.Provider>
);
const waitProgram = getByTestId("waiting-edit-program");
expect(waitProgram.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("edit-program"));
const name_program = getByTestId("name-program-input");
expect(name_program.value).toEqual("dummy 2");
await act(async () => {
await fireEvent.input(name_program, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-program"));
});
expect(fetch.mock.calls.length).toEqual(2);
});
test("Test edit program renders error", async () => {
fetch
.once(
JSON.stringify({
id: "6d7462da-6a85-4e2b-9930-69567090a5d5",
code: "3MXZ9T",
name: "dummy 2",
description: "yeyyy",
start_date_time: null,
end_date_time: null,
location: "Depok",
speaker: "Eddrick",
poster_image:
"https://industripilar-api-staging.s3.amazonaws.com/media/uploads/programs/1_txtcYocQEGtOFN33ZCTDbw.png",
})
)
.once(JSON.stringify({}), { status: 400 });
const { getByTestId } = render(
<AuthContext.Provider value={{ profile: { token: "BEBAS" } }}>
<EditProduk />
</AuthContext.Provider>
);
const waitProgram = getByTestId("waiting-edit-program");
expect(waitProgram.textContent).toContain("Fetching data..");
await waitFor(() => getByTestId("edit-program"));
const name_program = getByTestId("name-program-input");
const photo_program = getByTestId("photo-program");
expect(name_program.value).toEqual("dummy 2");
await act(async () => {
await fireEvent.input(name_program, { target: { value: "test" } });
});
await act(async () => {
await fireEvent.input(photo_program, { target: { value: "" } });
});
await act(async () => {
await fireEvent.submit(getByTestId("submit-program"));
});
const produk = getByTestId("edit-program");
expect(produk.textContent).toContain("Error !, Data tidak dapat disimpan");
expect(fetch.mock.calls.length).toEqual(2);
});
\ No newline at end of file
......@@ -104,7 +104,7 @@ const FormProgram = ({ onSubmit, initialData = null }) => {
) : null}
<RowInput>
<LabelInput htmlFor="poster_image">Gambar Poster </LabelInput>
<InputForm type="file" name="poster_image" ref={register} />
<InputForm type="file" name="poster_image" data-testid="photo-program" ref={register} />
</RowInput>
<RowInput>
<InputSubmitForm type="submit" data-testid="submit-program" />
......
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