Skip to content

Commit

Permalink
test delete
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Sep 20, 2024
1 parent 4a5987d commit 258fe86
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
29 changes: 29 additions & 0 deletions test/components/ChooseDataset.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ describe("<ManageDatasets/>", () => {
});
});

test("user can delete dataset", async () => {
mockAxios.onGet(`/datasets/`)
.reply(200, mockSuccess(["d1", "d2"]));

mockAxios.onDelete(`/dataset/d1/`)
.reply(200, mockSuccess("d1"));

let state = mockAppState({
datasetNames: ["d1", "d2"]
});
const dispatch = jest.fn();
const user = userEvent.setup();

render(<RootContext.Provider value={state}>
<RootDispatchContext.Provider
value={dispatch}><ManageDatasets/>
</RootDispatchContext.Provider>
</RootContext.Provider>);

const links = screen.getAllByRole("button") as HTMLAnchorElement[];

await user.click(links[1]);

expect(dispatch.mock.calls[3][0]).toEqual({
type: ActionType.DATASET_DELETED,
payload: "d1"
});
});

test("user can upload new file", async () => {
mockAxios.onGet(`/datasets/`)
.reply(200, mockSuccess(["d1", "d2"]));
Expand Down
1 change: 0 additions & 1 deletion test/integration/dataService.itest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe("DataService", () => {
expect(dispatch.mock.calls.length).toBe(1);
});


test("it can fetch individual plot data", async () => {
const dispatch = jest.fn();
const sut = dataService("en", dispatch);
Expand Down
9 changes: 9 additions & 0 deletions test/rootReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ describe("rootReducer", () => {
{type: ActionType.PLOT_SELECTED, payload: "individual"});
expect(newState.selectedPlot).toBe("individual");
});

it("should delete dataset on DATASET_DELETED", () => {
const state = mockAppState({
datasetNames: ["d1", "d2"]
});
const newState = rootReducer(state,
{type: ActionType.DATASET_DELETED, payload: "d1"});
expect(newState.datasetNames).toEqual(["d2"]);
});
});

0 comments on commit 258fe86

Please sign in to comment.