-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cabin): add tests for Cabin classes
- Loading branch information
1 parent
09e263c
commit 90463d3
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:cabin_booking/model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('CabinElements', () { | ||
group('.from()', () { | ||
test('should create a new CabinElements from a JSON object', () { | ||
const rawCabinElements = { | ||
'p': [ | ||
{'b': 'Yamaha', 'm': 'C5', 'ie': false}, | ||
], | ||
'l': 2, | ||
'c': 0, | ||
't': 1, | ||
}; | ||
const pianos = [Piano(brand: 'Yamaha', model: 'C5')]; | ||
final cabinElements = CabinElements.from(rawCabinElements); | ||
expect( | ||
cabinElements, | ||
CabinElements(pianos: pianos, lecterns: 2, tables: 1), | ||
); | ||
}); | ||
}); | ||
|
||
group('.toJson()', () { | ||
test( | ||
'should return a JSON object representation of this CabinElements', | ||
() { | ||
final cabinElements = CabinElements( | ||
pianos: const [Piano(brand: 'Yamaha', model: 'C5')], | ||
lecterns: 2, | ||
tables: 1, | ||
); | ||
const rawCabinElements = { | ||
'p': [ | ||
{'b': 'Yamaha', 'm': 'C5', 'ie': false}, | ||
], | ||
'l': 2, | ||
'c': 0, | ||
't': 1, | ||
}; | ||
expect(cabinElements.toJson(), rawCabinElements); | ||
expect(CabinElements.from(cabinElements.toJson()), cabinElements); | ||
}, | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:cabin_booking/model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Cabin', () { | ||
group('.from()', () { | ||
test('should create a new Cabin from a JSON object', () { | ||
const rawCabin = { | ||
'id': 'cabin-id', | ||
'cdt': '1969-07-20T20:18:04.000Z', | ||
'mdt': '1969-07-20T20:18:04.000Z', | ||
'mc': 1, | ||
'n': 1, | ||
'e': { | ||
'p': [ | ||
{'b': 'Yamaha', 'm': 'C5', 'ie': false}, | ||
], | ||
'l': 2, | ||
'c': 0, | ||
't': 1, | ||
}, | ||
'b': <Map<String, dynamic>>[], | ||
'rb': <Map<String, dynamic>>[], | ||
}; | ||
const pianos = [Piano(brand: 'Yamaha', model: 'C5')]; | ||
final cabin = Cabin.from(rawCabin); | ||
expect( | ||
cabin, | ||
Cabin( | ||
id: 'cabin-id', | ||
number: 1, | ||
elements: CabinElements( | ||
pianos: pianos, | ||
lecterns: 2, | ||
tables: 1, | ||
), | ||
bookings: {}, | ||
recurringBookings: {}, | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
group('.toJson()', () { | ||
test( | ||
'should return a JSON object representation of this Cabin', | ||
() { | ||
final rawCabin = { | ||
'id': 'cabin-id', | ||
'cdt': '1969-07-20T20:18:04.000Z', | ||
'mdt': '1969-07-20T20:18:04.000Z', | ||
'mc': 1, | ||
'n': 1, | ||
'e': { | ||
'p': [ | ||
{'b': 'Yamaha', 'm': 'C5', 'ie': false}, | ||
], | ||
'l': 2, | ||
'c': 0, | ||
't': 1, | ||
}, | ||
'b': <Map<String, dynamic>>[], | ||
'rb': <Map<String, dynamic>>[], | ||
}; | ||
expect(Cabin.from(rawCabin).toJson(), rawCabin); | ||
}, | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:cabin_booking/model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Piano', () { | ||
group('.from()', () { | ||
test('should create a new Piano from a JSON object', () { | ||
const rawPiano = { | ||
'b': 'Yamaha', | ||
'm': 'C5', | ||
'ie': false, | ||
}; | ||
final piano = Piano.from(rawPiano); | ||
expect(piano, const Piano(brand: 'Yamaha', model: 'C5')); | ||
}); | ||
}); | ||
|
||
group('.toJson()', () { | ||
test('should return a JSON object representation of this Piano', () { | ||
const piano = Piano(brand: 'Yamaha', model: 'C5'); | ||
const rawPiano = { | ||
'b': 'Yamaha', | ||
'm': 'C5', | ||
'ie': false, | ||
}; | ||
expect(piano.toJson(), rawPiano); | ||
expect(Piano.from(piano.toJson()), piano); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:cabin_booking/model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('TokenizedCabin', () { | ||
group('.fromTokens()', () { | ||
test('should create a new TokenizedCabin from a JSON object', () { | ||
const cabinTokens = { | ||
'cabinNumber': '1', | ||
}; | ||
final tokenizedCabin = TokenizedCabin.fromTokens(cabinTokens); | ||
expect(tokenizedCabin, const TokenizedCabin(cabinNumber: '1')); | ||
}); | ||
}); | ||
|
||
group('.toCabin()', () { | ||
test('should create a new Cabin from this TokenizedCabin', () { | ||
const tokenizedCabin = TokenizedCabin(cabinNumber: '1'); | ||
final cabin = Cabin(number: 1); | ||
expect(tokenizedCabin.toCabin().number, cabin.number); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import 'cabin/cabin_elements_test.dart' as cabin_elements_test; | ||
import 'cabin/cabin_test.dart' as cabin_test; | ||
import 'cabin/piano_test.dart' as piano_test; | ||
import 'cabin/tokenized_cabin_test.dart' as tokenized_cabin_test; | ||
import 'date/date_range_test.dart' as date_range_test; | ||
import 'date/date_ranger_test.dart' as date_ranger_test; | ||
|
||
void main() { | ||
cabin_elements_test.main(); | ||
cabin_test.main(); | ||
tokenized_cabin_test.main(); | ||
piano_test.main(); | ||
date_range_test.main(); | ||
date_ranger_test.main(); | ||
} |