From 1c1da85f7bc51e03896215de4b764f854dc050e9 Mon Sep 17 00:00:00 2001 From: Lehtinen Teemu <lehtint6@t31300-lr146.org.aalto.fi> Date: Tue, 7 Jan 2020 14:37:48 +0200 Subject: [PATCH] Add button event test --- tests/content-tests.js | 74 +++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/tests/content-tests.js b/tests/content-tests.js index 452f5ad..5da5cc1 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(); }); }); -- GitLab