Skip to content

Commit

Permalink
Merge pull request #189 from kojiba/main
Browse files Browse the repository at this point in the history
Added first items and validation of items for
  • Loading branch information
Illia Kucheriavyi authored Aug 7, 2020
2 parents e408d73 + 0a9d9c1 commit fda6f6c
Show file tree
Hide file tree
Showing 15 changed files with 574 additions and 164 deletions.
61 changes: 61 additions & 0 deletions O-FISHTests/CatchViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,67 @@ class CatchViewModelTests: XCTestCase {
//then
XCTAssertNotNil(fish)
}


func testIsComplete() {
//given
let sut = CatchViewModel()
sut.fish = "Some fish"

// when
sut.quantityType = [.weight, .count]
sut.weight = 1
sut.unit = .pound
sut.number = 10

//then
XCTAssertTrue(sut.isComplete)

// when
sut.quantityType = [.count]
sut.weight = 0
sut.unit = .notSelected
sut.number = 10

//then
XCTAssertTrue(sut.isComplete)

// when
sut.quantityType = [.weight]
sut.weight = 1
sut.unit = .kilograms
sut.number = 0

//then
XCTAssertTrue(sut.isComplete)
}

func testIsNotComplete() {
//given
let sut = CatchViewModel()

//then
XCTAssertFalse(sut.isComplete)

// when
sut.fish = "Some fish"
sut.weight = 1
sut.unit = .kilograms
sut.number = 1

// then
XCTAssertFalse(sut.isComplete, "QuantityType mandatory")

// when
sut.fish = ""
sut.weight = 1
sut.unit = .kilograms
sut.number = 1
sut.quantityType = [.weight, .count]

// then
XCTAssertFalse(sut.isComplete, "Fish type mandatory")
}

func testInitWithCatch() {
//given
Expand Down
34 changes: 33 additions & 1 deletion O-FISHTests/CrewMemberViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,39 @@ class CrewMemberViewModelTests: XCTestCase {
XCTAssertEqual(crew?.name, name)
XCTAssertEqual(crew?.license, license)
}


func testIsComplete() {
//given
let sut = CrewMemberViewModel()

// when
sut.name = "Name"
sut.license = "Licence number"

//then
XCTAssertTrue(sut.isComplete, "If name and licence is filled then crew should be complete")
}

func testIsNotComplete() {
//given
let sut = CrewMemberViewModel()

// when
sut.name = "Name"
sut.license = ""

//then
XCTAssertFalse(sut.isComplete, "Should not be complete if only name exists")

sut.name = ""
sut.license = "Licence"
XCTAssertFalse(sut.isComplete, "Should not be complete if only license exists")

sut.name = ""
sut.license = ""
XCTAssertFalse(sut.isComplete, "Should not be complete if no data")
}

func testSaveCrewNil() {
//given
let crewMember: CrewMember? = nil
Expand Down
47 changes: 47 additions & 0 deletions O-FISHTests/EMSViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,53 @@ class EMSViewModelTests: XCTestCase {
XCTAssertEqual(emsIn?.emsDescription, description)
XCTAssertEqual(emsIn?.registryNumber, registryNumber)
}

func testIsComplete() {
//given
let sut = EMSViewModel()

// when
sut.emsType = "Some type"
sut.registryNumber = "12345789"

//then
XCTAssertTrue(sut.isComplete, "If name and licence is filled then crew should be complete")

// when
sut.emsType = "Other"
sut.registryNumber = "12345789"
sut.emsDescription = "Some description"

//then
XCTAssertTrue(sut.isComplete, "For other type should be an additional description")
}

func testIsNotComplete() {
//given
let sut = EMSViewModel()

// when
sut.emsType = ""
sut.registryNumber = "12345789"

//then
XCTAssertFalse(sut.isComplete, "EMS type mandatory")

// when
sut.emsType = "Other"
sut.registryNumber = "12345789"
sut.emsDescription = ""

//then
XCTAssertFalse(sut.isComplete, "For Other type should be an additional description")

// when
sut.emsType = "Type"
sut.registryNumber = ""

//then
XCTAssertFalse(sut.isComplete, "Registry number mandatory")
}

func testSaveEMSNil() {
//given
Expand Down
13 changes: 13 additions & 0 deletions o-fish-ios/ViewModel/Report/CatchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class CatchViewModel: ObservableObject, Identifiable {
fish.isEmpty && quantityType.contains(.notSelected) && number == 0 && weight == 0 && unit == .notSelected
}

var isComplete: Bool {
var result = false

result = !fish.isEmpty
result = result && !(quantityType == [.notSelected])

result = result && !(quantityType.contains(.weight) && weight == 0)
result = result && !(quantityType.contains(.weight) && unit == .notSelected)
result = result && !(quantityType.contains(.count) && number == 0)

return result
}

convenience init(_ fishCatch: Catch?) {
self.init()
if let fishCatch = fishCatch {
Expand Down
4 changes: 4 additions & 0 deletions o-fish-ios/ViewModel/Report/CrewMemberViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class CrewMemberViewModel: ObservableObject, Identifiable {
name.isEmpty && license.isEmpty
}

var isComplete: Bool {
!name.isEmpty && !license.isEmpty
}

convenience init(_ crewMember: CrewMember?, isCaptain: Bool = false) {
self.init()
if let crewMember = crewMember {
Expand Down
6 changes: 6 additions & 0 deletions o-fish-ios/ViewModel/Report/EMSViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class EMSViewModel: ObservableObject, Identifiable {
emsType == "" && registryNumber.isEmpty
}

var isComplete: Bool {
!emsType.isEmpty
&& !registryNumber.isEmpty
&& !(emsType == "Other" ? emsDescription.isEmpty : false)
}

convenience init(_ eMS: EMS?) {
self.init()
if let eMS = eMS {
Expand Down
Loading

0 comments on commit fda6f6c

Please sign in to comment.