| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { setupPosEnv, dialogActions } from "../utils"; |
| 3 |
import { definePosModels } from "../data/generate_model_definitions"; |
| 4 |
import { mountWithCleanup } from "@web/../tests/web_test_helpers"; |
| 5 |
import { click } from "@odoo/hoot-dom"; |
| 6 |
import { InternalNoteButton } from "@point_of_sale/app/screens/product_screen/control_buttons/orderline_note_button/orderline_note_button"; |
| 7 |
import { OrderSummary } from "@point_of_sale/app/screens/product_screen/order_summary/order_summary"; |
| 8 |
|
| 9 |
definePosModels(); |
| 10 |
|
| 11 |
test("orderline_note_button.js", async () => { |
| 12 |
const store = await setupPosEnv(); |
| 13 |
const order = store.addNewOrder(); |
| 14 |
const productTmplCombo = store.models["product.template"].get(7); |
| 15 |
|
| 16 |
const productComboSteps = [ |
| 17 |
() => click("#article_product_8"), // Wood Chair 1/2 |
| 18 |
() => click("#article_product_8"), // Wood Chair 2/2 |
| 19 |
() => click("#article_product_10"), // Wood desk |
| 20 |
() => click(".confirm"), // Confirm combo configuration |
| 21 |
]; |
| 22 |
const lineAction = async () => |
| 23 |
await store.addLineToCurrentOrder({ |
| 24 |
product_tmpl_id: productTmplCombo, |
| 25 |
qty: 1, |
| 26 |
}); |
| 27 |
const line = await dialogActions(lineAction, productComboSteps); |
| 28 |
expect(order.lines[0].qty).toBe(1); |
| 29 |
expect(order.lines[1].qty).toBe(1); |
| 30 |
expect(order.lines[2].qty).toBe(2); |
| 31 |
const orderSummary = await mountWithCleanup(OrderSummary, { props: {} }); |
| 32 |
orderSummary._setValue(4); |
| 33 |
expect(order.lines[0].qty).toBe(4); |
| 34 |
expect(order.lines[1].qty).toBe(4); |
| 35 |
expect(order.lines[2].qty).toBe(8); |
| 36 |
const comp = await mountWithCleanup(InternalNoteButton, { props: { label: "" } }); |
| 37 |
await comp.setChanges(line, '[{"1":"Test","colorIndex":0}]'); |
| 38 |
order.updateLastOrderChange(); |
| 39 |
orderSummary._setValue(9); |
| 40 |
|
| 41 |
const noteAction = async () => await comp.setChanges(line, '[{"2":"Test","colorIndex":0}]'); |
| 42 |
await dialogActions(noteAction, productComboSteps); |
| 43 |
// Check quantity |
| 44 |
expect(order.lines[0].qty).toBe(4); |
| 45 |
expect(order.lines[1].qty).toBe(4); |
| 46 |
expect(order.lines[2].qty).toBe(8); |
| 47 |
expect(order.lines[3].qty).toBe(5); |
| 48 |
expect(order.lines[4].qty).toBe(5); |
| 49 |
expect(order.lines[5].qty).toBe(10); |
| 50 |
|
| 51 |
// Check notes (only on parent lines) |
| 52 |
expect(order.lines[0].note).toBe('[{"1":"Test","colorIndex":0}]'); |
| 53 |
expect(order.lines[3].note).toBe('[{"2":"Test","colorIndex":0}]'); |
| 54 |
}); |