Skip to content

Commit

Permalink
ZPS-21 [Osaide] Adding tests, fixing about me bug
Browse files Browse the repository at this point in the history
  • Loading branch information
picaso committed Aug 7, 2016
1 parent 7023518 commit 755d8d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 4 additions & 0 deletions ParrotStatus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
2F21AA261D430D7C009EEFC1 /* FlightModeStatusAnswer.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2F21AA231D430D7C009EEFC1 /* FlightModeStatusAnswer.xml */; };
2F21AA271D430D7C009EEFC1 /* ConcertHallStatusAnswer.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2F21AA241D430D7C009EEFC1 /* ConcertHallStatusAnswer.xml */; };
2F21AA281D430D7C009EEFC1 /* HeadDetectionStatusAnswer.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2F21AA251D430D7C009EEFC1 /* HeadDetectionStatusAnswer.xml */; };
2F2C71BF1D570AF20000FF91 /* NoiseControlLevelAnswer.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2F2C71BE1D570AF20000FF91 /* NoiseControlLevelAnswer.xml */; };
2F6F054D1D4448D2002CB556 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2F6F054B1D4448D2002CB556 /* Credits.rtf */; };
2F6F054E1D4448D2002CB556 /* EULA.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2F6F054C1D4448D2002CB556 /* EULA.rtf */; };
2F6F05501D444A27002CB556 /* About.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F6F054F1D444A27002CB556 /* About.swift */; };
Expand Down Expand Up @@ -65,6 +66,7 @@
2F21AA231D430D7C009EEFC1 /* FlightModeStatusAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = FlightModeStatusAnswer.xml; sourceTree = "<group>"; };
2F21AA241D430D7C009EEFC1 /* ConcertHallStatusAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = ConcertHallStatusAnswer.xml; sourceTree = "<group>"; };
2F21AA251D430D7C009EEFC1 /* HeadDetectionStatusAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = HeadDetectionStatusAnswer.xml; sourceTree = "<group>"; };
2F2C71BE1D570AF20000FF91 /* NoiseControlLevelAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = NoiseControlLevelAnswer.xml; sourceTree = "<group>"; };
2F3683281D0E911F00E55E87 /* SoftwareVersionAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = SoftwareVersionAnswer.xml; sourceTree = "<group>"; };
2F3683381D0E917E00E55E87 /* NoiseCancellationStatusAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = NoiseCancellationStatusAnswer.xml; sourceTree = "<group>"; };
2F3683411D0E91A800E55E87 /* BatteryInfoAnswer.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = BatteryInfoAnswer.xml; sourceTree = "<group>"; };
Expand Down Expand Up @@ -151,6 +153,7 @@
2F3683381D0E917E00E55E87 /* NoiseCancellationStatusAnswer.xml */,
2F3683411D0E91A800E55E87 /* BatteryInfoAnswer.xml */,
2F779B301D13DF180090F724 /* NoiseControlStatusAnswer.xml */,
2F2C71BE1D570AF20000FF91 /* NoiseControlLevelAnswer.xml */,
);
path = resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -415,6 +418,7 @@
2F21AA281D430D7C009EEFC1 /* HeadDetectionStatusAnswer.xml in Resources */,
2F21AA261D430D7C009EEFC1 /* FlightModeStatusAnswer.xml in Resources */,
2F0A2CE01D0EA1100091616A /* NoiseCancellationStatusAnswer.xml in Resources */,
2F2C71BF1D570AF20000FF91 /* NoiseControlLevelAnswer.xml in Resources */,
2FC9CC631D4DAC93007EBED0 /* DeviceNameAnswer.xml in Resources */,
2F0A2CE71D0EA1130091616A /* BatteryInfoAnswer.xml in Resources */,
);
Expand Down
6 changes: 5 additions & 1 deletion ParrotStatus/models/NoiseControlState.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct NoiseControlState {
struct NoiseControlState: Equatable {
private static let max: Int = 2
private static let normal: Int = 1

Expand Down Expand Up @@ -34,3 +34,7 @@ struct NoiseControlState {
}

}

func == (lhs: NoiseControlState, rhs: NoiseControlState) -> Bool {
return lhs.urlParameter() == rhs.urlParameter()
}
5 changes: 5 additions & 0 deletions ParrotStatusTests/resources/NoiseControlLevelAnswer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<answer path="/api/audio/noise_control/get">
<audio>
<noise_control value="1" type="aoc" />
</audio>
</answer>
22 changes: 11 additions & 11 deletions ParrotStatusTests/services/BTCommunicationServiceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ class ParrotZikApiMock: ParrotZik2Api {
var getAsyncFlightModeStatusWasCalled = false
var getAsyncConcertHallStatusWasCalled = false
var getAsyncheadDetectionStatusWasCalled = false

func reset() {
getAsyncApplicationVersionWasCalled = false
getAsyncNoiseCancellationStatusWasCalled = false
getAsyncBatteryInfoWasCalled = false
getAsyncFriendlyNameWasCalled = false
getAsyncNoiseControlStatusWasCalled = false
getAsyncEqualizerStatusWasCalled = false
}
var getAsyncNoiseControlLevelStatusWasCalled = false

func allApiWereCalled() -> Bool {
return getAsyncApplicationVersionWasCalled &&
Expand All @@ -34,7 +26,8 @@ class ParrotZikApiMock: ParrotZik2Api {
getAsyncFriendlyNameWasCalled &&
getAsyncNoiseControlStatusWasCalled &&
getAsyncEqualizerStatusWasCalled &&
getAsyncFlightModeStatusWasCalled
getAsyncFlightModeStatusWasCalled &&
getAsyncNoiseControlLevelStatusWasCalled
}

override func getAsyncApplicationVersion() -> Bool {
Expand Down Expand Up @@ -82,6 +75,12 @@ class ParrotZikApiMock: ParrotZik2Api {
return true
}

override func getAsyncNoiseControlLevelStatus() -> Bool {
getAsyncNoiseControlLevelStatusWasCalled = true
return true
}


}

class ZikResponseHandlerMock: ZikResponseHandler {}
Expand All @@ -98,9 +97,9 @@ class BTCommunicationServiceTest: QuickSpec {
}

beforeEach {
parrotZikApiMock = ParrotZikApiMock()
serviceUnderTest = BTCommunicationService(api: parrotZikApiMock,
zikResponseHandler: zikResponseHandlerMock)
parrotZikApiMock.reset()
}

describe("Parrot status communication service") {
Expand All @@ -110,6 +109,7 @@ class BTCommunicationServiceTest: QuickSpec {
.rfcommChannelData(IOBluetoothRFCOMMChannel(), data: &data, length: 3)
expect(parrotZikApiMock.allApiWereCalled()).to(beTrue())
}

}
}

Expand Down
10 changes: 10 additions & 0 deletions ParrotStatusTests/services/ZikResponseHandlerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class ZikResponseHandlerTest: QuickSpec {
handler.handle(answer!)
expect(deviceState.name).to(equal("Picaso"))
}

it("should mutate deviceState to reflect NoiseControl Level state") {
let answer = self.loadXml("NoiseControlLevelAnswer")
expect(deviceState.noiseControlLevelState)
.to(equal(NoiseControlState.cancellingNormal()))
handler.handle(answer!)
expect(deviceState.noiseControlLevelState)
.to(equal(NoiseControlState.streetNormal()))
}

}
}

Expand Down

0 comments on commit 755d8d5

Please sign in to comment.