Convert progress-status.spec.js to typescript

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-01-15 23:03:37 +01:00 committed by Alexis Svinartchouk
parent 2b3c84f21a
commit 914a4574de
2 changed files with 150 additions and 115 deletions

View File

@ -1,115 +0,0 @@
'use strict'
const m = require('mochainon')
// eslint-disable-next-line node/no-missing-require
const settings = require('../../../lib/gui/app/models/settings')
// eslint-disable-next-line node/no-missing-require
const progressStatus = require('../../../lib/gui/app/modules/progress-status')
describe('Browser: progressStatus', function () {
describe('.fromFlashState()', function () {
beforeEach(function () {
this.state = {
flashing: 1,
verifying: 0,
successful: 0,
failed: 0,
percentage: 0,
eta: 15,
speed: 100000000000000
}
settings.set('unmountOnSuccess', true)
settings.set('validateWriteOnSuccess', true)
})
it('should report 0% if percentage == 0 but speed != 0', function () {
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('0% Flashing')
})
it('should handle percentage == 0, flashing, unmountOnSuccess', function () {
this.state.speed = 0
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Starting...')
})
it('should handle percentage == 0, flashing, !unmountOnSuccess', function () {
this.state.speed = 0
settings.set('unmountOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Starting...')
})
it('should handle percentage == 0, verifying, unmountOnSuccess', function () {
this.state.speed = 0
this.state.flashing = 0
this.state.verifying = 1
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Validating...')
})
it('should handle percentage == 0, verifying, !unmountOnSuccess', function () {
this.state.speed = 0
this.state.flashing = 0
this.state.verifying = 1
settings.set('unmountOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Validating...')
})
it('should handle percentage == 50, flashing, unmountOnSuccess', function () {
this.state.percentage = 50
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('50% Flashing')
})
it('should handle percentage == 50, flashing, !unmountOnSuccess', function () {
this.state.percentage = 50
settings.set('unmountOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('50% Flashing')
})
it('should handle percentage == 50, verifying, unmountOnSuccess', function () {
this.state.flashing = 0
this.state.verifying = 1
this.state.percentage = 50
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('50% Validating')
})
it('should handle percentage == 50, verifying, !unmountOnSuccess', function () {
this.state.flashing = 0
this.state.verifying = 1
this.state.percentage = 50
settings.set('unmountOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('50% Validating')
})
it('should handle percentage == 100, flashing, unmountOnSuccess, validateWriteOnSuccess', function () {
this.state.percentage = 100
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Finishing...')
})
it('should handle percentage == 100, flashing, unmountOnSuccess, !validateWriteOnSuccess', function () {
this.state.percentage = 100
settings.set('validateWriteOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Unmounting...')
})
it('should handle percentage == 100, flashing, !unmountOnSuccess, !validateWriteOnSuccess', function () {
this.state.percentage = 100
settings.set('unmountOnSuccess', false)
settings.set('validateWriteOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Finishing...')
})
it('should handle percentage == 100, verifying, unmountOnSuccess', function () {
this.state.flashing = 0
this.state.verifying = 1
this.state.percentage = 100
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Unmounting...')
})
it('should handle percentage == 100, validatinf, !unmountOnSuccess', function () {
this.state.flashing = 0
this.state.verifying = 1
this.state.percentage = 100
settings.set('unmountOnSuccess', false)
m.chai.expect(progressStatus.fromFlashState(this.state)).to.equal('Finishing...')
})
})
})

View File

@ -0,0 +1,150 @@
/*
* Copyright 2020 balena.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from 'chai';
import * as settings from '../../../lib/gui/app/models/settings';
import * as progressStatus from '../../../lib/gui/app/modules/progress-status';
describe('Browser: progressStatus', function() {
describe('.fromFlashState()', function() {
beforeEach(function() {
this.state = {
flashing: 1,
verifying: 0,
successful: 0,
failed: 0,
percentage: 0,
eta: 15,
speed: 100000000000000,
};
settings.set('unmountOnSuccess', true);
settings.set('validateWriteOnSuccess', true);
});
it('should report 0% if percentage == 0 but speed != 0', function() {
expect(progressStatus.fromFlashState(this.state)).to.equal('0% Flashing');
});
it('should handle percentage == 0, flashing, unmountOnSuccess', function() {
this.state.speed = 0;
expect(progressStatus.fromFlashState(this.state)).to.equal('Starting...');
});
it('should handle percentage == 0, flashing, !unmountOnSuccess', function() {
this.state.speed = 0;
settings.set('unmountOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal('Starting...');
});
it('should handle percentage == 0, verifying, unmountOnSuccess', function() {
this.state.speed = 0;
this.state.flashing = 0;
this.state.verifying = 1;
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Validating...',
);
});
it('should handle percentage == 0, verifying, !unmountOnSuccess', function() {
this.state.speed = 0;
this.state.flashing = 0;
this.state.verifying = 1;
settings.set('unmountOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Validating...',
);
});
it('should handle percentage == 50, flashing, unmountOnSuccess', function() {
this.state.percentage = 50;
expect(progressStatus.fromFlashState(this.state)).to.equal(
'50% Flashing',
);
});
it('should handle percentage == 50, flashing, !unmountOnSuccess', function() {
this.state.percentage = 50;
settings.set('unmountOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'50% Flashing',
);
});
it('should handle percentage == 50, verifying, unmountOnSuccess', function() {
this.state.flashing = 0;
this.state.verifying = 1;
this.state.percentage = 50;
expect(progressStatus.fromFlashState(this.state)).to.equal(
'50% Validating',
);
});
it('should handle percentage == 50, verifying, !unmountOnSuccess', function() {
this.state.flashing = 0;
this.state.verifying = 1;
this.state.percentage = 50;
settings.set('unmountOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'50% Validating',
);
});
it('should handle percentage == 100, flashing, unmountOnSuccess, validateWriteOnSuccess', function() {
this.state.percentage = 100;
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Finishing...',
);
});
it('should handle percentage == 100, flashing, unmountOnSuccess, !validateWriteOnSuccess', function() {
this.state.percentage = 100;
settings.set('validateWriteOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Unmounting...',
);
});
it('should handle percentage == 100, flashing, !unmountOnSuccess, !validateWriteOnSuccess', function() {
this.state.percentage = 100;
settings.set('unmountOnSuccess', false);
settings.set('validateWriteOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Finishing...',
);
});
it('should handle percentage == 100, verifying, unmountOnSuccess', function() {
this.state.flashing = 0;
this.state.verifying = 1;
this.state.percentage = 100;
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Unmounting...',
);
});
it('should handle percentage == 100, validatinf, !unmountOnSuccess', function() {
this.state.flashing = 0;
this.state.verifying = 1;
this.state.percentage = 100;
settings.set('unmountOnSuccess', false);
expect(progressStatus.fromFlashState(this.state)).to.equal(
'Finishing...',
);
});
});
});