| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { click, queryAllTexts } from "@odoo/hoot-dom"; |
| 3 |
import { |
| 4 |
clickSave, |
| 5 |
defineModels, |
| 6 |
defineParams, |
| 7 |
fields, |
| 8 |
models, |
| 9 |
mountView, |
| 10 |
onRpc, |
| 11 |
} from "@web/../tests/web_test_helpers"; |
| 12 |
|
| 13 |
class Partner extends models.Model { |
| 14 |
sun = fields.Boolean(); |
| 15 |
mon = fields.Boolean(); |
| 16 |
tue = fields.Boolean(); |
| 17 |
wed = fields.Boolean(); |
| 18 |
thu = fields.Boolean(); |
| 19 |
fri = fields.Boolean(); |
| 20 |
sat = fields.Boolean(); |
| 21 |
|
| 22 |
_records = [ |
| 23 |
{ |
| 24 |
id: 1, |
| 25 |
sun: false, |
| 26 |
mon: false, |
| 27 |
tue: false, |
| 28 |
wed: false, |
| 29 |
thu: false, |
| 30 |
fri: false, |
| 31 |
sat: false, |
| 32 |
}, |
| 33 |
]; |
| 34 |
} |
| 35 |
|
| 36 |
defineModels([Partner]); |
| 37 |
|
| 38 |
test("simple week recurrence widget", async () => { |
| 39 |
expect.assertions(13); |
| 40 |
defineParams({ lang_parameters: { week_start: 1 } }); |
| 41 |
let writeCall = 0; |
| 42 |
onRpc("web_save", ({ args }) => { |
| 43 |
writeCall++; |
| 44 |
if (writeCall === 1) { |
| 45 |
expect(args[1].sun).toBe(true); |
| 46 |
} |
| 47 |
if (writeCall === 2) { |
| 48 |
expect(args[1].sun).not.toBe(true); |
| 49 |
expect(args[1].mon).toBe(true); |
| 50 |
expect(args[1].tue).toBe(true); |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
await mountView({ |
| 55 |
type: "form", |
| 56 |
resModel: "partner", |
| 57 |
resId: 1, |
| 58 |
arch: /* xml */ `<form><sheet><group><widget name="week_days" /></group></sheet></form>`, |
| 59 |
}); |
| 60 |
|
| 61 |
expect(queryAllTexts(".o_recurrent_weekday_label")).toEqual( |
| 62 |
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| 63 |
{ message: "labels should be short week names" } |
| 64 |
); |
| 65 |
expect(".form-check input:disabled").toHaveCount(0, { |
| 66 |
message: "all inputs should be enabled in edit mode", |
| 67 |
}); |
| 68 |
|
| 69 |
await click("td:nth-child(7) input"); |
| 70 |
expect("td:nth-child(7) input").toBeChecked({ |
| 71 |
message: "sunday checkbox should be checked", |
| 72 |
}); |
| 73 |
|
| 74 |
await clickSave(); |
| 75 |
|
| 76 |
await click("td:nth-child(1) input"); |
| 77 |
expect("td:nth-child(1) input").toBeChecked({ |
| 78 |
message: "monday checkbox should be checked", |
| 79 |
}); |
| 80 |
|
| 81 |
await click("td:nth-child(2) input"); |
| 82 |
expect("td:nth-child(2) input").toBeChecked({ |
| 83 |
message: "tuesday checkbox should be checked", |
| 84 |
}); |
| 85 |
|
| 86 |
// uncheck Sunday checkbox and check write call |
| 87 |
await click("td:nth-child(7) input"); |
| 88 |
expect("td:nth-child(7) input").not.toBeChecked({ |
| 89 |
message: "sunday checkbox should be unchecked", |
| 90 |
}); |
| 91 |
|
| 92 |
await clickSave(); |
| 93 |
|
| 94 |
expect("td:nth-child(7) input").not.toBeChecked({ |
| 95 |
message: "sunday checkbox should be unchecked", |
| 96 |
}); |
| 97 |
expect("td:nth-child(1) input").toBeChecked({ message: "monday checkbox should be checked" }); |
| 98 |
expect("td:nth-child(2) input").toBeChecked({ |
| 99 |
message: "tuesday checkbox should be checked", |
| 100 |
}); |
| 101 |
}); |
| 102 |
|
| 103 |
test("week recurrence widget readonly modifiers", async () => { |
| 104 |
defineParams({ lang_parameters: { week_start: 1 } }); |
| 105 |
await mountView({ |
| 106 |
type: "form", |
| 107 |
resModel: "partner", |
| 108 |
resId: 1, |
| 109 |
arch: /* xml */ `<form><sheet><group><widget name="week_days" readonly="1"/></group></sheet></form>`, |
| 110 |
}); |
| 111 |
|
| 112 |
expect(queryAllTexts(".o_recurrent_weekday_label")).toEqual( |
| 113 |
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| 114 |
{ message: "labels should be short week names" } |
| 115 |
); |
| 116 |
expect(".form-check input:disabled").toHaveCount(7, { |
| 117 |
message: "all inputs should be disabled in readonly mode", |
| 118 |
}); |
| 119 |
}); |
| 120 |
|
| 121 |
test("week recurrence widget show week start as per language configuration", async () => { |
| 122 |
defineParams({ lang_parameters: { week_start: 5 } }); |
| 123 |
await mountView({ |
| 124 |
type: "form", |
| 125 |
resModel: "partner", |
| 126 |
resId: 1, |
| 127 |
arch: /* xml */ `<form><sheet><group><widget name="week_days"/></group></sheet></form>`, |
| 128 |
}); |
| 129 |
|
| 130 |
expect(queryAllTexts(".o_recurrent_weekday_label")).toEqual( |
| 131 |
["Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu"], |
| 132 |
{ message: "labels should be short week names" } |
| 133 |
); |
| 134 |
}); |