Ensure in UI compatible VO count and on demand

This commit is contained in:
Kristina Lim
2018-11-28 19:31:39 +08:00
parent a32bb0445f
commit cc003c99d5
4 changed files with 112 additions and 3 deletions

View File

@@ -87,3 +87,66 @@ describe "VariantOverridesCtrl", ->
$httpBackend.flush()
expect(VariantOverrides.updateData).toHaveBeenCalledWith variant_overrides_mock
expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.'
describe "ensuring that on demand and count on hand settings are compatible", ->
describe "changing to limited stock when count on hand is set", ->
beforeEach ->
scope.variantOverrides = {123: {2: {id: 5, on_demand: true}}}
describe "when count on hand is set", ->
beforeEach ->
scope.variantOverrides[123][2].count_on_hand = 1
it "changes to limited stock and registers dirty attribute", ->
scope.selectLimitedStockIfCountOnHandSet(123, 2)
expect(scope.variantOverrides[123][2].on_demand).toBe(false)
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.on_demand).toBe(false)
describe "when count on hand is null", ->
beforeEach ->
scope.variantOverrides[123][2].count_on_hand = null
it "does not change to limited stock", ->
scope.selectLimitedStockIfCountOnHandSet(123, 2)
expect(scope.variantOverrides[123][2].on_demand).toBe(true)
describe "when count on hand is blank string", ->
beforeEach ->
scope.variantOverrides[123][2].count_on_hand = ''
it "does not change to limited stock", ->
scope.selectLimitedStockIfCountOnHandSet(123, 2)
expect(scope.variantOverrides[123][2].on_demand).toBe(true)
describe "clearing count on hand when not limited stock", ->
beforeEach ->
scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}}
describe "when on demand is false", ->
beforeEach ->
scope.variantOverrides[123][2].on_demand = false
it "does not clear count on hand", ->
scope.clearCountOnHandUnlessLimitedStock(123, 2)
expect(scope.variantOverrides[123][2].count_on_hand).toEqual(1)
describe "when on demand is true", ->
beforeEach ->
scope.variantOverrides[123][2].on_demand = true
it "clears count on hand and registers dirty attribute", ->
scope.clearCountOnHandUnlessLimitedStock(123, 2)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
describe "when on demand is null", ->
beforeEach ->
scope.variantOverrides[123][2].on_demand = null
it "clears count on hand and registers dirty attribute", ->
scope.clearCountOnHandUnlessLimitedStock(123, 2)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()