1 |
|
2 |
|
3 |
|
4 | import GMP from 'GMP';
|
5 | import chai from 'chai';
|
6 | var expect = chai.expect;
|
7 | describe('GMPView test ', ()=> {
|
8 |
|
9 | it('jquery exists', ()=> {
|
10 | expect($).to.equal(jQuery);
|
11 | });
|
12 | it('GMP exists', ()=> {
|
13 | expect(GMP).to.be.a("function");
|
14 | });
|
15 | it('GMP instance null options', ()=> {
|
16 | let gmp = new GMP();
|
17 | expect(gmp instanceof GMP).to.equal(true);
|
18 | expect(gmp._uid).to.match(/^g/);
|
19 | expect(gmp.el).to.be.an.instanceOf(Node);
|
20 | expect(gmp.$el).to.be.an.instanceOf(jQuery);
|
21 | expect(gmp._eventsMapList).to.be.empty;
|
22 | expect(gmp.data).to.be.empty;
|
23 | expect(gmp.events).to.be.empty;
|
24 | expect(gmp.els).to.be.a("undefined");
|
25 | expect(gmp.init).to.be.a("undefined");
|
26 | });
|
27 |
|
28 | it('GMP instance options', ()=> {
|
29 | var script = '<script id="tmpl" type="text/html"><%=name%></script>';
|
30 | $('body').append('<div id="div"></div>').append(script);
|
31 | let gmp = new GMP({
|
32 | el: '#div',
|
33 | data: {
|
34 | name: 'zeromike',
|
35 | location: 'beijing'
|
36 | },
|
37 | template:GMP.template('tmpl'),
|
38 | events: {
|
39 | 'click #id': 'open'
|
40 | },
|
41 | open: function () {
|
42 | return 'open';
|
43 | },
|
44 | init: function () {
|
45 | this.$el.html(this.template(this.data));
|
46 | return 'test';
|
47 | }
|
48 | });
|
49 | gmp.on('gmp_event', function (arg) {
|
50 | expect('gmp_event_test').to.equal(arg);
|
51 | });
|
52 |
|
53 | expect(gmp instanceof GMP).to.equal(true);
|
54 | expect(gmp._uid).to.match(/^g/);
|
55 | expect(gmp.$el).to.be.an.instanceOf(jQuery);
|
56 | expect(gmp.el.id).to.equal('div');
|
57 | expect(gmp._eventsMapList[gmp._uid + "gmp_event"]).to.be.a('array');
|
58 | gmp.trigger('gmp_event', 'gmp_event_test');
|
59 | expect(gmp.data).to.have.property('name', 'zeromike');
|
60 | expect(gmp.data.location).to.equals('beijing');
|
61 | expect(gmp.events).to.have.property('click #id', 'open');
|
62 | expect(gmp.open()).to.equal('open');
|
63 | expect(gmp.els).to.be.a("undefined");
|
64 | expect(gmp.init()).to.equals('test');
|
65 | expect($('div').text().trim()).to.equals('zeromike');
|
66 | });
|
67 | }); |
\ | No newline at end of file |