diff --git a/tests/content-tests.js b/tests/content-tests.js index 452f5ad8b7ad4152032942d25a1fc06635214119..5da5cc141e97efba5da74a3f35da8376e7a0a4f1 100644 --- a/tests/content-tests.js +++ b/tests/content-tests.js @@ -1,6 +1,25 @@ let chai = require('chai'); chai.should(); +function PointsContent(browser) { + let points = browser.$$('.guide-column .points'); + points.should.have.lengthOf(1); + return { + text: points[0].getText(), + class: points[0].getAttribute('class'), + isZero: function () { + this.text.should.contain('0 / 10'); + this.text.should.not.contain('10 / 10'); + this.class.should.not.contain('yellow'); + this.class.should.not.contain('green'); + }, + isInitial: function () { + this.isZero(); + this.class.should.not.contain('red'); + } + }; +} + describe('Content module acos-webdev-inspector', () => { describe('Frontpage block', () => { @@ -18,6 +37,32 @@ describe('Content module acos-webdev-inspector', () => { }); + describe('Exercise click_for_points', () => { + + it('exercise page should open', () => { + browser.url('/html/webdev/webdev-inspector/fix_typo'); + browser.waitUntil(() => $('.instructions').getText().length > 0, 4000, 'expected instructions to appear'); + }); + + it('should start with zero grade', () => { + PointsContent(browser).isInitial(); + }); + + it('should include button and click it', () => { + let button = browser.$$('.exercise button'); + button.should.have.lengthOf(1); + button.click(); + browser.waitUntil(() => $$('.explosion').length == 0, 4000, 'expected explosion effect to pass'); + }); + + it('should now display full grade', () => { + let points = PointsContent(browser); + points.text.should.contain('10 / 10'); + points.class.should.contain('green'); + }); + + }); + describe('Exercise fix_typo', () => { it('exercise page should open', () => { @@ -25,10 +70,7 @@ describe('Content module acos-webdev-inspector', () => { }); it('should start with zero grade', () => { - let points = browser.$$('.guide-column .points'); - points.should.have.lengthOf(1); - points[0].getText().should.contain('0 / 10'); - points[0].getText().should.not.contain('10 / 10'); + PointsContent(browser).isInitial(); }); it('should include text paragraph', () => { @@ -45,11 +87,10 @@ describe('Content module acos-webdev-inspector', () => { }); it('should now display half grade', () => { - let points = browser.$$('.guide-column .points'); - points.should.have.lengthOf(1); - points[0].getText().should.contain('5 / 10'); - points[0].getAttribute('class').should.contain('yellow'); - points[0].getAttribute('class').should.not.contain('green'); + let points = PointsContent(browser); + points.text.should.contain('5 / 10'); + points.class.should.contain('yellow'); + points.class.should.not.contain('green'); }); it('fix text', () => { @@ -60,11 +101,10 @@ describe('Content module acos-webdev-inspector', () => { }); it('should now display full grade', () => { - let points = browser.$$('.guide-column .points'); - points.should.have.lengthOf(1); - points[0].getText().should.contain('10 / 10'); - points[0].getAttribute('class').should.contain('green'); - points[0].getAttribute('class').should.not.contain('yellow'); + let points = PointsContent(browser); + points.text.should.contain('10 / 10'); + points.class.should.contain('green'); + points.class.should.not.contain('yellow'); }); it('reset button should exist and be clicked', () => { @@ -80,11 +120,7 @@ describe('Content module acos-webdev-inspector', () => { let p = browser.$$('.exercise p'); p.should.have.lengthOf(1); p[0].getText().should.equal('Hello Wordl!'); - let points = browser.$$('.guide-column .points'); - points.should.have.lengthOf(1); - points[0].getText().should.contain('0 / 10'); - points[0].getText().should.not.contain('10 / 10'); - points[0].getAttribute('class').should.not.contain('green'); + PointsContent(browser).isInitial(); }); });