diff --git a/doc/6/getting-started/vuejs/cypress/integration/tchat.spec.js b/doc/6/getting-started/vuejs/cypress/integration/tchat.spec.js new file mode 100644 index 000000000..6d3ad2034 --- /dev/null +++ b/doc/6/getting-started/vuejs/cypress/integration/tchat.spec.js @@ -0,0 +1,87 @@ +describe('test realtime tchat', () => { + let currentIt = 1; + let env; + + before(() => { + cy.initialisation(); + }); + + beforeEach(() => { + cy.visit('/'); + cy.fixture(`Environment.${currentIt}.json`) + .then((fixtures) => { env = fixtures; }) + .then(() => cy.log(`Environment ${currentIt}: `, env)) + .then(() => cy.loadEnvironment(env)); + cy.wait(2000); + }); + + afterEach(() => { + currentIt++; + }); + + it('should enter a nickname', () => { + cy.get('[placeholder="Enter your message"]') + .should('not.exist'); + + cy.get('[placeholder="Enter your nickname"]') + .type(env.username); + + + cy.contains('Valid') + .click(); + + cy.get('[placeholder="Enter your message"]') + .should('exist'); + cy.get('[placeholder="Enter your nickname"]') + .should('not.exist'); + }); + + it('should fetch and display some messages', () => { + cy.get('[placeholder="Enter your nickname"]') + .type(env.username); + cy.contains('Valid') + .click(); + + env.messages.forEach(message => { + cy.get(message.payload.username === env.username ? '.fromMe': '.fromOthers') + .within(() => { + cy.contains(message.payload.value); + cy.contains(message.payload.username); + }); + }); + }); + + it('should send a message', () => { + cy.get('[placeholder="Enter your nickname"]') + .type(env.username); + cy.contains('Valid') + .click(); + cy.createMessage({ + _id: '1', + payload: env.payload + }); + + cy.get('.fromMe') + .within(() => { + cy.contains(env.payload.value); + cy.contains(env.username); + }); + }); + + it('should receive a message', () => { + cy.get('[placeholder="Enter your nickname"]') + .type(env.username); + cy.contains('Valid') + .click(); + cy.createMessage({ + _id: '1', + payload: env.payload + }); + + cy.get('.fromOthers') + .within(() => { + cy.contains(env.payload.value); + cy.contains(env.payload.username); + }); + }); +}); \ No newline at end of file diff --git a/doc/6/getting-started/vuejs/index.md b/doc/6/getting-started/vuejs/index.md new file mode 100644 index 000000000..f3fa0ce0d --- /dev/null +++ b/doc/6/getting-started/vuejs/index.md @@ -0,0 +1,7 @@ +--- +code: false +type: branch +title: VueJS +description: Get started with the Javascript SDK and VueJS +order: 300 +--- diff --git a/doc/6/getting-started/vuejs/without-vuex/index.md b/doc/6/getting-started/vuejs/without-vuex/index.md new file mode 100644 index 000000000..2c8e991df --- /dev/null +++ b/doc/6/getting-started/vuejs/without-vuex/index.md @@ -0,0 +1,121 @@ +--- +type: page +code: false +title: Without Vuex +description: Getting started with Kuzzle and VueJS +order: 0 +--- + + +# Getting Started with Kuzzle and VueJS + +This section deals with **Kuzzle** (+ **Javascript SDK**) and **VueJS**. We will create **documents** in Kuzzle and subscribe to [document notifications](/sdk/js/6/essentials/realtime-notifications/#document-messages) to develop a realtime chat. + +You can find the full code of this guide [here](https://github.com/kuzzleio/sdk-javascript/tree/6-dev/doc/6/getting-started/vuejs/without-vuex). + +## Requirements + +- **Node.js** >= 8.0.0 ([install here](https://nodejs.org/en/download/)) +- **Vue CLI** ([install here](https://cli.vuejs.org/guide/installation.html)) +- **Running Kuzzle Stack** ([instructions here](/core/1/guides/getting-started/running-kuzzle/)) + +## Prepare your environment + +Create your VueJS app with Vue CLI. You'll need to select manually the features, +just add Babel, Linter and select the default options for the other features. +```bash +vue create kuzzle-playground +``` + +Install the kuzzle-sdk: +```bash +cd kuzzle-playground +yarn add kuzzle-sdk +``` + +In the _App.vue_ file, you should remove the tag, the import and the component registration of the `HelloWorld` component, we won't use it. + +## Instanciating Kuzzle SDK + +We have to connect the server so that our client can interact with it. + +To do this, we have to create _src/services/kuzzle.js_ file to put our kuzzle instance, a bit like a singleton: + +<<< ./src/services/kuzzle.js + +We need to import our Kuzzle SDK instance, so just add the following line in your `