mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Splitting out specs for switchClass service
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
describe "switchClass service", ->
|
||||
elementMock = timeoutMock = {}
|
||||
removeClass = addClass = switchClassService = null
|
||||
|
||||
beforeEach ->
|
||||
addClass = jasmine.createSpy('addClass')
|
||||
removeClass = jasmine.createSpy('removeClass')
|
||||
elementMock =
|
||||
addClass: addClass
|
||||
removeClass: removeClass
|
||||
timeoutMock = jasmine.createSpy('timeout').andReturn "new timeout"
|
||||
timeoutMock.cancel = jasmine.createSpy('timeout.cancel')
|
||||
|
||||
beforeEach ->
|
||||
module "ofn.admin" , ($provide) ->
|
||||
$provide.value '$timeout', timeoutMock
|
||||
return
|
||||
|
||||
beforeEach inject (switchClass) ->
|
||||
switchClassService = switchClass
|
||||
|
||||
it "calls addClass on the element once", ->
|
||||
switchClassService elementMock, "addClass", [], false
|
||||
expect(addClass).toHaveBeenCalledWith "addClass"
|
||||
expect(addClass.calls.length).toEqual 1
|
||||
|
||||
it "calls removeClass on the element for ", ->
|
||||
switchClassService elementMock, "", ["remClass1", "remClass2", "remClass3"], false
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass1"
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass2"
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass3"
|
||||
expect(removeClass.calls.length).toEqual 3
|
||||
|
||||
it "call cancel on element.timout only if it exists", ->
|
||||
switchClassService elementMock, "", [], false
|
||||
expect(timeoutMock.cancel).not.toHaveBeenCalled()
|
||||
elementMock.timeout = true
|
||||
switchClassService elementMock, "", [], false
|
||||
expect(timeoutMock.cancel).toHaveBeenCalled()
|
||||
|
||||
it "doesn't set up a new timeout if 'timeout' is false", ->
|
||||
switchClassService elementMock, "class1", ["class2"], false
|
||||
expect(timeoutMock).not.toHaveBeenCalled()
|
||||
|
||||
it "doesn't set up a new timeout if 'timeout' is a string", ->
|
||||
switchClassService elementMock, "class1", ["class2"], "string"
|
||||
expect(timeoutMock).not.toHaveBeenCalled()
|
||||
|
||||
it "sets up a new timeout if 'timeout' parameter is an integer", ->
|
||||
switchClassService elementMock, "class1", ["class2"], 1000
|
||||
expect(timeoutMock).toHaveBeenCalled()
|
||||
expect(elementMock.timeout).toEqual "new timeout"
|
||||
@@ -407,59 +407,6 @@ describe "dataSubmitter service", ->
|
||||
expect(rejectSpy.calls.length).toEqual 1
|
||||
expect(switchClassSpy).toHaveBeenCalledWith element, "update-error", ["update-pending", "update-success"], false
|
||||
|
||||
describe "switchClass service", ->
|
||||
elementMock = timeoutMock = {}
|
||||
removeClass = addClass = switchClassService = null
|
||||
|
||||
beforeEach ->
|
||||
addClass = jasmine.createSpy('addClass')
|
||||
removeClass = jasmine.createSpy('removeClass')
|
||||
elementMock =
|
||||
addClass: addClass
|
||||
removeClass: removeClass
|
||||
timeoutMock = jasmine.createSpy('timeout').andReturn "new timeout"
|
||||
timeoutMock.cancel = jasmine.createSpy('timeout.cancel')
|
||||
|
||||
beforeEach ->
|
||||
module "ofn.admin" , ($provide) ->
|
||||
$provide.value '$timeout', timeoutMock
|
||||
return
|
||||
|
||||
beforeEach inject (switchClass) ->
|
||||
switchClassService = switchClass
|
||||
|
||||
it "calls addClass on the element once", ->
|
||||
switchClassService elementMock, "addClass", [], false
|
||||
expect(addClass).toHaveBeenCalledWith "addClass"
|
||||
expect(addClass.calls.length).toEqual 1
|
||||
|
||||
it "calls removeClass on the element for ", ->
|
||||
switchClassService elementMock, "", ["remClass1", "remClass2", "remClass3"], false
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass1"
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass2"
|
||||
expect(removeClass).toHaveBeenCalledWith "remClass3"
|
||||
expect(removeClass.calls.length).toEqual 3
|
||||
|
||||
it "call cancel on element.timout only if it exists", ->
|
||||
switchClassService elementMock, "", [], false
|
||||
expect(timeoutMock.cancel).not.toHaveBeenCalled()
|
||||
elementMock.timeout = true
|
||||
switchClassService elementMock, "", [], false
|
||||
expect(timeoutMock.cancel).toHaveBeenCalled()
|
||||
|
||||
it "doesn't set up a new timeout if 'timeout' is false", ->
|
||||
switchClassService elementMock, "class1", ["class2"], false
|
||||
expect(timeoutMock).not.toHaveBeenCalled()
|
||||
|
||||
it "doesn't set up a new timeout if 'timeout' is a string", ->
|
||||
switchClassService elementMock, "class1", ["class2"], "string"
|
||||
expect(timeoutMock).not.toHaveBeenCalled()
|
||||
|
||||
it "sets up a new timeout if 'timeout' parameter is an integer", ->
|
||||
switchClassService elementMock, "class1", ["class2"], 1000
|
||||
expect(timeoutMock).toHaveBeenCalled()
|
||||
expect(elementMock.timeout).toEqual "new timeout"
|
||||
|
||||
describe "Auxiliary functions", ->
|
||||
describe "getting a zero filled two digit number", ->
|
||||
it "returns the number as a string if its value is greater than or equal to 10", ->
|
||||
|
||||
Reference in New Issue
Block a user