Skip to content

Commit

Permalink
refactor: use global EventBus in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koebi authored and TheGreatRefrigerator committed Jan 30, 2023
1 parent ea161b0 commit ac3205f
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/App.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import I18nBuilder from '@/i18n/i18n-builder'
import router from '@/router'
import AppRootComponent from '@/App.vue'
import Footer from '@/fragments/footer/Footer'
// TODO: implement global event bus as standalone module
// import EventBus from '@/common/event-bus'
import {EventBus} from '@/common/event-bus'

describe('<App />', () => {
beforeEach(() => {
// // TODO: implement global event bus as standalone module
// cy.spy(EventBus, '$on').as('eventBusRegisterSpy')
// cy.spy(EventBus, '$emit').as('eventBusEmitSpy')
cy.spy(EventBus, '$on').as('eventBusRegisterSpy')
cy.spy(EventBus, '$emit').as('eventBusEmitSpy')
cy.intercept('GET', 'https://*.tile.openstreetmap.org/*/*/*.png', {fixture: 'map-pin.jpg'})
new AppLoader().fetchApiInitialData()
cy.stub(Footer.computed, 'appVersion', () => {
Expand All @@ -31,24 +29,23 @@ describe('<App />', () => {
cy.get('.progress-linear').should('have.class', 'progress-linear-disabled')
})

it.skip('should toggle progress bar correctly', () => {
// // TODO: implement global event bus as standalone module
// cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'showLoading')
// cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'titleChanged')
// cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'appLoaded')
// cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'titleChanged')
//
// // check progress bar hidden after initial page load and set loading true
// cy.get('.progress-linear').should('have.class', 'progress-linear-disabled').then(() => {
// EventBus.$emit('showLoading', true)
// })
// cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'showLoading', true)
//
// // check bar is enabled and set loading false again
// cy.get('.progress-linear').should('not.have.class', 'progress-linear-disabled').then(() => {
// EventBus.$emit('showLoading', false)
// })
// cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'showLoading', false)
// cy.get('.progress-linear').should('have.class', 'progress-linear-disabled')
it('should toggle progress bar correctly', () => {
cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'showLoading')
cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'titleChanged')
cy.get('@eventBusRegisterSpy').should('have.been.calledWith', 'appLoaded')
cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'titleChanged')

// check progress bar hidden after initial page load and set loading true
cy.get('.progress-linear').should('have.class', 'progress-linear-disabled').then(() => {
EventBus.$emit('showLoading', true)
})
cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'showLoading', true)

// check bar is enabled and set loading false again
cy.get('.progress-linear').should('not.have.class', 'progress-linear-disabled').then(() => {
EventBus.$emit('showLoading', false)
})
cy.get('@eventBusEmitSpy').should('have.been.calledWith', 'showLoading', false)
cy.get('.progress-linear').should('have.class', 'progress-linear-disabled')
})
})

0 comments on commit ac3205f

Please sign in to comment.