-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(order): A buyer and seller should be manage orders
- A buyer should see their orders and status - A seller should see their orders made on their products [Delivers #187900465]
- Loading branch information
1 parent
5b1bd21
commit 4df8890
Showing
24 changed files
with
1,106 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import "@testing-library/jest-dom/jest-globals"; | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { Provider } from "react-redux"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
|
||
import store from "../redux/store"; | ||
import DeleteNotify from "../components/common/notify/DeleteNotify"; | ||
|
||
describe("DeleteNotify component", () => { | ||
const mockOnConfirm = jest.fn(); | ||
const mockOnCancel = jest.fn(); | ||
|
||
beforeEach(() => { | ||
render( | ||
<Provider store={store}> | ||
<Router> | ||
<DeleteNotify onConfirm={mockOnConfirm} onCancel={mockOnCancel} /> | ||
</Router> | ||
</Provider>, | ||
); | ||
}); | ||
|
||
test('renders the "Clear Cart" button', () => { | ||
const clearCartButton = screen.getByText("Clear Cart"); | ||
expect(clearCartButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("opens the modal when Clear Cart button is clicked", () => { | ||
const clearCartButton = screen.getByText("Clear Cart"); | ||
fireEvent.click(clearCartButton); | ||
|
||
const modalHeader = screen.getByText( | ||
"Are you sure you want to delete this product?", | ||
); | ||
expect(modalHeader).toBeInTheDocument(); | ||
}); | ||
|
||
test("calls onConfirm and closes modal when is clicked", () => { | ||
const clearCartButton = screen.getByText("Clear Cart"); | ||
fireEvent.click(clearCartButton); | ||
|
||
const confirmButton = screen.getByText("Yes, I'm sure"); | ||
fireEvent.click(confirmButton); | ||
|
||
expect(mockOnConfirm).toHaveBeenCalledTimes(1); | ||
expect( | ||
screen.queryByText("Are you sure you want to delete this product?"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls onCancel and closes modal when "No, cancel" is clicked', () => { | ||
const clearCartButton = screen.getByText("Clear Cart"); | ||
fireEvent.click(clearCartButton); | ||
|
||
const cancelButton = screen.getByText("No, cancel"); | ||
fireEvent.click(cancelButton); | ||
|
||
expect(mockOnCancel).toHaveBeenCalledTimes(1); | ||
expect( | ||
screen.queryByText("Are you sure you want to delete this product?"), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { orders } from "../../type"; | ||
import ordersReducer, { | ||
fetchOrders, | ||
updateOrderStatus, | ||
} from "../redux/reducers/ordersSlice"; | ||
|
||
describe("orders reducer", () => { | ||
const initialState = { | ||
isLoading: false, | ||
data: [] as unknown as orders, | ||
error: false, | ||
}; | ||
|
||
it("should handle initial state", () => { | ||
expect(ordersReducer(undefined, { type: "unknown" })).toEqual(initialState); | ||
}); | ||
|
||
it("should handle fetchOrders.pending", () => { | ||
const action = { type: fetchOrders.pending.type }; | ||
const state = ordersReducer(initialState, action); | ||
expect(state).toEqual({ | ||
...initialState, | ||
isLoading: true, | ||
}); | ||
}); | ||
|
||
it("should handle fetchOrders.fulfilled", () => { | ||
const mockOrders = [ | ||
{ id: 1, status: "pending" }, | ||
{ id: 2, status: "completed" }, | ||
]; | ||
const action = { type: fetchOrders.fulfilled.type, payload: mockOrders }; | ||
const state = ordersReducer(initialState, action); | ||
expect(state).toEqual({ | ||
...initialState, | ||
isLoading: false, | ||
data: mockOrders, | ||
}); | ||
}); | ||
|
||
it("should handle fetchOrders.rejected", () => { | ||
const action = { type: fetchOrders.rejected.type }; | ||
const state = ordersReducer(initialState, action); | ||
expect(state).toEqual({ | ||
...initialState, | ||
isLoading: false, | ||
error: true, | ||
}); | ||
}); | ||
|
||
it("should handle updateOrderStatus.pending", () => { | ||
const action = { type: updateOrderStatus.pending.type }; | ||
const state = ordersReducer(initialState, action); | ||
expect(state).toEqual({ | ||
...initialState, | ||
isLoading: true, | ||
}); | ||
}); | ||
|
||
it("should handle updateOrderStatus.rejected", () => { | ||
const action = { type: updateOrderStatus.rejected.type }; | ||
const state = ordersReducer(initialState, action); | ||
expect(state).toEqual({ | ||
...initialState, | ||
isLoading: false, | ||
error: true, | ||
}); | ||
}); | ||
|
||
it("should handle updateOrderStatus.fulfilled", () => { | ||
const initialStateWithData: any = { | ||
...initialState, | ||
data: [ | ||
{ | ||
order: { id: 1 }, | ||
products: [ | ||
{ id: 101, status: "pending" }, | ||
{ id: 102, status: "pending" }, | ||
], | ||
}, | ||
{ | ||
order: { id: 2 }, | ||
products: [{ id: 201, status: "pending" }], | ||
}, | ||
], | ||
}; | ||
|
||
const action = { | ||
type: updateOrderStatus.fulfilled.type, | ||
payload: { orderId: 1, productId: 102, status: "completed" }, | ||
}; | ||
|
||
const state = ordersReducer(initialStateWithData, action); | ||
|
||
expect(state.data[0].products[1].status).toEqual("completed"); | ||
expect(state.data[0].products[0].status).toEqual("pending"); | ||
expect(state.data[1].products[0].status).toEqual("pending"); | ||
}); | ||
}); |
Oops, something went wrong.