Use correct placeholders for VO count_on_hand

This commit is contained in:
Kristina Lim
2018-11-29 15:18:01 +08:00
parent f5dc03e118
commit 4f2d96d763
5 changed files with 64 additions and 3 deletions

View File

@@ -120,3 +120,51 @@ describe "VariantOverridesCtrl", ->
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
describe "count on hand placeholder", ->
beforeEach ->
scope.variantOverrides = {123: {}}
describe "when variant is on demand", ->
variant = null
beforeEach ->
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
# enforced.
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")}
it "is 'On demand' when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("on_demand"))
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')
describe "when variant is limited stock", ->
variant = null
beforeEach ->
variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20}
it "is variant count on hand when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(20)
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')