Skip to content

Commit

Permalink
test: add slot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest committed May 2, 2021
1 parent 03de974 commit 386a643
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cypress/integration/slots/dropdown-item/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue
const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref('i')
const options = ref(['i'])
return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
>
<template #dropdown-item="{ option }">
<span>{{ option.toUpperCase() }}</span>
</template>
</vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions cypress/integration/slots/dropdown-item/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="cypress" />
import path from 'path'

context('dropdown-item', () => {
it('should expose slot', () => {
cy.visit(path.join(__dirname, 'index.html'))
cy.get('.vue-select').click()

cy.get('.vue-dropdown-item').should('have.text', 'I')
})
})
56 changes: 56 additions & 0 deletions cypress/integration/slots/loading/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue
const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref('i')
const options = ref(['i'])
const loading = ref(false)
const handleSearchInput = async () => {
loading.value = true
await new Promise(resolve => setTimeout(resolve, 100))
loading.value = false
}
return {
selectedOptions,
options,
loading,
handleSearchInput,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
searchable
@search:input="handleSearchInput"
:loading="loading"
>
<template #loading>
<span id="custom-loading">Loading</span>
</template>
</vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions cypress/integration/slots/loading/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="cypress" />
import path from 'path'

context('loading', () => {
it('should expose slot', () => {
cy.visit(path.join(__dirname, 'index.html'))

cy.get('#custom-loading').should('not.exist')

cy.get('input').type('i')
cy.get('#custom-loading').should('exist')

cy.wait(100).then(() => {
cy.get('#custom-loading').should('not.exist')
})
})
})
47 changes: 47 additions & 0 deletions cypress/integration/slots/tag/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue
const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref(['i'])
const options = ref(['i'])
return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
multiple
taggable
>
<template #tag="{ option }">
<span>{{ option.toUpperCase() }}</span>
</template>
</vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions cypress/integration/slots/tag/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="cypress" />
import path from 'path'

context('tag', () => {
it('should expose slot', () => {
cy.visit(path.join(__dirname, 'index.html'))
cy.get('.vue-select').click()

cy.get('.vue-tag').should('have.text', 'I')
})
})
45 changes: 45 additions & 0 deletions cypress/integration/slots/toggle/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue
const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref('i')
const options = ref(['i'])
return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
>
<template #toggle="{ toggle, isFocusing }">
<button id="custom-toggle" @click="toggle">{{ isFocusing ? 'Opening' : 'Closing' }}</button>
</template>
</vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions cypress/integration/slots/toggle/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />
import path from 'path'

context('toggle', () => {
it('should expose slot', () => {
cy.visit(path.join(__dirname, 'index.html'))

cy.get('#custom-toggle').should('exist')
cy.get('#custom-toggle').should('have.text', 'Closing')

cy.get('#custom-toggle').click()

cy.get('#custom-toggle').should('have.text', 'Opening')
})
})

0 comments on commit 386a643

Please sign in to comment.