Skip to content

Commit

Permalink
ic: add func test for autocomplete and abe data
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Dec 20, 2016
1 parent aa1b432 commit 9ee44ec
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"install-selenium": "node nightwatch.conf.js",
"pretest-func": "ROOT=$PWD/tests/demo ./dist/index.js serve -p 3003 &",
"test-func": "sleep 6 && node_modules/.bin/nightwatch --config nightwatch.conf.js",
"posttest-func": "killall node",
"posttest-func": "kill -9 $(lsof -ti tcp:3003)",
"start": "node --debug --harmony ./dist/server/index.js",
"babel": "babelify --presets [ es2015 ] src/server/public/abejs/scripts/template-engine.js -o src/server/public/abejs/scripts/template-engine-compiled.js",
"watch": "./node_modules/.bin/parallelshell './node_modules/.bin/watchify -v -t [ babelify --presets [ es2015 ] ] src/server/public/abejs/scripts/template-engine.js -o src/server/public/abejs/scripts/template-engine-compiled.js' './node_modules/.bin/watchify -v -t [ babelify --presets [ es2015 ] ] src/server/public/abejs/scripts/admin.js -o src/server/public/abejs/scripts/admin-compiled.js' './node_modules/.bin/watchify -v -t [ babelify --presets [ es2015 ] ] src/server/public/abejs/scripts/user-login.js -o src/server/public/abejs/scripts/user-login-compiled.js' 'npm run watch:sass'",
Expand Down
12 changes: 9 additions & 3 deletions src/cli/cms/data/attr.js
Expand Up @@ -37,12 +37,18 @@ export default class Attr {
* @return {String} str without attributes
*/
remove() {
return this.str.replace(new RegExp(fullAttr + this.getExtension() + ')'), '')
if (this.str != null) {
return this.str.replace(new RegExp(fullAttr + this.getExtension() + ')'), '')
}
return this.str
}

getExtension(){
var ext = this.str.split('.')
return ext[ext.length - 1]
if (this.str != null) {
var ext = this.str.split('.')
return ext[ext.length - 1]
}
return ''
}

/**
Expand Down
53 changes: 53 additions & 0 deletions tests/demo/reference/adress.json
@@ -0,0 +1,53 @@
{
"address_components": [
{
"long_name": "State of Pará",
"short_name": "PA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Brazil",
"short_name": "BR",
"types": [
"country",
"political"
]
}
],
"formatted_address": "State of Pará, Brazil",
"geometry": {
"bounds": {
"northeast": {
"lat": 2.5910246,
"lng": -46.0643195
},
"southwest": {
"lat": -9.8411565,
"lng": -58.89827700000001
}
},
"location": {
"lat": -1.9981271,
"lng": -54.9306152
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 2.5910246,
"lng": -46.0643195
},
"southwest": {
"lat": -9.8411565,
"lng": -58.89827700000001
}
}
},
"place_id": "ChIJlwksrJn5iJIRCvNV5z7IXjE",
"types": [
"administrative_area_level_1",
"political"
]
}
17 changes: 17 additions & 0 deletions tests/demo/reference/data.json
@@ -0,0 +1,17 @@
[
{
"id": 1,
"name": "test 1",
"lang": "de"
},
{
"id": 2,
"name": "test 2",
"lang": "fr"
},
{
"id": 3,
"name": "test 3",
"lang": "es"
}
]
24 changes: 24 additions & 0 deletions tests/demo/reference/products.json
@@ -0,0 +1,24 @@
[
{
"name": "r1",
"recipe": "Recipe 1",
"products": [
{
"title": "product 1",
"cover_300x200": "/image/turkey_300x200.jpg",
},
{
"title": "product 2",
"cover_300x200": "/image/chicken_300x200.jpg",
},
{
"title": "product 3",
"cover_300x200": "/image/chicken_300x200.jpg",
},
{
"title": "product 4",
"cover_300x200": "/image/chicken_300x200.jpg",
}
]
}
]
48 changes: 48 additions & 0 deletions tests/demo/templates/autocomplete.html
@@ -0,0 +1,48 @@
{{abe type='data' key='colors.single' desc='Color single' source='["rouge", "vert", "bleu"]' max-length="1" tab="colors" reload="true"}}
{{abe type='data' key='colors.multiple' desc='Color multiple' source='["rouge", "vert", "bleu"]' tab="colors" reload="true"}}
{{abe type='data' key='colors.colors_autocomplete' desc='Color autocomplete (enter "rouge")' source='["rouge", "vert", "bleu"]' autocomplete="true" tab="colors" reload="true"}}

{{abe type='data' key='reference.single' source="reference/data.json" max-length="1" display="{{name}}" desc='data ref single' tab="reference" reload="true"}}
{{abe type='data' key='reference.multiple' source="reference/data.json" display="{{name}}" desc='data ref multiple' tab="reference" reload="true"}}
{{abe type='data' key='reference.autocomplete' source="reference/data.json" display="{{name}}" autocomplete="true" desc='Data ref autocomplete (enter "test")' tab="reference" reload="true"}}

<!DOCTYPE HTML>
<!--
Twenty by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<style>
code { background: hsl(220, 80%, 90%); }
pre { white-space: pre-wrap; background: hsl(30,80%,90%); word-break: break-all;}
</style>
</head>
<body class="index">
<div>
<b>colors:</b>
<pre><code>{{printJson colors}}</code></pre>
</div>
<hr>
<div>
<b>reference:</b>
<pre><code>{{printJson reference}}</code></pre>
</div>
<hr>

{{abe type='text' key='title1' desc='title' tab='default'}}
<img src="{{abe type='image' key='image1' desc='image' tab='default'}}" alt="">

{{abe type='text' key='level1.title' desc='level 1 title' tab='default'}}
<img src="{{abe type='image' key='level1.image' desc='level 1 image' tab='default'}}" alt="">

{{abe type='text' key='level2.sublevel2.title' desc='level 2 title' tab='default'}}

{{#each eachlevel}}
{{abe type='text' key='eachlevel.title' desc='title' tab='default'}}
<img src="{{abe type='image' key='eachlevel.image' desc='image' tab='default'}}" alt="">
{{abe type='text' key='eachlevel.level.value' desc='value' tab='default'}}
{{/each}}
</body>
</html>
51 changes: 51 additions & 0 deletions tests/functional/abe-data.js
@@ -0,0 +1,51 @@
describe('Abe', function() {

describe('data', function() {

before(function(client, done) {
done();
});

after(function(client, done) {
client.end(function() {
done();
});
});

afterEach(function(client, done) {
done();
});

beforeEach(function(client, done) {
done();
});

it('Create a autocomplete template post', function(client) {
client
.url('http://localhost:3003/abe/editor')
.click('select[name="selectTemplate"] option[value="autocomplete"]')
.waitForElementVisible('div[data-precontrib-templates="autocomplete"] input[id="name"]', 1000)
.setValue('div[data-precontrib-templates="autocomplete"] input[id="name"]', 'autocomplete')
.click('button[type="submit"]')
.waitForElementVisible('form[id="abeForm"]', 2000)
.assert.urlEquals("http://localhost:3003/abe/editor/autocomplete.html", "Clicked URL Matches with URL of the New Window");
});


it('Abe type data reference json', function(client) {
client
.useXpath()
.url('http://localhost:3003/abe/editor/autocomplete.html')
.waitForElementVisible('//body')
.pause(1000)
.click('//*[@id="abeForm"]/ul/li[2]/a')
.waitForElementVisible('//*[@id="reference"]/div')
.click('//*[@id="reference.single"]/option[2]')
.click('//*[@id="reference.multiple"]/option[3]')
.setValue('//*[@id="reference.autocomplete"]', 'test')
.waitForElementVisible('//*[@id="reference"]/div/div/div/div[3]/div[2]', 2000)
.click('//*[@id="reference"]/div/div/div/div[3]/div[2]/div[1]')
.waitForElementVisible('//*[@id="reference"]/div/div/div/div[3]/div/div', 2000);
});
});
});

0 comments on commit 9ee44ec

Please sign in to comment.