Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion InteractiveHtmlBom/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class Config:
default_checkboxes = ['Sourced', 'Placed']
html_config_fields = [
'dark_mode', 'show_pads', 'show_fabrication', 'show_silkscreen',
'highlight_pin1', 'redraw_on_drag', 'board_rotation', 'checkboxes',
'highlight_pin1', 'highlight_row_on_click', 'redraw_on_drag',
'board_rotation', 'checkboxes',
'bom_view', 'layer_view', 'offset_back_rotation',
'kicad_text_formatting', 'mark_when_checked', 'custom_metadata'
]
Expand All @@ -51,6 +52,7 @@ class Config:
show_fabrication = False
show_silkscreen = True
redraw_on_drag = True
highlight_row_on_click = False
highlight_pin1 = highlight_pin1_choices[0]
board_rotation = 0
offset_back_rotation = False
Expand Down Expand Up @@ -374,6 +376,9 @@ def add_options(cls, parser, version):
choices=cls.highlight_pin1_choices,
nargs='?',
help='Highlight first pin.')
parser.add_argument('--highlight-row-on-click',
help='Highlight BOM rows on click by default.',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change help string to indicate what default behavior is:
Highlight BOM rows on click (default is highlight on hover).

action='store_true')
parser.add_argument('--no-redraw-on-drag',
help='Do not redraw pcb on drag by default.',
action='store_true')
Expand Down Expand Up @@ -612,6 +617,7 @@ def set_from_args(self, args):
self.show_fabrication = args.show_fabrication
self.show_silkscreen = not args.hide_silkscreen
self.highlight_pin1 = args.highlight_pin1
self.highlight_row_on_click = args.highlight_row_on_click
self.redraw_on_drag = not args.no_redraw_on_drag
# Stored in 5 degree steps, wrap to -180..180 range
self.board_rotation = args.board_rotation // 5
Expand Down
2 changes: 1 addition & 1 deletion InteractiveHtmlBom/web/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ function initDefaults() {
}
initBooleanSetting("dnpOutline", false, "dnpOutlineCheckbox", dnpOutline);
initBooleanSetting("redrawOnDrag", config.redraw_on_drag, "dragCheckbox", setRedrawOnDrag);
initBooleanSetting("highlightRowOnClick", false, "highlightRowOnClickCheckbox", setHighlightRowOnClick);
initBooleanSetting("highlightRowOnClick", config.highlight_row_on_click === true, "highlightRowOnClickCheckbox", setHighlightRowOnClick);
initBooleanSetting("darkmode", config.dark_mode, "darkmodeCheckbox", setDarkMode);

var fields = ["checkboxes", "References"].concat(config.fields).concat(["Quantity"]);
Expand Down
40 changes: 40 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
import json
import os
from pathlib import Path
import re
import subprocess
import sys

import pytest


def test_module_import():
import InteractiveHtmlBom # noqa


@pytest.mark.parametrize('args, expected', [([], False), (['--highlight-row-on-click'], True)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is misplaced and is more like an integration test.

Add test_config.py and write it as a proper unit test that doesnt start any child processes.

def test_cli_highlight_row_on_click(tmp_path, args, expected):
board = tmp_path / 'board.json'
board.write_text(json.dumps({
'spec_version': 1,
'pcbdata': {
'edges_bbox': {'minx': 0, 'miny': 0, 'maxx': 10, 'maxy': 10},
'edges': [],
'drawings': {},
'footprints': [],
'metadata': {'title': '', 'revision': '', 'company': '', 'date': ''},
},
'components': [],
}), encoding='utf-8')

generator = (Path(__file__).resolve().parents[1] /
'InteractiveHtmlBom/generate_interactive_bom.py')
result = subprocess.run(
[sys.executable, str(generator), str(board), '--no-browser', *args],
env=dict(os.environ, INTERACTIVE_HTML_BOM_NO_DISPLAY='1'),
capture_output=True, text=True, timeout=90,
)
assert result.returncode == 0, result.stdout + result.stderr

html = (tmp_path / 'bom' / 'ibom.html').read_text(encoding='utf-8')
match = re.search(r'^var config = (.+)$', html, re.M)
assert match is not None
assert json.loads(match.group(1)).get('highlight_row_on_click', False) is expected