Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/button tests #77

Open
wants to merge 4 commits into
base: proto
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/UI/SwapButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<slot></slot>
</span>

<span v-if="tooltip" v-tooltip="computedTooltipParams" class="swap-button__tooltip"></span>
<span
v-if="tooltip"
v-tooltip="computedTooltipParams"
data-testid="button-tooltip"
class="swap-button__tooltip"
></span>
</button>
</template>

Expand Down
63 changes: 63 additions & 0 deletions tests/unit/components/UI/SwapButton.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SwapButton from '@/components/UI/SwapButton.vue'
import { shallowMount } from '@vue/test-utils'

const slotText = 'slot test'

describe('Swap button', () => {
let wrapper

const createComponent = ({ propsData = {}, provide = {}, listeners = {} } = {}) => {
wrapper = shallowMount(SwapButton, {
propsData: {
...propsData
},
provide: {
mediaQueries: { mobile: false },
...provide
},
slots: {
default: slotText
},
listeners
})
}

it('renders slot', () => {
createComponent()

expect(wrapper.text()).toBe(slotText)
})

it('renders tooltip', () => {
createComponent({ propsData: { tooltip: 'Tooltip' } })

const buttonTooltip = wrapper.find('[data-testid="button-tooltip"]')

expect(buttonTooltip.exists()).toBe(true)
})

it.each`
propName
${'round'}
${'text'}
${'disabled'}
`('has class for styles $propName', ({ propName }) => {
createComponent({ propsData: { [propName]: true } })

expect(wrapper.element.classList.value.includes(propName)).toBe(true)
})

it.each`
eventName
${'click'}
${'focus'}
${'blur'}
`('emits $eventName event', async ({ eventName }) => {
const handler = jest.fn()
createComponent({ listeners: { [eventName]: handler } })

await wrapper.find('button').trigger(eventName)

expect(handler).toHaveBeenCalled()
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно было обработчики событий добавить, хотя бы пару основных: focus, blur, click и т.п.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для проверки что есть v-on="$listeners"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ага, ну и это кнопка) странно, что у неё нет тестов обработчиков :)