Skip to content
Merged
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
4 changes: 3 additions & 1 deletion ooui/graph/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def __init__(self, graph_type, element):
) or None
self._show_percent = parse_bool_attribute(
element.get('showPercent')) if element.get('showPercent') else False
# showTotal is True by default only if totalDomain is defined, otherwise False
default_show_total = bool(self._total_domain)
self._show_total = parse_bool_attribute(
element.get('showTotal')) if element.get('showTotal') else True
element.get('showTotal')) if element.get('showTotal') else default_show_total
self._progressbar = parse_bool_attribute(
element.get('progressbar')) if element.get('progressbar') else False
self.domain_parse_values = {}
Expand Down
33 changes: 25 additions & 8 deletions spec/graph/graph_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(graph.fields).to(contain_only('potencia'))
expect(graph.total_domain).to(be_none)
expect(graph.show_percent).to(be_true)
expect(graph.show_total).to(be_true)
expect(graph.show_total).to(be_false) # False because no totalDomain
expect(graph.progressbar).to(be_false)
expect(graph.suffix).to(equal('kW'))

Expand Down Expand Up @@ -74,11 +74,20 @@
expect(result).not_to(have_key('progressbar'))
expect(result).not_to(have_key('showPercent'))

with it('should include showTotal by default'):
with it('should not include showTotal by default when no totalDomain'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" />
"""
graph = parse_graph(xml)
expect(graph.show_total).to(be_false)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', False))

with it('should include showTotal=True by default when totalDomain is defined'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" totalDomain="[('user', '=', uid)]" />
"""
graph = parse_graph(xml)
expect(graph.show_total).to(be_true)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', True))
Expand All @@ -101,14 +110,22 @@
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', True))

with it('should always include showTotal in response'):
xml = """<?xml version="1.0"?>
with it('should always include showTotal in response with correct value'):
xml_no_domain = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" />
"""
graph = parse_graph(xml)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal'))
expect(result['showTotal']).to(be_true)
graph_no_domain = parse_graph(xml_no_domain)
result_no_domain = graph_no_domain.process(50, 100)
expect(result_no_domain).to(have_key('showTotal'))
expect(result_no_domain['showTotal']).to(be_false)

xml_with_domain = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" totalDomain="[]" />
"""
graph_with_domain = parse_graph(xml_with_domain)
result_with_domain = graph_with_domain.process(50, 100)
expect(result_with_domain).to(have_key('showTotal'))
expect(result_with_domain['showTotal']).to(be_true)

xml_false = """<?xml version="1.0"?>
<graph string="My indicator" showTotal="0" type="indicator" />
Expand Down
4 changes: 2 additions & 2 deletions spec/graph/processor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_graph_data(xml, model):
"""
result = get_graph_data(xml, 'polissa')
expect(result).to(have_keys(
value=275.72, color='red'
value=275.72, color='red', showTotal=False # False because no totalDomain
))

with it('should process indicatorField graph'):
Expand All @@ -68,7 +68,7 @@ def get_graph_data(xml, model):
icon='slack',
suffix='kW',
type='indicatorField',
showTotal=True,
showTotal=True, # True because totalDomain="[]" is defined
))

with it('should process indicator graph'):
Expand Down