mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
add currency spec file and update some class names
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
# Convert number to string currency using injected currency localisation settings.
|
||||
#
|
||||
# Injected: currencyLocalisation - see /app/serializers/api/currency_localization_serializer.rb
|
||||
|
||||
Darkswarm.filter "localiseCurrency", (currencyLocalization)->
|
||||
(amount) ->
|
||||
decimals = if currencyLocalization.hide_cents then 0 else 2
|
||||
amount_fixed = amount.toFixed(decimals)
|
||||
currency_str = ""
|
||||
currency_str = " " + currencyLocalization.currency if currencyLocalization.display_currency
|
||||
|
||||
# Return string
|
||||
if currencyLocalization.symbol_position == 'before'
|
||||
currencyLocalization.symbol + amount_fixed + currency_str
|
||||
else
|
||||
amount_fixed + " " + currencyLocalization.symbol + currency_str
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Convert number to string currency using injected currency localisation settings.
|
||||
#
|
||||
# @requires currencyConfig json - /app/serializers/api/currency_localization_serializer.rb
|
||||
# @return string
|
||||
Darkswarm.filter "localizeCurrency", (currencyConfig)->
|
||||
(amount) ->
|
||||
decimals = if currencyConfig.hide_cents then 0 else 2
|
||||
amount_fixed = amount.toFixed(2)
|
||||
currency_str = ""
|
||||
currency_str = " " + currencyConfig.currency if currencyConfig.display_currency
|
||||
|
||||
# Return: string. Varies with symbol position.
|
||||
if currencyConfig.symbol_position == 'before'
|
||||
currencyConfig.symbol + amount_fixed + currency_str
|
||||
else
|
||||
amount_fixed + " " + currencyConfig.symbol + currency_str
|
||||
|
||||
@@ -10,26 +10,26 @@
|
||||
.expanded{"ng-show" => "expanded"}
|
||||
%ul
|
||||
%li.cost
|
||||
.right {{ variant.price | localiseCurrency }}
|
||||
.right {{ variant.price | localizeCurrency }}
|
||||
Item cost
|
||||
%li{"bo-if" => "variant.fees.admin"}
|
||||
.right {{ variant.fees.admin | localiseCurrency }}
|
||||
.right {{ variant.fees.admin | localizeCurrency }}
|
||||
Admin fee
|
||||
%li{"bo-if" => "variant.fees.sales"}
|
||||
.right {{ variant.fees.sales | localiseCurrency }}
|
||||
.right {{ variant.fees.sales | localizeCurrency }}
|
||||
Sales fee
|
||||
%li{"bo-if" => "variant.fees.packing"}
|
||||
.right {{ variant.fees.packing | localiseCurrency }}
|
||||
.right {{ variant.fees.packing | localizeCurrency }}
|
||||
Packing fee
|
||||
%li{"bo-if" => "variant.fees.transport"}
|
||||
.right {{ variant.fees.transport | localiseCurrency }}
|
||||
.right {{ variant.fees.transport | localizeCurrency }}
|
||||
Transport fee
|
||||
%li{"bo-if" => "variant.fees.fundraising"}
|
||||
.right {{ variant.fees.fundraising | localiseCurrency }}
|
||||
.right {{ variant.fees.fundraising | localizeCurrency }}
|
||||
Fundraising fee
|
||||
%li
|
||||
%strong
|
||||
.right = {{ variant.price | localiseCurrency }}
|
||||
.right = {{ variant.price | localizeCurrency }}
|
||||
|
||||
|
||||
%a{"ng-click" => "expanded = !expanded"}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
.small-4.medium-2.large-2.columns.variant-price
|
||||
.table-cell.price
|
||||
%i.ofn-i_009-close
|
||||
{{ variant.price | localiseCurrency }}
|
||||
{{ variant.price | localizeCurrency }}
|
||||
|
||||
-# Now in a template in app/assets/javascripts/templates !
|
||||
%price-breakdown{"price-breakdown" => "_", variant: "variant",
|
||||
@@ -59,4 +59,4 @@
|
||||
.small-12.medium-2.large-2.columns.total-price.text-right
|
||||
.table-cell
|
||||
%strong
|
||||
{{ variant.getPrice() | localiseCurrency }}
|
||||
{{ variant.getPrice() | localizeCurrency }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Api::CurrencyLocalizationSerializer < ActiveModel::Serializer
|
||||
class Api::CurrencyConfigSerializer < ActiveModel::Serializer
|
||||
attributes :currency, :display_currency, :symbol, :symbol_position, :hide_cents, :decimal_mark, :thousands_separator
|
||||
|
||||
def currency
|
||||
@@ -22,20 +22,20 @@
|
||||
%small
|
||||
{{line_item.quantity}}
|
||||
%i.ofn-i_009-close
|
||||
{{ line_item.variant.price_with_fees | localiseCurrency }}
|
||||
{{ line_item.variant.price_with_fees | localizeCurrency }}
|
||||
|
||||
.columns.small-2
|
||||
%small
|
||||
\=
|
||||
%strong
|
||||
.right {{ line_item.variant.getPrice() | localiseCurrency }}
|
||||
.right {{ line_item.variant.getPrice() | localizeCurrency }}
|
||||
|
||||
%li.total-cart{"ng-show" => "Cart.line_items_present().length > 0"}
|
||||
.row
|
||||
.columns.small-6
|
||||
%em Total:
|
||||
.columns.small-6.text-right
|
||||
%strong {{ Cart.total() | localiseCurrency }}
|
||||
%strong {{ Cart.total() | localizeCurrency }}
|
||||
|
||||
.text-right
|
||||
%a.button.primary.small{href: checkout_path, "ng-disabled" => "Cart.dirty"} Quick checkout
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
describe 'convert number to localised currency ', ->
|
||||
filter = null
|
||||
|
||||
currencyconfig =
|
||||
currency: "D"
|
||||
symbol: "$"
|
||||
symbol_position: "before"
|
||||
hide_cents: "false"
|
||||
decimal_mark: "."
|
||||
thousands_separator: ","
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
module ($provide)->
|
||||
$provide.value "currencyConfig", currencyconfig
|
||||
null
|
||||
inject ($filter) ->
|
||||
filter = $filter('localizeCurrency')
|
||||
|
||||
it "adds decimal fraction to an amount", ->
|
||||
expect(filter(10)).toEqual "$10.00"
|
||||
|
||||
it "handles an existing fraction", ->
|
||||
expect(filter(9.9)).toEqual "$9.90"
|
||||
|
||||
it "can use any currency symbol", ->
|
||||
currencyconfig.symbol = "£"
|
||||
expect(filter(404.04)).toEqual "£404.04"
|
||||
currencyconfig.symbol = "$"
|
||||
|
||||
it "can place symbols after the amount", ->
|
||||
currencyconfig.symbol_position = "after"
|
||||
expect(filter(333.3)).toEqual "333.30 $"
|
||||
currencyconfig.symbol_position = "before"
|
||||
|
||||
it "can add a currency string", ->
|
||||
currencyconfig.display_currency = "true"
|
||||
expect(filter(5)).toEqual "$5.00 D"
|
||||
currencyconfig.display_currency = "false"
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ describe 'Variants service', ->
|
||||
beforeEach ->
|
||||
variant =
|
||||
id: 1
|
||||
base_price: 80.5
|
||||
price: 100
|
||||
price: 80.5
|
||||
price_with_fees: 100
|
||||
module 'Darkswarm'
|
||||
inject ($injector)->
|
||||
Variants = $injector.get("Variants")
|
||||
|
||||
Reference in New Issue
Block a user