Commit fe5108cd664ca5d7feecd0f1ec6588f2d7134b08

Authored by Sergio Crisostomo
1 parent 9b376832

Add Time-Picker unit tests

Showing 1 changed file with 60 additions and 0 deletions   Show diff stats
test/unit/specs/time-spinner.spec.js 0 → 100644
  1 +import { createVue, destroyVM } from '../util';
  2 +
  3 +describe('TimePicker.vue', () => {
  4 + let vm;
  5 + afterEach(() => {
  6 + destroyVM(vm);
  7 + });
  8 +
  9 + it('should create a TimePicker component with hours, minutes and seconds', done => {
  10 + vm = createVue(`
  11 + <Time-Picker></Time-Picker>
  12 + `);
  13 + const picker = vm.$children[0];
  14 + picker.handleIconClick(); // open the picker panels
  15 +
  16 + vm.$nextTick(() => {
  17 + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list');
  18 + expect(spiners.length).to.equal(3); // hh:mm:ss
  19 + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24);
  20 + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60);
  21 + expect(spiners[2].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60);
  22 + done();
  23 + });
  24 + });
  25 +
  26 + it('should create a TimePicker component with only hours and minutes', done => {
  27 + vm = createVue(`
  28 + <Time-Picker format="HH:mm"></Time-Picker>
  29 + `);
  30 + const picker = vm.$children[0];
  31 + picker.handleIconClick(); // open the picker panels
  32 +
  33 + vm.$nextTick(() => {
  34 + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list');
  35 + expect([...spiners].filter(el => el.style.display != 'none').length).to.equal(2); // hh:mm
  36 + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24);
  37 + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60);
  38 + done();
  39 + });
  40 + });
  41 +
  42 + it('should create a TimePicker component with steps of 15 minutes', done => {
  43 + vm = createVue(`
  44 + <Time-Picker :steps="[1, 15]"></Time-Picker>
  45 + `);
  46 + const picker = vm.$children[0];
  47 + picker.handleIconClick(); // open the picker panels
  48 +
  49 + vm.$nextTick(() => {
  50 + const spiners = picker.$el.querySelectorAll('.ivu-time-picker-cells-list');
  51 + const minutesList = [...spiners[1].querySelectorAll('.ivu-time-picker-cells-cell')];
  52 +
  53 + expect(spiners[0].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(24);
  54 + expect(minutesList.map(el => el.textContent).join(',')).to.equal('00,15,30,45');
  55 + expect(spiners[1].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(4);
  56 + expect(spiners[2].querySelectorAll('.ivu-time-picker-cells-cell').length).to.equal(60);
  57 + done();
  58 + });
  59 + });
  60 +});
... ...