Refactoring: Migrated JS core tests to promise bases approach.
This commit is contained in:
parent
f80725ed62
commit
ae642683f5
2 changed files with 563 additions and 583 deletions
|
@ -1,259 +1,243 @@
|
||||||
window.onload = function() {
|
test( "ajax get 200", function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
callback = function() {
|
new Promise( (resolve, reject) => {
|
||||||
// ajax
|
|
||||||
App.Ajax.request({
|
App.Ajax.request({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/assets/tests/ajax-test.json',
|
url: '/assets/tests/ajax-test.json',
|
||||||
success: function (data) {
|
success: resolve,
|
||||||
test( "ajax get 200", function() {
|
error: reject
|
||||||
|
});
|
||||||
|
}).then( function(data) {
|
||||||
ok( true, "File found!")
|
ok( true, "File found!")
|
||||||
equal(data.success, true, "content parsable and ok!")
|
equal(data.success, true, "content parsable and ok!")
|
||||||
equal(data.success2, undefined, "content parsable and ok!")
|
equal(data.success2, undefined, "content parsable and ok!")
|
||||||
});
|
}, function(data) {
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
test( "ajax", function() {
|
|
||||||
ok( false, "Failed!")
|
ok( false, "Failed!")
|
||||||
});
|
})
|
||||||
}
|
.finally(done)
|
||||||
});
|
});
|
||||||
|
|
||||||
// ajax queueing
|
test( "ajax - queue - ajax get 200 1/2", function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
App.Ajax.request({
|
App.Ajax.request({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/tests/wait/2',
|
url: '/tests/wait/2',
|
||||||
queue: true,
|
queue: true,
|
||||||
success: function (data) {
|
success: resolve,
|
||||||
test( "ajax - queue - ajax get 200 1/2", function() {
|
error: reject
|
||||||
|
});
|
||||||
// check queue
|
}).then( function(data) {
|
||||||
ok( !window.testAjax, 'ajax - queue - check queue')
|
ok( !window.testAjax, 'ajax - queue - check queue')
|
||||||
window.testAjax = true;
|
window.testAjax = true;
|
||||||
equal(data.success, true, "ajax - queue - content parsable and ok!")
|
equal(data.success, true, "ajax - queue - content parsable and ok!")
|
||||||
equal(data.success2, undefined, "ajax - queue - content parsable and ok!")
|
equal(data.success2, undefined, "ajax - queue - content parsable and ok!")
|
||||||
});
|
}, function(data) {
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
test( "ajax", function() {
|
|
||||||
ok( false, "Failed!")
|
ok( false, "Failed!")
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
test( "ajax - queue - ajax get 200 2/2", function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
App.Ajax.request({
|
App.Ajax.request({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/tests/wait/1',
|
url: '/tests/wait/1',
|
||||||
queue: true,
|
queue: true,
|
||||||
success: function (data) {
|
success: resolve,
|
||||||
test( "ajax - queue - ajax get 200 2/2", function() {
|
error: reject
|
||||||
|
});
|
||||||
|
}).then( function(data) {
|
||||||
|
|
||||||
// check queue
|
// check queue
|
||||||
ok( window.testAjax, 'ajax - queue - check queue')
|
ok( window.testAjax, 'ajax - queue - check queue')
|
||||||
window.testAjax = undefined;
|
window.testAjax = undefined;
|
||||||
|
|
||||||
equal(data.success, true, "content parsable and ok!")
|
equal(data.success, true, "content parsable and ok!")
|
||||||
equal(data.success2, undefined, "content parsable and ok!")
|
equal(data.success2, undefined, "content parsable and ok!")
|
||||||
});
|
}, function(data) {
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
test( "ajax", function() {
|
|
||||||
ok( false, "Failed!")
|
ok( false, "Failed!")
|
||||||
});
|
})
|
||||||
}
|
.finally(done)
|
||||||
});
|
});
|
||||||
|
|
||||||
// ajax parallel
|
test( "ajax - parallel - ajax get 200", function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
App.Ajax.request({
|
App.Ajax.request({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/tests/wait/3',
|
url: '/tests/wait/3',
|
||||||
success: function (data) {
|
success: resolve,
|
||||||
test( "ajax - parallel - ajax get 200 1/2", function() {
|
error: reject
|
||||||
|
});
|
||||||
|
|
||||||
// check queue
|
new Promise( (resolve, reject) => {
|
||||||
ok( window.testAjaxQ, 'ajax - parallel - check queue')
|
|
||||||
window.testAjaxQ = undefined;
|
|
||||||
equal(data.success, true, "ajax - parallel - content parsable and ok!")
|
|
||||||
equal(data.success2, undefined, "ajax - parallel - content parsable and ok!")
|
|
||||||
});
|
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
test( "ajax", function() {
|
|
||||||
ok( false, "Failed!")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
App.Ajax.request({
|
App.Ajax.request({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/tests/wait/1',
|
url: '/tests/wait/1',
|
||||||
success: function (data) {
|
success: resolve,
|
||||||
test( "ajax - parallel - ajax get 200 2/2", function() {
|
error: reject
|
||||||
|
});
|
||||||
|
}).then( function(data) {
|
||||||
|
|
||||||
// check queue
|
// check queue
|
||||||
ok( !window.testAjaxQ, 'ajax - parallel - check queue')
|
ok( !window.testAjaxQ, 'ajax - parallel - check queue')
|
||||||
window.testAjaxQ = true;
|
window.testAjaxQ = true;
|
||||||
|
|
||||||
equal(data.success, true, "content parsable and ok!")
|
equal(data.success, true, "content parsable and ok!")
|
||||||
equal(data.success2, undefined, "content parsable and ok!")
|
equal(data.success2, undefined, "content parsable and ok!")
|
||||||
});
|
}, function(data) {
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
test( "ajax", function() {
|
|
||||||
ok( false, "Failed!")
|
ok( false, "Failed!")
|
||||||
});
|
})
|
||||||
}
|
.finally(done)
|
||||||
|
}).then( function(data) {
|
||||||
|
|
||||||
|
// check queue
|
||||||
|
ok( window.testAjaxQ, 'ajax - parallel - check queue')
|
||||||
|
window.testAjaxQ = undefined;
|
||||||
|
equal(data.success, true, "ajax - parallel - content parsable and ok!")
|
||||||
|
equal(data.success2, undefined, "ajax - parallel - content parsable and ok!")
|
||||||
|
}, function(data) {
|
||||||
|
ok( false, "Failed!")
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// delay
|
test('delay - test', function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
window.testDelay1 = false
|
window.testDelay1 = false
|
||||||
App.Delay.set(function() {
|
new Promise( (resolve, reject) => {
|
||||||
test('delay - test 1 - 1/3 - should not be executed, will be reset by next set()', function() {
|
App.Delay.set(resolve, 1000, 'delay-test1', 'level');
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
ok(false, 'delay - test 1 - 1/3 - should not be executed, will be reset by next set()')
|
App.Delay.set(resolve, 2000, 'delay-test1', 'level');
|
||||||
window.testDelay1 = true;
|
}).then( function() {
|
||||||
});
|
ok(!window.testDelay1, 'delay - 1/2')
|
||||||
},
|
|
||||||
1000,
|
|
||||||
'delay-test1',
|
|
||||||
'level'
|
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('delay - test 1 - 2/3', function() {
|
|
||||||
|
|
||||||
// check
|
|
||||||
ok(!window.testDelay1, 'delay - test 1 - 2/3')
|
|
||||||
window.testDelay1 = 1;
|
window.testDelay1 = 1;
|
||||||
});
|
})
|
||||||
},
|
|
||||||
2000,
|
|
||||||
'delay-test1',
|
|
||||||
'level'
|
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('delay - test 1 - 2/3', function() {
|
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
ok(window.testDelay1, 'delay - test 1 - 2/3')
|
App.Delay.set(resolve, 3000, 'delay-test1-verify', 'level');
|
||||||
|
}).then( function() {
|
||||||
|
ok(window.testDelay1, 'delay - 2/2')
|
||||||
window.testDelay1 = false;
|
window.testDelay1 = false;
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
}).then( function() {
|
||||||
|
ok(false, 'delay - 1/2 - FAILED - should not be executed, will be reset by next set()')
|
||||||
|
window.testDelay1 = true;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
|
||||||
3000,
|
|
||||||
'delay-test1-verify',
|
|
||||||
'level'
|
|
||||||
);
|
|
||||||
|
|
||||||
App.Delay.set(function() {
|
test('delay - test 2', function(assert) {
|
||||||
test('delay - test 2 - 1/3', function() {
|
var done = assert.async(1)
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
|
App.Delay.set(resolve, 2000);
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
|
App.Delay.set(resolve, 1000);
|
||||||
|
}).then( function() {
|
||||||
ok(!window.testDelay2, 'delay - test 2 - 1/3')
|
ok(!window.testDelay2, 'delay - test 2 - 1/3')
|
||||||
window.testDelay2 = 1;
|
})
|
||||||
});
|
|
||||||
},
|
|
||||||
2000
|
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('delay - test 2 - 2/3', function() {
|
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
ok(!window.testDelay2, 'delay - test 2 - 2/3')
|
App.Delay.set(resolve, 3000);
|
||||||
});
|
}).then( function() {
|
||||||
},
|
|
||||||
1000
|
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('delay - test 2 - 3/3', function() {
|
|
||||||
|
|
||||||
// check
|
|
||||||
ok(window.testDelay2, 'delay - test 2 - 3/3')
|
ok(window.testDelay2, 'delay - test 2 - 3/3')
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
}).then( function() {
|
||||||
|
ok(!window.testDelay2, 'delay - test 2 - 2/3')
|
||||||
|
window.testDelay2 = 1;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
|
||||||
3000
|
|
||||||
);
|
|
||||||
|
|
||||||
window.testDelay3 = 1;
|
test('delay - test 3', function(assert) {
|
||||||
App.Delay.set(function() {
|
var done = assert.async(1)
|
||||||
test('delay - test 3 - 1/1', function() {
|
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
ok(false, 'delay - test 3 - 1/1')
|
App.Delay.set(resolve, 1000, 'delay3');
|
||||||
});
|
|
||||||
},
|
|
||||||
1000,
|
|
||||||
'delay3'
|
|
||||||
);
|
|
||||||
App.Delay.clear('delay3')
|
App.Delay.clear('delay3')
|
||||||
|
ok(true, 'delay - test 3 - 1/1')
|
||||||
App.Delay.set(function() {
|
done()
|
||||||
test('delay - test 4 - 1/1', function() {
|
}).then( function() {
|
||||||
|
ok(false, 'delay - test 3 - 1/1 - FAILED')
|
||||||
// check
|
})
|
||||||
ok(false, 'delay - test 4 - 1/1')
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
1000,
|
test('delay - test 4', function(assert) {
|
||||||
undefined,
|
var done = assert.async(1)
|
||||||
'Page'
|
|
||||||
);
|
new Promise( (resolve, reject) => {
|
||||||
|
App.Delay.set(resolve, 1000, undefined, 'Page');
|
||||||
App.Delay.clearLevel('Page')
|
App.Delay.clearLevel('Page')
|
||||||
|
ok(true, 'delay - test 4 - 1/1')
|
||||||
|
done()
|
||||||
|
}).then( function() {
|
||||||
|
ok(false, 'delay - test 4 - 1/1 - FAILED')
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
test('interval - test 1', function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
// interval 1
|
|
||||||
window.testInterval1 = 1
|
window.testInterval1 = 1
|
||||||
App.Interval.set(function() {
|
App.Interval.set(function() {
|
||||||
window.testInterval1 += 1;
|
window.testInterval1 += 1;
|
||||||
},
|
},
|
||||||
2000,
|
100,
|
||||||
'interval-test1'
|
'interval-test1'
|
||||||
);
|
);
|
||||||
App.Delay.set(function() {
|
|
||||||
test('interval - test 1 - 1/2', function() {
|
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
equal(window.testInterval1, 4, 'interval - test 1')
|
App.Delay.set(resolve, 1000);
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
|
App.Delay.set(resolve, 2000);
|
||||||
|
}).then( function() {
|
||||||
|
equal(window.testInterval1, window.testInterval1Backup, 'interval - did not change after clear interval')
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
}).then( function() {
|
||||||
|
notEqual(window.testInterval1, 1, 'interval - interval moved up')
|
||||||
App.Interval.clear('interval-test1')
|
App.Interval.clear('interval-test1')
|
||||||
});
|
window.testInterval1Backup = window.testInterval1;
|
||||||
},
|
})
|
||||||
5200
|
})
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('interval - test 1 - 2/2', function() {
|
|
||||||
|
|
||||||
// check
|
test('interval - test 2', function(assert) {
|
||||||
equal(window.testInterval1, 4, 'interval - test after clear')
|
var done = assert.async(1)
|
||||||
});
|
|
||||||
},
|
|
||||||
6500
|
|
||||||
);
|
|
||||||
|
|
||||||
|
window.testInterval1 = 1
|
||||||
// interval 2
|
|
||||||
window.testInterval2 = 1
|
|
||||||
App.Interval.set(function() {
|
App.Interval.set(function() {
|
||||||
window.testInterval2 += 1;
|
window.testInterval1 += 1;
|
||||||
},
|
},
|
||||||
2000,
|
100,
|
||||||
undefined,
|
undefined,
|
||||||
'someLevel'
|
'someLevel'
|
||||||
);
|
);
|
||||||
App.Delay.set(function() {
|
|
||||||
test('interval - test 2 - 1/2', function() {
|
|
||||||
|
|
||||||
// check
|
new Promise( (resolve, reject) => {
|
||||||
equal(window.testInterval2, 4, 'interval - test 2')
|
App.Delay.set(resolve, 1000);
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
|
App.Delay.set(resolve, 2000);
|
||||||
|
}).then( function() {
|
||||||
|
equal(window.testInterval1, window.testInterval1Backup, 'interval - did not change after clear interval')
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
}).then( function() {
|
||||||
|
notEqual(window.testInterval1, 1, 'interval - interval moved up')
|
||||||
App.Interval.clearLevel('someLevel')
|
App.Interval.clearLevel('someLevel')
|
||||||
});
|
window.testInterval1Backup = window.testInterval1;
|
||||||
},
|
})
|
||||||
5200
|
})
|
||||||
);
|
|
||||||
App.Delay.set(function() {
|
|
||||||
test('interval - test 2 - 2/2', function() {
|
|
||||||
|
|
||||||
// check
|
|
||||||
equal(window.testInterval2, 4, 'interval - test 2 - after clear')
|
|
||||||
});
|
|
||||||
},
|
|
||||||
6900
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// events
|
// events
|
||||||
test('events simple', function() {
|
test('events simple', function() {
|
||||||
|
@ -597,50 +581,44 @@ window.onload = function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// auth
|
test('auth - not existing user', function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
App.Auth.login({
|
App.Auth.login({
|
||||||
data: {
|
data: {
|
||||||
username: 'not_existing',
|
username: 'not_existing',
|
||||||
password: 'not_existing',
|
password: 'not_existing',
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: resolve,
|
||||||
test('auth - not existing user', function() {
|
error: reject
|
||||||
ok(false, 'ok')
|
|
||||||
})
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
test('auth - not existing user', function() {
|
|
||||||
ok(true, 'ok')
|
|
||||||
authWithSession()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}).then( function(data) {
|
||||||
|
ok(false, 'ok')
|
||||||
|
}, function() {
|
||||||
|
ok(true, 'ok')
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
})
|
||||||
|
|
||||||
var authWithSession = function() {
|
test('auth - existing user', function(assert) {
|
||||||
|
var done = assert.async(1)
|
||||||
|
|
||||||
|
new Promise( (resolve, reject) => {
|
||||||
App.Auth.login({
|
App.Auth.login({
|
||||||
data: {
|
data: {
|
||||||
username: 'master@example.com',
|
username: 'master@example.com',
|
||||||
password: 'test',
|
password: 'test',
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: resolve,
|
||||||
test('auth - existing user', function() {
|
error: reject
|
||||||
|
});
|
||||||
|
}).then( function(data) {
|
||||||
ok(true, 'authenticated')
|
ok(true, 'authenticated')
|
||||||
var user = App.Session.get('login')
|
var user = App.Session.get('login')
|
||||||
equal('master@example.com', user, 'session login')
|
equal('master@example.com', user, 'session login')
|
||||||
|
}, function() {
|
||||||
|
ok(false, 'failed')
|
||||||
})
|
})
|
||||||
},
|
.finally(done)
|
||||||
error: function() {
|
|
||||||
test('auth - existing user', function() {
|
|
||||||
ok(false, 'not authenticated')
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run tests after the app has been initialized to avoid race condition
|
|
||||||
// between interval (timing) checks that may delayed by JS parsing
|
|
||||||
// and App initialization
|
|
||||||
App.Event.bind("app:ready", callback)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,12 +10,14 @@ class AgentNavigationAndTitleTest < TestCase
|
||||||
)
|
)
|
||||||
tasks_close_all()
|
tasks_close_all()
|
||||||
|
|
||||||
# since we run the basic functionality tests via Capybara the clues are shown
|
# since we run the basic functionality tests via Capybara now the clues are shown
|
||||||
# and skipped after the login. This removes the 'is-active' class from the
|
# and closed after the login. This unfortunately removes the 'is-active' class from the
|
||||||
# dashboard link causing the following tests to fail. As the browser tests are
|
# dashboard link causing the following tests to fail.
|
||||||
# deprecated and there is no easy fix to change that we refresh the page as
|
# Because the browser tests are deprecated and there is no easy fix to change the
|
||||||
# a workaround. This will cause the 'is-active' class to be set on the menu item again
|
# behavior we refresh the page and wait for it to finish loading the app as a workaround.
|
||||||
|
# This will cause the 'is-active' class to be set on the menu item again
|
||||||
reload()
|
reload()
|
||||||
|
sleep 4
|
||||||
|
|
||||||
# dashboard after login
|
# dashboard after login
|
||||||
verify_title(value: 'dashboard')
|
verify_title(value: 'dashboard')
|
||||||
|
|
Loading…
Reference in a new issue