For example I would like to test that my controller responds to a given message by loading a store from a static mock data file.
I'm having trouble creating controllers because they create stores and the Ext code needs an Ext.application to create the store. I can create a full version of my application in a test file but that is much more than I want to test. If I try to create a mock app I run into problems where the 'get' functions generated by the controller's refs block are not defined. (that's the problem I've run into in my latest attempt, but I've tried other variations of test code that all run into similar problems.)
What do I need to generate these refs functions? And, more generally, are there any examples of controller tests? I haven't been able to find any.
My test looks like this:
StartTest(function(t) {
var aStore, srStore, form, mStore, drStore, fCtlr;
var searchButton,
patientIdBox,
patientNameBox,
patientBirthDateBox,
accessionNumberBox,
studyDescriptionBox,
modalityBox,
dateRangeBox,
clearResultsBox;
t.diag("Search filter form test");
t.chain(
function(next) {
// we need an app to create a controller.
var app;
Ext.application({
name: 'StudySearch',
appFolder: '/vitrea-home/study-search',
models: ['Archive', 'DateRange', 'Modality'],
stores: ['Archives', 'DateRanges', 'Modalities'],
controllers: ['Filter'],
launch: function() {
app = this;
var app = this;
fCtlr = app.getController('Filter');
aStore = app.getStore('Archives');
srStore = app.getStore('SearchResults');
mStore = app.getStore('Modalities');
drStore = app.getStore('DateRanges');
t.ok(fCtlr, 'now we can test the Filter controller with the mock app');
next();
}
});
},
function (next) {
// override with mock data urls
aStore.model.proxy.url = './siesta-test/mock/archive.json';
srStore.proxy.url = srStore.mintURL = '/vitrea-home/siesta-test/mock/studies.json';
t.loadStoresAndThen(aStore, srStore, next);
},
...
function(next) {
t.done();
}
);
})
Ext.define('StudySearch.controller.Filter', {
extend: 'Ext.app.Controller',
stores: ['Archives', 'DateRanges', 'Modalities'],
views: ['ArchivesList', 'SearchForm', 'SelectField'],
refs: [{
ref: 'filter',
selector: 'filter'
},{
ref: 'archivesList', // ******* this fails to generate a getArchivesList() function *******
selector: 'archiveslist'
},{
ref: 'searchForm', // ******* this fails to generate a getSearchForm() function *******
selector: 'searchform'
}],
init: function() {
this.control({
'archiveslist': {
select: this.onArchiveSelect
},
'viewport > #search-west > searchform button': {
click: this.onSearch
},
'viewport > #search-west > searchform textfield': {
keyup: this.onKeyUp
}
});
// listen for events from other controllers
if (this.application) {
this.application.on({
logout: this.onLogout,
scope: this
});
}
},
... function defs ...
}