Skip to content
Merged
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
3 changes: 3 additions & 0 deletions doc/6/getting-started/vuejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/cypress/screenshots/
/cypress/videos/
package-lock.json
14 changes: 14 additions & 0 deletions doc/6/getting-started/vuejs/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"baseUrl": "http://localhost:8080",
"viewportWidth": 1400,
"viewportHeight": 900,
"defaultCommandTimeout": 5000,
"env": {
"kuzzle": {
"host": "localhost",
"port": "7512",
"index": "chat",
"collection": "messages"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"username": "Elrond"
}
26 changes: 26 additions & 0 deletions doc/6/getting-started/vuejs/cypress/fixtures/Environment.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"username": "Legolas",
"messages": [
{
"_id": "1",
"payload": {
"value": "It still only counts as one!",
"username": "Gimli"
}
},
{
"_id": "2",
"payload": {
"value": "What do your elf eyes see?",
"username": "Aragorn"
}
},
{
"_id": "3",
"payload": {
"value": "What about side by side with a friend?",
"username": "Legolas"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "Sam",
"payload": {
"username": "Sam",
"value": "I can't carry it for you, But I can carry you!"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "Sauron",
"payload": {
"username": "Eowyn",
"value": "I am no man"
}
}
87 changes: 87 additions & 0 deletions doc/6/getting-started/vuejs/cypress/integration/chat.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
describe('test realtime chat', () => {
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);
});
});
});
17 changes: 17 additions & 0 deletions doc/6/getting-started/vuejs/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
106 changes: 106 additions & 0 deletions doc/6/getting-started/vuejs/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

function reinitialisation() {
const kuzzle = Cypress.env('kuzzle');

// Clear collection
return cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}/${kuzzle.collection}/_truncate`,
method: 'DELETE',
})
.then(searchResponse => {
cy.log(`Request : truncate ${kuzzle.collection} status : ${searchResponse.status}`);
cy.wait(500);
});
}

Cypress.Commands.add('createMessage', (message) => {
const kuzzle = Cypress.env('kuzzle');
return cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}/${kuzzle.collection}/${message._id}/_create`,
method: 'POST',
body: message.payload,
})
.its('body')
.then(response => {
cy.log(`Create : ${message._id} status : ${response.status}`);
cy.wait(500);
});
});


Cypress.Commands.add('initialisation', () => {
const kuzzle = Cypress.env('kuzzle');

// Delete index if exists
cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}/_exists`,
method: 'GET',
})
.then(existsResponse => {
cy.log(`Request : exists ${kuzzle.index} status : ${existsResponse.status}`);
if (existsResponse.body.result) {
cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}`,
method: 'DELETE',
})
.then(deleteResponse => {
cy.log(`Request : delete ${kuzzle.index} status : ${deleteResponse.status}`);
});
}
}).then(() => {
// Create index
cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}/_create`,
method: 'POST',
})
.then(createResponse => {
cy.log(`Request : create ${kuzzle.index} status : ${createResponse.status}`);
cy.wait(500);
});
})
.then(() => {
// Create collection
cy.request({
url: `http://${kuzzle.host}:${kuzzle.port}/${kuzzle.index}/${kuzzle.collection}`,
method: 'PUT',
body: {}
})
.then(createResponse => {
cy.log(`Request : create ${kuzzle.collection} status : ${createResponse.status}`);
cy.wait(500);
});
});
});

Cypress.Commands.add('loadEnvironment', (env) => {
reinitialisation();
if (!env.messages) {return;}
env.messages.forEach(message => {
cy.createMessage(message);
});
});
20 changes: 20 additions & 0 deletions doc/6/getting-started/vuejs/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
50 changes: 50 additions & 0 deletions doc/6/getting-started/vuejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "kuzzle-vuejs-gs",
"version": "0.1.0",
"private": true,
"scripts": {
"postinstall": "if [ ! -f ../../../../dist/kuzzle.js ]; then npm run build --prefix ../../../../;fi && rm -rf ./node_modules/kuzzle-sdk/* && rsync -r --exclude 'getting-started' ../../../../ ./node_modules/kuzzle-sdk",
"serve-without-vuex": "cd without-vuex && vue-cli-service serve",
"build-without-vuex": "cd without-vuex && vue-cli-service build",
"lint-without-vuex": "cd without-vuex && vue-cli-service lint",
"test": "./node_modules/.bin/cypress run"
},
"dependencies": {
"core-js": "^2.6.5",
"vue": "^2.6.10",
"vuex": "^3.1.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.7.0",
"@vue/cli-plugin-eslint": "^3.7.0",
"@vue/cli-service": "^3.7.0",
"babel-eslint": "^10.0.1",
"cypress": "^3.3.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"vue-template-compiler": "^2.5.21"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
5 changes: 5 additions & 0 deletions doc/6/getting-started/vuejs/without-vuex/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/app'
]
}
Binary file not shown.
17 changes: 17 additions & 0 deletions doc/6/getting-started/vuejs/without-vuex/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>kuzzle-vuejs-gs</title>
</head>
<body>
<noscript>
<strong>We're sorry but kuzzle-vuejs-gs doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Loading