Skip to content

Commit

Permalink
[IMP] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Dec 26, 2024
1 parent d1b930d commit 3c61132
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 24 deletions.
51 changes: 27 additions & 24 deletions stock_barcodes/static/src/views/kanban_renderer.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ patch(KanbanRenderer.prototype, "add hotkey", {
}
}
},
getNextCard(direction, iCard, cards, iGroup, isGrouped) {
let nextCard = null;
switch (direction) {
case "down":
nextCard = iCard < cards[iGroup].length - 1 && cards[iGroup][iCard + 1];
break;
case "up":
nextCard = iCard > 0 && cards[iGroup][iCard - 1];
break;
case "right":
if (isGrouped) {
nextCard = iGroup < cards.length - 1 && cards[iGroup + 1][0];
} else {
nextCard = iCard < cards[0].length - 1 && cards[0][iCard + 1];
}
break;
case "left":
if (isGrouped) {
nextCard = iGroup > 0 && cards[iGroup - 1][0];
} else {
nextCard = iCard > 0 && cards[0][iCard - 1];
}
break;
}
return nextCard;
},

// eslint-disable-next-line complexity
// This is copied from the base kanban_renderer.
Expand Down Expand Up @@ -118,30 +144,7 @@ patch(KanbanRenderer.prototype, "add hotkey", {
iGroup = 0;
}
// Find next card to focus
let nextCard = null;
switch (direction) {
case "down":
nextCard = iCard < cards[iGroup].length - 1 && cards[iGroup][iCard + 1];
break;
case "up":
nextCard = iCard > 0 && cards[iGroup][iCard - 1];
break;
case "right":
if (isGrouped) {
nextCard = iGroup < cards.length - 1 && cards[iGroup + 1][0];
} else {
nextCard = iCard < cards[0].length - 1 && cards[0][iCard + 1];
}
break;
case "left":
if (isGrouped) {
nextCard = iGroup > 0 && cards[iGroup - 1][0];
} else {
nextCard = iCard > 0 && cards[0][iCard - 1];
}
break;
}

const nextCard = this.getNextCard(direction, iCard, cards, iGroup, isGrouped);
if (nextCard && nextCard instanceof HTMLElement) {
nextCard.focus();
return true;
Expand Down
1 change: 1 addition & 0 deletions stock_barcodes_camera/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def setUpClass(cls):
cls.location_hash = (
"#id=17&model=wiz.stock.barcodes.read.inventory&view_type=form"
)
cls.stock_barcodes_action = cls.env["stock.barcodes.action"]

def camera_barcode_scanner(self, location_hash=""):
if location_hash:
Expand Down
42 changes: 42 additions & 0 deletions stock_barcodes_camera/tests/test_stock_barcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,45 @@ def test_location_hash(self):
with self.assertRaises(IndexError):
invalid_loc_hash = self.location_hash.replace("model=", "modell=")
self.camera_barcode_scanner(invalid_loc_hash)

def test_open_inventory_action_valid_context(self):
test_context = {"default_model": "stock.barcodes.action"}
action = self.stock_barcodes_action.open_inventory_action(test_context)
self.assertIn("res_id", action, "The action should contain a 'res_id'.")
self.assertIn("context", action, "The action should contain a 'context'.")
self.assertEqual(
action["context"],
test_context,
"The context should match the provided one.",
)

def test_open_inventory_action_missing_option_group(self):
option_group = self.env.ref(
"stock_barcodes.stock_barcodes_option_group_inventory"
)
if option_group:
option_group.unlink()
with self.assertRaises(
ValueError, msg="Expected exception for missing option group."
):
self.stock_barcodes_action.open_inventory_action({})

def test_open_inventory_action_camera_barcode_scanner_disabled(self):
self.env["ir.config_parameter"].sudo().set_param(
"stock_barcodes.enable_camera_barcode_scanner", False
)
action = self.stock_barcodes_action.open_inventory_action({})
res_id = action.get("res_id")
wiz = self.env["wiz.stock.barcodes.read.inventory"].browse(res_id)
self.assertFalse(
wiz.show_barcode_scanner, "Barcode scanner should be disabled."
)

def test_open_inventory_action_camera_barcode_scanner_enabled(self):
self.env["ir.config_parameter"].sudo().set_param(
"stock_barcodes.enable_camera_barcode_scanner", True
)
action = self.stock_barcodes_action.open_inventory_action({})
res_id = action.get("res_id")
wiz = self.env["wiz.stock.barcodes.read.inventory"].browse(res_id)
self.assertTrue(wiz.show_barcode_scanner, "Barcode scanner should be enabled.")

0 comments on commit 3c61132

Please sign in to comment.