-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/test-e2e-composable-vue3/src/components/Subscription.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts" setup> | ||
import { useSubscription } from '@vue/apollo-composable' | ||
import gql from 'graphql-tag' | ||
import { ref } from 'vue' | ||
const messages = ref<Array<{ id: string, text: string }>>([]) | ||
const { onResult } = useSubscription(gql`subscription OnMessageAdded { | ||
messageAdded(channelId: "general") { | ||
id | ||
text | ||
} | ||
}`) | ||
onResult((result) => { | ||
console.log(result.data?.messageAdded) | ||
if (result.data?.messageAdded) { | ||
messages.value.push(result.data.messageAdded) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="space-y-2 p-2 border border-gray-200 rounded-xl"> | ||
<div | ||
v-for="message in messages" | ||
:key="message.id" | ||
class="message px-4 py-2 bg-white rounded-lg" | ||
> | ||
{{ message.text }} | ||
</div> | ||
|
||
<div v-if="!messages.length"> | ||
No messages yet | ||
</div> | ||
</div> | ||
</template> |
20 changes: 20 additions & 0 deletions
20
packages/test-e2e-composable-vue3/src/components/Subscriptions.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script lang="ts" setup> | ||
import MessageForm from './MessageForm.vue' | ||
import Subscription from './Subscription.vue' | ||
</script> | ||
|
||
<template> | ||
<div class="m-12 space-y-4"> | ||
<h1 class="text-2xl"> | ||
Subscription | ||
</h1> | ||
<MessageForm channel-id="general" /> | ||
<div class="flex gap-4"> | ||
<Subscription | ||
v-for="n in 3" | ||
:key="n" | ||
class="flex-1" | ||
/> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/test-e2e-composable-vue3/tests/e2e/specs/subscription.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe('Subscription', () => { | ||
beforeEach(() => { | ||
cy.task('db:reset') | ||
cy.visit('/') | ||
}) | ||
|
||
it('receive messages in real time', () => { | ||
cy.visit('/subscriptions') | ||
cy.get('input').type('Meow{enter}') | ||
cy.get('.message').should('have.length', 3) | ||
cy.get('.message').should('contain', 'Meow') | ||
cy.get('input').type('Waf{enter}') | ||
cy.get('.message').should('have.length', 6) | ||
cy.get('.message').should('contain', 'Waf') | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.