删除与TestSet关联的所有测试用例

时间:2014-02-04 15:07:55

标签: extjs rally

使用Rally SDK 2.0 API,我想将新TestCases与给定的TestSet相关联。要做到这一点我:

  1. 初始化商店:

    me.selectedTestCasesStore = myTestSet.getCollection('TestCases',{...});
    
  2. 删除所有项目(我不想保留它们):

    me.selectedTestCasesStore.removeAll();
    
  3. 添加新的TestCases

    me.selectedTestCasesStore.add({'_ref':aTestCaseRecord.data._ref});
    
  4. 然后同步

    me.selectedTestCasesStore.sync({...});
    
  5. 第1步没问题:console.log(me.selectedTestCasesStore)向我展示了data.items[]中的收藏。

    第2步似乎没问题,因为console.log(me.selectedTestCasesStore)data.items[]中没有显示任何内容(以前的记录已经消失)。

    步骤3没问题,因为步骤1中不存在的添加的测试用例现在位于集合

    第4步:被叫功能是“成功”

    但是 ...只添加了新的TestCase,旧的没有被删除,就好像第2步没有效果一样。我的代码有什么问题?我提取了相关代码的一部分:

    // me.selectedTestCasesStore : my store, with old TestCase associated to a TestSet.
    // It is initialized with something like :
    //    me.selectedTestCasesStore = myTestSet.getCollection('TestCases',{...});
    //
    // selectedTestCasesArray : an array of records with the new TestCases to assign to the test set.
    
    
    _removeAllFromSelectedTestCaseStore:function()
    {
        var me = this ;
        console.log('In _removeAllFromSelectedTestCaseStore');
    
        me.selectedTestCasesStore.addListener({
            clear : me._addSelectedTestCasesToSelectedTestCaseStore,
            scope : me,
        });
    
        // Remove all associated TestCases from selectedTestCases store
        me.selectedTestCasesStore.removeAll();
    },
    
    
    _addSelectedTestCasesToSelectedTestCaseStore:function()
    {
        var me = this ;
        console.log('In _addSelectedTestCasesToSelectedTestCaseStore');
    
        console.log('      After remove, store is now :',me.selectedTestCasesStore);
    
        // Add each check TestCase to selectedTestCases store
        for (var i=0; i < me.selectedTestCasesArray.length; i++)
        {
            // Add it to the collection
            me.selectedTestCasesStore.add({'_ref':me.selectedTestCasesArray[j].data._ref});
        }
    
        console.log('      After add, store is now :',me.selectedTestCasesStore);
    
        // Synchronyze
        me.selectedTestCasesStore.sync(
        {
            success: function(batch, options) {
                //success!
                console.log('      Success', me.selectedTestSetStore);
            },
            failure: function(batch, options){
                console.log('      Faillure :(', me.selectedTestSetStore);
            },
        });
    },
    

    感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

这适用于我而不是removeAll():

 var testcases = testCaseStore.getRange();
 _.each(testcases, function(testcase) { 
     testCaseStore.remove(testcase);
 });

以下是在添加新测试用例之前清空测试集上的测试用例集合的完整js文件

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',

    launch: function() {
        console.log("launch");
       Rally.data.ModelFactory.getModel({
            type: 'TestSet',
            success: this._onModelRetrieved,
            scope: this
        });
    },
    _onModelRetrieved: function(model) {
        console.log("_onModelRetrieved");
        this.model = model;
        this._readRecord(model);
    },

     _readRecord: function(model) {
        var id = 16805375409;
        console.log("_readRecord");
        this.model.load(id, {
            fetch: ['Name', 'FormattedID', 'TestCases'],
            callback: this._onRecordRead,
            scope: this
        });
    },

    _onRecordRead: function(record, operation) {
        console.log('name:', record.get('Name'));
        console.log('test cases:', record.get('TestCases'));
        if(operation.wasSuccessful()) {
             var testCaseStore = record.getCollection('TestCases', {
                autoLoad: true,
                listeners: { load: function() {
                    var testcases = testCaseStore.getRange();
                    _.each(testcases, function(testcase) { 
                        testCaseStore.remove(testcase);
                    });
                    testCaseStore.sync({
                            callback: function() {
                             console.log('test cases after removeAll():', record.get('TestCases'));
                        }
                        });
                    testCaseStore.add({'_ref':'/testcase/14469886070'});
                    testCaseStore.sync({
                        callback: function() {
                             console.log('test cases after add():', record.get('TestCases'));
                        }
                    });
                }}
            });
        }

    }, 
});