This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hotels: Fix relay/unused-fields in HotelDetailScreen
Refactor countBookingPrice function into HotelDetailScreen since it is not used elsewhere anymore
- Loading branch information
1 parent
e36beb4
commit fecf7bb
Showing
5 changed files
with
148 additions
and
136 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
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
102 changes: 102 additions & 0 deletions
102
app/hotels/src/singleHotel/__tests__/HotelDetailScreen.test.js
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,102 @@ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import { HotelDetailScreen } from '../HotelDetailScreen'; | ||
|
||
const $fragmentRefs: any = null; | ||
const availableRooms = [ | ||
{ | ||
$fragmentRefs, | ||
id: 'aaa', | ||
incrementalPrice: [ | ||
{ | ||
amount: 500, | ||
currency: 'EUR', | ||
}, | ||
{ | ||
amount: 1000, | ||
currency: 'EUR', | ||
}, | ||
], | ||
}, | ||
{ | ||
$fragmentRefs, | ||
id: 'bbb', | ||
incrementalPrice: [ | ||
{ | ||
amount: 333, | ||
currency: 'EUR', | ||
}, | ||
{ | ||
amount: 666, | ||
currency: 'EUR', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const getComponent = (availableRooms, selected) => { | ||
// $FlowExpectedError: Passing just props needed to perform test | ||
return new HotelDetailScreen({ | ||
availableHotel: { | ||
availableRooms, | ||
}, | ||
selected, | ||
}); | ||
}; | ||
|
||
describe('countBookingPrice', () => { | ||
it('returns null when availableRooms are not provided', () => { | ||
const NullComponent = getComponent(null, { aaa: 1 }); | ||
|
||
const UndefinedComponent = getComponent(null, { aaa: 1 }); | ||
|
||
expect(NullComponent.countBookingPrice()).toBe(null); | ||
expect(UndefinedComponent.countBookingPrice()).toBe(null); | ||
}); | ||
|
||
it('returns null when no room is selected', () => { | ||
const ComponentA = getComponent(availableRooms, {}); | ||
const ComponentB = getComponent(availableRooms, { aaa: 0, bbb: 0 }); | ||
|
||
expect(ComponentA.countBookingPrice()).toBe(null); | ||
expect(ComponentB.countBookingPrice()).toBe(null); | ||
}); | ||
|
||
it('returns sum of selected rooms', () => { | ||
const Component = getComponent(availableRooms, { aaa: 2, bbb: 1 }); | ||
|
||
expect(Component.countBookingPrice()).toEqual({ | ||
amount: 1333, | ||
currency: 'EUR', | ||
}); | ||
}); | ||
|
||
it('takes a currency from the first selected room', () => { | ||
const czechRooms = [ | ||
{ | ||
$fragmentRefs, | ||
id: 'aaa', | ||
incrementalPrice: [], | ||
}, | ||
{ | ||
$fragmentRefs, | ||
id: 'bbb', | ||
incrementalPrice: [ | ||
{ | ||
amount: 123, | ||
currency: 'CZK', | ||
}, | ||
], | ||
}, | ||
]; | ||
const Component = getComponent(czechRooms, { bbb: 1 }); | ||
|
||
expect(Component.countBookingPrice()).toEqual({ | ||
amount: 123, | ||
currency: 'CZK', | ||
}); | ||
}); | ||
}); |
76 changes: 0 additions & 76 deletions
76
app/hotels/src/singleHotel/bookNow/__tests__/countBookingPrice.test.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.