2024-04-15 23:00:35 +02:00
|
|
|
// Import the necessary dependencies
|
2024-04-30 10:30:00 +02:00
|
|
|
import AuthorCard from '@/components/cards/AuthorCard.vue'
|
|
|
|
import AuthorImage from '@/components/covers/AuthorImage.vue'
|
|
|
|
import Tooltip from '@/components/ui/Tooltip.vue'
|
|
|
|
import LoadingSpinner from '@/components/widgets/LoadingSpinner.vue'
|
2024-04-15 23:00:35 +02:00
|
|
|
|
|
|
|
describe('AuthorCard', () => {
|
|
|
|
const author = {
|
|
|
|
id: 1,
|
|
|
|
name: 'John Doe',
|
|
|
|
numBooks: 5
|
|
|
|
}
|
|
|
|
|
|
|
|
const propsData = {
|
|
|
|
author,
|
|
|
|
width: 192 * 0.8,
|
|
|
|
height: 192,
|
|
|
|
sizeMultiplier: 1,
|
|
|
|
nameBelow: false
|
|
|
|
}
|
|
|
|
|
|
|
|
const mocks = {
|
|
|
|
$strings: {
|
|
|
|
LabelBooks: 'Books',
|
|
|
|
ButtonQuickMatch: 'Quick Match'
|
|
|
|
},
|
2024-04-29 23:30:30 +02:00
|
|
|
$store: {
|
2024-04-15 23:00:35 +02:00
|
|
|
getters: {
|
|
|
|
'user/getUserCanUpdate': true,
|
2024-04-29 23:30:30 +02:00
|
|
|
'libraries/getLibraryProvider': () => 'audible.us'
|
2024-04-15 23:00:35 +02:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
libraries: {
|
|
|
|
currentLibraryId: 'library-123'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$eventBus: {
|
2024-04-29 23:30:30 +02:00
|
|
|
$on: () => { },
|
|
|
|
$off: () => { },
|
2024-04-15 23:00:35 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const stubs = {
|
|
|
|
'covers-author-image': AuthorImage,
|
|
|
|
'ui-tooltip': Tooltip,
|
|
|
|
'widgets-loading-spinner': LoadingSpinner
|
|
|
|
}
|
|
|
|
|
|
|
|
const mountOptions = { propsData, mocks, stubs }
|
|
|
|
|
|
|
|
it('renders the component', () => {
|
|
|
|
cy.mount(AuthorCard, mountOptions)
|
2024-04-29 23:30:30 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&textInline').should('be.visible')
|
|
|
|
cy.get('&match').should('be.hidden')
|
|
|
|
cy.get('&edit').should('be.hidden')
|
|
|
|
cy.get('&nameBelow').should('be.hidden')
|
|
|
|
cy.get('&card').should(($el) => {
|
2024-04-15 23:00:35 +02:00
|
|
|
const width = $el.width()
|
|
|
|
const height = $el.height()
|
|
|
|
expect(width).to.be.closeTo(propsData.width, 0.01)
|
|
|
|
expect(height).to.be.closeTo(propsData.height, 0.01)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the component with the author name below', () => {
|
|
|
|
const updatedPropsData = { ...propsData, nameBelow: true }
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, { ...mountOptions, propsData: updatedPropsData })
|
2024-04-15 23:00:35 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&textInline').should('be.hidden')
|
|
|
|
cy.get('&match').should('be.hidden')
|
|
|
|
cy.get('&edit').should('be.hidden')
|
2024-04-15 23:00:35 +02:00
|
|
|
let nameBelowHeight
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&nameBelow')
|
2024-04-29 23:30:30 +02:00
|
|
|
.should('be.visible')
|
|
|
|
.and('have.text', 'John Doe')
|
|
|
|
.and(($el) => {
|
|
|
|
const height = $el.height()
|
|
|
|
const width = $el.width()
|
|
|
|
const sizeMultiplier = propsData.sizeMultiplier
|
|
|
|
const defaultFontSize = 16
|
|
|
|
const defaultLineHeight = 1.5
|
|
|
|
const fontSizeMultiplier = 0.75
|
|
|
|
const px2 = 16
|
|
|
|
expect(height).to.be.closeTo(defaultFontSize * fontSizeMultiplier * sizeMultiplier * defaultLineHeight, 0.01)
|
|
|
|
nameBelowHeight = height
|
|
|
|
expect(width).to.be.closeTo(propsData.width - px2, 0.01)
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').should(($el) => {
|
2024-04-15 23:00:35 +02:00
|
|
|
const width = $el.width()
|
|
|
|
const height = $el.height()
|
|
|
|
const py1 = 8
|
|
|
|
expect(width).to.be.closeTo(propsData.width, 0.01)
|
|
|
|
expect(height).to.be.closeTo(propsData.height + nameBelowHeight + py1, 0.01)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders quick-match and edit buttons on mouse hover', () => {
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, mountOptions)
|
2024-04-15 23:00:35 +02:00
|
|
|
|
|
|
|
// before mouseover
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&match').should('be.hidden')
|
|
|
|
cy.get('&edit').should('be.hidden')
|
2024-04-15 23:00:35 +02:00
|
|
|
// after mouseover
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').trigger('mouseover')
|
|
|
|
cy.get('&match').should('be.visible')
|
|
|
|
cy.get('&edit').should('be.visible')
|
2024-04-15 23:00:35 +02:00
|
|
|
// after mouseleave
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').trigger('mouseleave')
|
|
|
|
cy.get('&match').should('be.hidden')
|
|
|
|
cy.get('&edit').should('be.hidden')
|
2024-04-15 23:00:35 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the component with spinner while searching', () => {
|
|
|
|
const data = () => { return { searching: true, isHovering: false } }
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, { ...mountOptions, data })
|
2024-04-15 23:00:35 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&textInline').should('be.hidden')
|
|
|
|
cy.get('&match').should('be.hidden')
|
|
|
|
cy.get('&edit').should('be.hidden')
|
|
|
|
cy.get('&spinner').should('be.visible')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
2024-04-29 23:30:30 +02:00
|
|
|
it('toasts after quick match with no updates', () => {
|
2024-04-15 23:00:35 +02:00
|
|
|
const updatedMocks = {
|
|
|
|
...mocks,
|
|
|
|
$axios: {
|
|
|
|
$post: cy.stub().resolves({ updated: false, author: { name: 'John Doe' } })
|
|
|
|
},
|
|
|
|
$toast: {
|
|
|
|
success: cy.spy().as('success'),
|
|
|
|
error: cy.spy().as('error'),
|
|
|
|
info: cy.spy().as('info')
|
2024-04-29 23:30:30 +02:00
|
|
|
}
|
2024-04-15 23:00:35 +02:00
|
|
|
}
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, { ...mountOptions, mocks: updatedMocks })
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').trigger('mouseover')
|
|
|
|
cy.get('&match').click()
|
2024-04-15 23:00:35 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&spinner').should('be.hidden')
|
2024-04-15 23:00:35 +02:00
|
|
|
cy.get('@success').should('not.have.been.called')
|
|
|
|
cy.get('@error').should('not.have.been.called')
|
|
|
|
cy.get('@info').should('have.been.called')
|
|
|
|
})
|
|
|
|
|
2024-04-29 23:30:30 +02:00
|
|
|
it('toasts after quick match with updates and no image', () => {
|
2024-04-15 23:00:35 +02:00
|
|
|
const updatedMocks = {
|
|
|
|
...mocks,
|
|
|
|
$axios: {
|
|
|
|
$post: cy.stub().resolves({ updated: true, author: { name: 'John Doe' } })
|
|
|
|
},
|
|
|
|
$toast: {
|
2024-04-17 22:22:21 +02:00
|
|
|
success: cy.stub().as('success'),
|
2024-04-15 23:00:35 +02:00
|
|
|
error: cy.spy().as('error'),
|
|
|
|
info: cy.spy().as('info')
|
2024-04-29 23:30:30 +02:00
|
|
|
}
|
2024-04-15 23:00:35 +02:00
|
|
|
}
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, { ...mountOptions, mocks: updatedMocks })
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').trigger('mouseover')
|
|
|
|
cy.get('&match').click()
|
2024-04-15 23:00:35 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&spinner').should('be.hidden')
|
2024-04-17 22:22:21 +02:00
|
|
|
cy.get('@success').should('have.been.calledOnceWithExactly', 'Author John Doe was updated (no image found)')
|
2024-04-15 23:00:35 +02:00
|
|
|
cy.get('@error').should('not.have.been.called')
|
|
|
|
cy.get('@info').should('not.have.been.called')
|
|
|
|
})
|
|
|
|
|
2024-04-29 23:30:30 +02:00
|
|
|
it('toasts after quick match with updates including image', () => {
|
2024-04-15 23:00:35 +02:00
|
|
|
const updatedMocks = {
|
|
|
|
...mocks,
|
|
|
|
$axios: {
|
|
|
|
$post: cy.stub().resolves({ updated: true, author: { name: 'John Doe', imagePath: "path/to/image" } })
|
|
|
|
},
|
|
|
|
$toast: {
|
2024-04-17 22:22:21 +02:00
|
|
|
success: cy.stub().as('success'),
|
2024-04-15 23:00:35 +02:00
|
|
|
error: cy.spy().as('error'),
|
|
|
|
info: cy.spy().as('info')
|
2024-04-29 23:30:30 +02:00
|
|
|
}
|
2024-04-15 23:00:35 +02:00
|
|
|
}
|
2024-04-29 23:30:30 +02:00
|
|
|
cy.mount(AuthorCard, { ...mountOptions, mocks: updatedMocks })
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').trigger('mouseover')
|
|
|
|
cy.get('&match').click()
|
2024-04-15 23:00:35 +02:00
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&spinner').should('be.hidden')
|
2024-04-17 22:22:21 +02:00
|
|
|
cy.get('@success').should('have.been.calledOnceWithExactly', 'Author John Doe was updated')
|
2024-04-15 23:00:35 +02:00
|
|
|
cy.get('@error').should('not.have.been.called')
|
|
|
|
cy.get('@info').should('not.have.been.called')
|
|
|
|
})
|
|
|
|
})
|