Skip to content

Commit

Permalink
#138 test for award printing
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 26, 2024
1 parent 9fcf70a commit b1cf075
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 15 additions & 0 deletions test/pages/test_awards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ def test_in_week
assert_equal('true', xml.xpath('/r/text()').to_s, xml)
end

def test_award
{
42 => [ 'darkgreen', '+42' ],
0 => [ 'lightgray', '—' ],
-7 => [ 'darkred', '-7' ]
}.each do |k, v|
xml = xslt(
"<xsl:copy-of select='z:award(#{k})'/>",
'<fb/>'
)
assert_equal(v[0], xml.xpath('/span/@class').to_s, xml)
assert_equal(v[1], xml.xpath('/span/text()').to_s, xml)
end
end

private

def xslt(template, xml, vars = {})
Expand Down
10 changes: 7 additions & 3 deletions xsl/awards.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SOFTWARE.
Calculates the amount to be paid to a user, according to the information
in current awards and previously posted "reconciliation" facts.
-->
<xsl:param name="name"/>
<xsl:param name="name" as="xs:string"/>
<xsl:variable name="rec" select="$fb/f[what='reconciliation' and who_name=$name][last()]"/>
<xsl:choose>
<xsl:when test="$rec">
Expand Down Expand Up @@ -108,7 +108,11 @@ SOFTWARE.
</xsl:choose>
</xsl:function>
<xsl:function name="z:award">
<xsl:param name="a"/>
<!--
Converts a number to a "span" with a properly formatted monetary value.
The span will have a "class" with the HTML color, according to the value.
-->
<xsl:param name="a" as="xs:integer"/>
<span>
<xsl:attribute name="class">
<xsl:choose>
Expand Down Expand Up @@ -138,7 +142,7 @@ SOFTWARE.
</span>
</xsl:function>
<xsl:function name="z:td-award">
<xsl:param name="a"/>
<xsl:param name="a" as="xs:integer"/>
<td class="ff right" data-value="{$a}">
<xsl:copy-of select="z:award($a)"/>
</td>
Expand Down

0 comments on commit b1cf075

Please sign in to comment.