File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
packages/test-e2e-composable-vue3 Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ <script lang="ts">
2+ import gql from ' graphql-tag'
3+ import { useQuery } from ' @vue/apollo-composable'
4+ import { defineComponent , computed , ref } from ' vue'
5+
6+ export default defineComponent ({
7+ setup () {
8+ const selectedId = ref <string | null >(null )
9+
10+ const { result, loading } = useQuery (gql `
11+ query channel ($id: ID!) {
12+ channel (id: $id) {
13+ id
14+ label
15+ messages {
16+ id
17+ }
18+ }
19+ }
20+ ` , () => ({
21+ id: selectedId .value ,
22+ }), () => ({
23+ fetchPolicy: ' no-cache' ,
24+ enabled: !! selectedId .value ,
25+ }))
26+ const channel = computed (() => result .value ?.channel )
27+
28+ function load () {
29+ selectedId .value = ' general'
30+ }
31+
32+ return {
33+ load ,
34+ loading ,
35+ channel ,
36+ }
37+ },
38+ })
39+ </script >
40+
41+ <template >
42+ <div class =" m-6" >
43+ <div >
44+ <button
45+ class =" bg-green-200 rounded-lg p-4"
46+ @click =" load()"
47+ >
48+ Load channel
49+ </button >
50+ </div >
51+
52+ <div
53+ v-if =" loading"
54+ class =" loading"
55+ >
56+ Loading...
57+ </div >
58+
59+ <div
60+ v-if =" channel"
61+ data-test-id =" data"
62+ >
63+ <div >Loaded channel: {{ channel.label }}</div >
64+ <div >Messages: {{ channel.messages.length }}</div >
65+ </div >
66+ </div >
67+ </template >
Original file line number Diff line number Diff line change @@ -34,5 +34,9 @@ export const router = createRouter({
3434 path : '/partial-error' ,
3535 component : ( ) => import ( './components/PartialError.vue' ) ,
3636 } ,
37+ {
38+ path : '/disabled' ,
39+ component : ( ) => import ( './components/Disabled.vue' ) ,
40+ } ,
3741 ] ,
3842} )
Original file line number Diff line number Diff line change @@ -109,4 +109,12 @@ describe('Vue 3 + Apollo Composable', () => {
109109 cy . get ( '.list-disc' ) . should ( 'have.length' , 3 )
110110 cy . get ( '[data-test-id="refetched"]' ) . should ( 'contain' , 'true' )
111111 } )
112+
113+ it ( 'enabled' , ( ) => {
114+ cy . visit ( '/disabled' )
115+ cy . get ( '[data-test-id="data"]' ) . should ( 'not.exist' )
116+ cy . get ( '.loading' ) . should ( 'not.exist' )
117+ cy . get ( 'button' ) . click ( )
118+ cy . get ( '[data-test-id="data"]' ) . should ( 'contain' , 'Loaded channel: General' )
119+ } )
112120} )
You can’t perform that action at this time.
0 commit comments