forked from homedepot/infinite-wish-board
-
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.
Merge branch 'master' into 98-design-updates
- Loading branch information
Showing
9 changed files
with
287 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,105 @@ | ||
import React, { Component } from 'react' | ||
import './styles.scss' | ||
import { getWishes } from '../services/WishDetailsService' | ||
import backgroundGif from '../assets/gifs/MAW_BG.gif' | ||
import rocketGif from '../assets/gifs/MAW_Rocket.gif' | ||
import toBeGif from '../assets/gifs/MAW_To_Be.gif' | ||
import toMeetGif from '../assets/gifs/MAW_To_Meet.gif' | ||
|
||
export default class GalaxyScreen extends Component { | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
currentGif: null, | ||
previousWishList: [] | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}, | ||
() => { | ||
setInterval(() => { | ||
this.handleCurrentGif() | ||
}, | ||
3000) | ||
}) | ||
} | ||
|
||
handleCurrentGif = async () => { | ||
const wishes = await getWishes() | ||
if (JSON.stringify(this.state.previousWishList) !== JSON.stringify(wishes)) { | ||
const difference = wishes.filter(wish => !this.state.previousWishList.some(prevWish => wish._id === prevWish._id)); | ||
|
||
// console.log(this.state.previousWishList) | ||
// console.log(difference) | ||
if (difference && difference.length > 0 && this.state.previousWishList.length > 0) { | ||
|
||
if (difference[0].type === 'go') { | ||
this.setState({ | ||
currentGif: rocketGif // 13 seconds | ||
}, () => { | ||
setTimeout(() => { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}) | ||
}, | ||
13000) | ||
}) | ||
} else if (difference[0].type === 'meet') { | ||
this.setState({ | ||
currentGif: toMeetGif // 11 seconds | ||
}, () => { | ||
setTimeout(() => { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}) | ||
}, | ||
11000) | ||
}) | ||
} else if (difference[0].type === 'be') { | ||
this.setState({ | ||
currentGif: toBeGif // 11 seconds | ||
}, () => { | ||
setTimeout(() => { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}) | ||
}, | ||
11000) | ||
}) | ||
} else { | ||
this.setState({ | ||
currentGif: rocketGif // 13 seconds | ||
}, () => { | ||
setTimeout(() => { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}) | ||
}, | ||
13000) | ||
}) | ||
} | ||
} else { | ||
this.setState({ | ||
currentGif: backgroundGif | ||
}) | ||
} | ||
|
||
this.setState({ | ||
previousWishList: wishes | ||
}) | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id="GalaxyScreen"> | ||
<img className='galaxy-image' src={this.state.currentGif} alt="loading..." /> | ||
</div> | ||
) | ||
} | ||
|
||
} |
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,155 @@ | ||
import React from 'react' | ||
import GalaxyScreen from './galaxyScreen' | ||
import { shallow } from 'enzyme' | ||
import { getWishes } from '../services/WishDetailsService' | ||
import rocketGif from '../assets/gifs/MAW_Rocket.gif' | ||
import toBeGif from '../assets/gifs/MAW_To_Be.gif' | ||
import toMeetGif from '../assets/gifs/MAW_To_Meet.gif' | ||
|
||
jest.mock('../services/WishDetailsService', () => ({ | ||
getWishes: jest.fn(() => { | ||
return ([ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
} | ||
]) | ||
}) | ||
})); | ||
|
||
describe('GalaxyScreen component', () => { | ||
|
||
const component = shallow( | ||
<GalaxyScreen /> | ||
) | ||
|
||
it('should render a GalaxyScreen component', () => { | ||
expect(component.length).toEqual(1) | ||
}) | ||
|
||
it('should render a galaxy image', () => { | ||
expect(component.find('.galaxy-image').length).toEqual(1) | ||
}) | ||
|
||
describe('When handleCurrentGif is called', () => { | ||
|
||
beforeEach(() => { | ||
component.setState({ | ||
previousWishList: [ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
} | ||
] | ||
}) | ||
}) | ||
|
||
it('should always show `rocket` GIF after receiving `go` wish type', async () => { | ||
const wishes = [ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
}, | ||
{ | ||
_id: '3', | ||
type: 'go' | ||
} | ||
] | ||
|
||
getWishes.mockImplementation(() => { | ||
return wishes | ||
}) | ||
|
||
await component.instance().handleCurrentGif() | ||
expect(component.state().currentGif).toEqual(rocketGif) | ||
expect(component.state().previousWishList).toEqual(wishes) | ||
}) | ||
|
||
it('should always show `to meet` GIF after receiving `meet` wish type', async () => { | ||
const wishes = [ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
}, | ||
{ | ||
_id: '3', | ||
type: 'meet' | ||
} | ||
] | ||
|
||
getWishes.mockImplementation(() => { | ||
return wishes | ||
}) | ||
|
||
await component.instance().handleCurrentGif() | ||
expect(component.state().currentGif).toEqual(toMeetGif) | ||
expect(component.state().previousWishList).toEqual(wishes) | ||
}) | ||
|
||
it('should always show `to be` GIF after receiving `be` wish type', async () => { | ||
const wishes = [ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
}, | ||
{ | ||
_id: '3', | ||
type: 'be' | ||
} | ||
] | ||
|
||
getWishes.mockImplementation(() => { | ||
return wishes | ||
}) | ||
|
||
await component.instance().handleCurrentGif() | ||
expect(component.state().currentGif).toEqual(toBeGif) | ||
expect(component.state().previousWishList).toEqual(wishes) | ||
}) | ||
|
||
it('should always show `rocket` GIF after receiving any unmatched wish type', async () => { | ||
const wishes = [ | ||
{ | ||
_id: '1', | ||
type: 'go' | ||
}, | ||
{ | ||
_id: '2', | ||
type: 'be' | ||
}, | ||
{ | ||
_id: '3', | ||
type: 'something' | ||
} | ||
] | ||
|
||
getWishes.mockImplementation(() => { | ||
return wishes | ||
}) | ||
|
||
await component.instance().handleCurrentGif() | ||
expect(component.state().currentGif).toEqual(rocketGif) | ||
expect(component.state().previousWishList).toEqual(wishes) | ||
}) | ||
}) | ||
}) |
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,16 @@ | ||
@import "../styles/colors"; | ||
|
||
#GalaxyScreen { | ||
position: absolute; | ||
height: 100%; | ||
width: 100%; | ||
background-color: $light-blue; | ||
color: $dark-blue; | ||
font-family: 'Arial Rounded MT Bold', sans-serif; | ||
box-sizing: border-box; | ||
|
||
.galaxy-image { | ||
height: 100vh; | ||
width: 100vw; | ||
} | ||
} |