Skip to content

Commit 1c50819

Browse files
committed
Move gig navigation inside Day component
1 parent d1df17c commit 1c50819

File tree

7 files changed

+59
-35
lines changed

7 files changed

+59
-35
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import PageObject from './PageObject'
2+
3+
export default class DayListPageObject extends PageObject {
4+
constructor(wrapper) {
5+
super(wrapper)
6+
this.wrapper = wrapper
7+
}
8+
9+
clickFirstGig() {
10+
this.wrapper.findAll('.q-item').at(0).trigger('click')
11+
}
12+
13+
clickSecondGig() {
14+
this.wrapper.findAll('.q-item').at(1).trigger('click')
15+
}
16+
}

src/app/__page_objects__/DaysPageObject.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ export default class DayListPageObject extends PageObject {
2121
clickSecondGig() {
2222
this.wrapper.findAll('.q-item').at(1).trigger('click')
2323
}
24-
25-
setRouterSpy(routerSpy) {
26-
this.wrapper.vm.mosicaRouter = routerSpy
27-
}
2824
}

src/app/__page_objects__/PageObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ export default class PageObject {
2727
matchSnapshot() {
2828
expect(this.wrapper.html()).toMatchSnapshot()
2929
}
30+
31+
setRouterSpy(routerSpy) {
32+
this.wrapper.vm.mosicaRouter = routerSpy
33+
}
3034
}

src/app/pages/Days/Day.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
<q-list-header>{{day.day}}</q-list-header>
55

66
<div v-for="gig in day.gigs">
7-
<Gig :gig ="gig" :onClick="onClick"/>
7+
<Gig :gig ="gig" :onClick="goTo"/>
88
</div>
99
</div>
1010
</q-list>
1111
</template>
1212

1313
<script>
14+
import { MosicaRouter } from '../../services/MosicaRouter'
15+
1416
export default {
15-
props: { day: Object, isLoading: Boolean, onClick: Function }
17+
props: {day: Object, isLoading: Boolean},
18+
created() {
19+
this.mosicaRouter = new MosicaRouter(this.$router)
20+
},
21+
methods: {
22+
goTo(gig) {
23+
this.mosicaRouter.navigateToGig(gig.id)
24+
}
25+
}
1626
}
1727
</script>
1828

src/app/pages/Days/Days.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
<div class="full-width">
33
<LoadSpinner :isLoading="isLoading"/>
44
<div v-for="day in gigsByDay" v-if="!isLoading">
5-
<Day :day="day" :onClick="goTo"/>
5+
<Day :day="day"/>
66
</div>
77
</div>
88
</template>
99

1010
<script>
1111
import { mapState, mapActions } from 'vuex'
12-
import { MosicaRouter } from '../../services/MosicaRouter'
1312
import { gigService } from '../../services/mosica-instances'
1413
1514
export default {
@@ -33,13 +32,9 @@
3332
await this.retrieve_days()
3433
this.gigsByDay = this.days
3534
this.isLoading = false
36-
this.mosicaRouter = new MosicaRouter(this.$router)
3735
},
3836
methods: {
39-
...mapActions(['retrieve_days']),
40-
goTo(gig) {
41-
this.mosicaRouter.navigateToGig(gig.id)
42-
}
37+
...mapActions(['retrieve_days'])
4338
},
4439
computed: {
4540
...mapState(['days'])

src/app/pages/Days/__test__/Day.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Day from '@/app/pages/Days/Day.vue'
22
import PageObject from '../../../__page_objects__/PageObject'
33
import { fakeGigsByDay } from '../../../services/__mocks__/gigs-sample'
44
import { Wrap } from '../../../../../test/helpers'
5+
import DayListPageObject from '../../../__page_objects__/DayPageObject';
56

67
const FIRST_DAY = fakeGigsByDay[0]
78

@@ -11,8 +12,9 @@ describe('Day', () => {
1112
beforeEach(async () => {
1213
wrapper = Wrap(Day)
1314
.withProps({ day: FIRST_DAY, isLoading: false, onClick: jest.fn })
15+
.withRouter(jest.fn())
1416
.mount()
15-
page = new PageObject(wrapper)
17+
page = new DayListPageObject(wrapper)
1618
await page.updateAsync()
1719
})
1820

@@ -26,4 +28,26 @@ describe('Day', () => {
2628
it('renders gig', async() => {
2729
page.contains(FIRST_DAY.day)
2830
})
31+
32+
33+
describe('When clicking buttons', () => {
34+
35+
let navigateToGigSpy
36+
beforeEach(async () => {
37+
navigateToGigSpy = jest.fn()
38+
page.setRouterSpy({ navigateToGig: navigateToGigSpy })
39+
})
40+
41+
it('navigates to first gig detail', async () => {
42+
const FIRST_GIG = FIRST_DAY.gigs[0]
43+
page.clickFirstGig()
44+
expect(navigateToGigSpy).toHaveBeenCalledWith(FIRST_GIG.id)
45+
})
46+
47+
it('navigates to second gig detail', async () => {
48+
const SECOND_GIG = FIRST_DAY.gigs[1]
49+
page.clickSecondGig()
50+
expect(navigateToGigSpy).toHaveBeenCalledWith(SECOND_GIG.id)
51+
})
52+
})
2953
})

src/app/pages/__test__/Days.spec.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@ describe('Days', () => {
2525
FIRST_DAY_GIG_TEXTS.map((text) => page.contains(text))
2626
})
2727

28-
describe('When clicking buttons', () => {
29-
30-
let navigateToGigSpy
31-
beforeEach(async () => {
32-
navigateToGigSpy = jest.fn()
33-
page.setRouterSpy({ navigateToGig: navigateToGigSpy })
34-
})
35-
36-
it('navigates to first gig detail', async () => {
37-
const FIRST_GIG = fakeGigsByDay[0].gigs[0]
38-
page.clickFirstGig()
39-
expect(navigateToGigSpy).toHaveBeenCalledWith(FIRST_GIG.id)
40-
})
41-
42-
it('navigates to second gig detail', async () => {
43-
const SECOND_GIG = fakeGigsByDay[0].gigs[1]
44-
page.clickSecondGig()
45-
expect(navigateToGigSpy).toHaveBeenCalledWith(SECOND_GIG.id)
46-
})
47-
})
48-
4928
/* Different examples of more accurate tests that need
5029
to explicitly run over the DOM structure
5130
*/

0 commit comments

Comments
 (0)