This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#105): added test cases for details Attribute component and cont…
…ainer
- Loading branch information
Andreas Gasser
committed
May 2, 2019
1 parent
e2dd84c
commit 01932a5
Showing
6 changed files
with
1,793 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { __testables__ } from '../Container'; | ||
import { getImage } from '../../../redux/images'; | ||
|
||
const { select, mapDispatchToProps, mapKeyToValue } = __testables__; | ||
|
||
describe('auth register container test suite', () => { | ||
const expectedInitialState = { | ||
image: undefined, | ||
labels: [], | ||
faces: [], | ||
selectedFace: null, | ||
selectedLabel: null, | ||
getImageRequest: undefined, | ||
}; | ||
|
||
const initialProps = { | ||
match: { | ||
params: { | ||
id: null, | ||
}, | ||
}, | ||
location: { | ||
search: '', | ||
}, | ||
}; | ||
|
||
it('should return container state', () => { | ||
const state = select({}, initialProps); | ||
expect(state).toEqual(expectedInitialState); | ||
|
||
expect(Object.keys(state)).toEqual([ | ||
'image', | ||
'labels', | ||
'faces', | ||
'selectedFace', | ||
'selectedLabel', | ||
'getImageRequest', | ||
]); | ||
}); | ||
|
||
it('should return redux actions', () => { | ||
expect(mapDispatchToProps).toEqual({ | ||
getImage, | ||
}); | ||
}); | ||
|
||
it('mapKeyToValue should return params', () => { | ||
const string = '?attr1=val1'; | ||
expect(mapKeyToValue(string)).toEqual({ | ||
attr1: 'val1', | ||
}); | ||
}); | ||
|
||
it('should select face based on face url attr', () => { | ||
const id = 'ae1f94b0-a090-4e09-aa70-2fdc23e74bcc'; | ||
const face = { | ||
id, | ||
name: 'test face', | ||
}; | ||
const url = `?face=${id}`; | ||
const expectedState = { | ||
...expectedInitialState, | ||
selectedFace: face, | ||
}; | ||
|
||
// check for valid face | ||
expect(select({ | ||
// set faces state | ||
faces: { | ||
byId: { | ||
[id]: face, | ||
}, | ||
}, | ||
}, { | ||
...initialProps, | ||
location: { | ||
search: url, | ||
}, | ||
})).toEqual(expectedState); | ||
|
||
// check for invalid face | ||
expect(select({ | ||
// set faces state | ||
faces: { | ||
byId: { | ||
'invalid-id': face, | ||
}, | ||
}, | ||
}, { | ||
...initialProps, | ||
location: { | ||
search: url, | ||
}, | ||
})).toEqual(expectedInitialState); | ||
}); | ||
|
||
it('should select label based on label url attr', () => { | ||
const id = 'ae1f94b0-a090-4e09-aa70-2fdc23e74baa'; | ||
const label = { | ||
id, | ||
name: 'test label', | ||
}; | ||
const url = `?label=${id}`; | ||
const expectedState = { | ||
...expectedInitialState, | ||
selectedLabel: label, | ||
}; | ||
|
||
// check for valid face | ||
expect(select({ | ||
// set faces state | ||
labels: { | ||
byId: { | ||
[id]: label, | ||
}, | ||
}, | ||
}, { | ||
...initialProps, | ||
location: { | ||
search: url, | ||
}, | ||
})).toEqual(expectedState); | ||
|
||
// check for invalid label | ||
expect(select({ | ||
// set label state | ||
labels: { | ||
byId: { | ||
'invalid-id': label, | ||
}, | ||
}, | ||
}, { | ||
...initialProps, | ||
location: { | ||
search: url, | ||
}, | ||
})).toEqual(expectedInitialState); | ||
}); | ||
}); |
Oops, something went wrong.