2024-04-30 10:30:00 +02:00
|
|
|
import NarratorCard from '@/components/cards/NarratorCard.vue'
|
2024-04-15 23:00:35 +02:00
|
|
|
|
|
|
|
describe('<NarratorCard />', () => {
|
|
|
|
const narrator = {
|
|
|
|
name: 'John Doe',
|
|
|
|
numBooks: 5
|
|
|
|
}
|
|
|
|
const propsData = {
|
2024-06-03 08:04:03 +02:00
|
|
|
narrator
|
2024-04-15 23:00:35 +02:00
|
|
|
}
|
|
|
|
const mocks = {
|
|
|
|
$store: {
|
|
|
|
getters: {
|
2024-06-03 08:04:03 +02:00
|
|
|
'user/getUserCanUpdate': true,
|
|
|
|
'user/getSizeMultiplier': 1
|
2024-04-15 23:00:35 +02:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
libraries: {
|
|
|
|
currentLibraryId: 'library-123'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$encode: (value) => value
|
|
|
|
}
|
|
|
|
|
|
|
|
it('renders the component', () => {
|
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
// see: https://on.cypress.io/mounting-vue
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the narrator name correctly', () => {
|
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&name').should('have.text', 'John Doe')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the number of books correctly', () => {
|
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&numBooks').should('have.text', '5 Books')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders 1 book correctly', () => {
|
2024-06-03 08:04:03 +02:00
|
|
|
let propsData = { narrator: { name: 'John Doe', numBooks: 1 }, width: 200, height: 150 }
|
2024-04-15 23:00:35 +02:00
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
|
|
|
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&numBooks').should('have.text', '1 Book')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the default name and num-books when narrator is not provided', () => {
|
2024-06-03 08:04:03 +02:00
|
|
|
let propsData = { width: 200, height: 150 }
|
2024-04-15 23:00:35 +02:00
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&name').should('have.text', '')
|
|
|
|
cy.get('&numBooks').should('have.text', '0 Books')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('has the correct width and height', () => {
|
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
2024-06-03 08:04:03 +02:00
|
|
|
cy.get('&card').should('have.css', 'width', '150px')
|
|
|
|
cy.get('&card').should('have.css', 'height', '100px')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('has the correct width and height when not provided', () => {
|
2024-06-03 08:04:03 +02:00
|
|
|
let propsData = { narrator }
|
2024-04-15 23:00:35 +02:00
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
2024-04-29 07:30:14 +02:00
|
|
|
cy.get('&card').should('have.css', 'width', '150px')
|
|
|
|
cy.get('&card').should('have.css', 'height', '100px')
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
|
|
|
|
2024-04-29 23:30:30 +02:00
|
|
|
it('has the correct font sizes', () => {
|
2024-04-15 23:00:35 +02:00
|
|
|
let mountOptions = { propsData, mocks }
|
|
|
|
cy.mount(NarratorCard, mountOptions)
|
2024-06-03 08:04:03 +02:00
|
|
|
const defaultFontSize = 16
|
|
|
|
cy.get('&name').should('have.css', 'font-size', `${0.75 * defaultFontSize}px`)
|
|
|
|
cy.get('&numBooks').should('have.css', 'font-size', `${0.65 * defaultFontSize}px`)
|
2024-04-15 23:00:35 +02:00
|
|
|
})
|
2024-06-03 08:04:03 +02:00
|
|
|
})
|