From fe5108cd664ca5d7feecd0f1ec6588f2d7134b08 Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Sun, 13 Aug 2017 09:13:08 +0200 Subject: [PATCH] Add Time-Picker unit tests --- test/unit/specs/time-spinner.spec.js | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/unit/specs/time-spinner.spec.js diff --git a/test/unit/specs/time-spinner.spec.js b/test/unit/specs/time-spinner.spec.js new file mode 100644 index 00000000..984255cf --- /dev/null +++ b/test/unit/specs/time-spinner.spec.js @@ -0,0 +1,60 @@ +import { createVue, destroyVM } from '../util'; + +describe('TimePicker.vue', () => { + let vm; + afterEach(() => { + destroyVM(vm); + }); + + it('should create a TimePicker component with hours, minutes and seconds', done => { + vm = createVue(` + + `); + const picker = vm.$children[0]; + picker.handleIconClick(); // open the picker panels + + vm.$nextTick(() => { + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list'); + expect(spiners.length).to.equal(3); // hh:mm:ss + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24); + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60); + expect(spiners[2].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60); + done(); + }); + }); + + it('should create a TimePicker component with only hours and minutes', done => { + vm = createVue(` + + `); + const picker = vm.$children[0]; + picker.handleIconClick(); // open the picker panels + + vm.$nextTick(() => { + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list'); + expect([...spiners].filter(el => el.style.display != 'none').length).to.equal(2); // hh:mm + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24); + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60); + done(); + }); + }); + + it('should create a TimePicker component with steps of 15 minutes', done => { + vm = createVue(` + + `); + const picker = vm.$children[0]; + picker.handleIconClick(); // open the picker panels + + vm.$nextTick(() => { + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list'); + const minutesList = [...spiners[1].querySelectorAll('.ivu-time-picker-cells-cell')]; + + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24); + expect(minutesList.map(el => el.textContent).join(',')).to.equal('00,15,30,45'); + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(4); + expect(spiners[2].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60); + done(); + }); + }); +});