theia-ide / sprotty

A next-gen web-based graphics framework
Apache License 2.0
138 stars 23 forks source link

[client] enable testing #2

Closed JanKoehnlein closed 7 years ago

JanKoehnlein commented 7 years ago

Hook up an appropriate testing framework (mocha, jest, or similar) with npm and write some basic tests.

JanKoehnlein commented 7 years ago

An exemplary test for commands could look like

// setup the GModel
const model = new GGraph({
   id: 'graph', 
   type: 'graph', 
   shapes: [{
       id: 'node0', type: 'circle', selected=true, x: 100, y: 100
    },{
       id: 'node1', type: 'circle', x: 100, y: 100
    },
   ]
});

// create the command
const cmd = new SelectionCommand({
   selected = [ 'node1' ],
   deselected = ['node0']
})

// execute command
const newModel = cmd.execute(model)

// check result
const nodes = newModel.getChildren()
// assertions, e.g. using chai should style
const node0 = newModel.index.getById('node0')
node0.selected.should.be.false
nodes.indexOf(node0).should.equal(1)

const node1 = newModel.index.getById('node1')
node1.selected.should.be.true
nodes.indexOf(node1).should.equal(0)

// test undo
...
// test redo
...
JanKoehnlein commented 7 years ago

Theia is going to use mocha, chai and karma.

JanKoehnlein commented 7 years ago

We have set up various kinds of tests:

I think, that's enough to close this issue.