mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 09:48:51 -03:30
Update unit tests.
This commit is contained in:
@@ -1,101 +1,97 @@
|
|||||||
import StreamService from '~features/output/stream.service';
|
import StreamService from '~features/output/stream.service';
|
||||||
|
|
||||||
describe('Output | StreamService', () => {
|
describe('Output | StreamService', () => {
|
||||||
angular.module('test', []).service('StreamService', StreamService);
|
angular.module('test', []).service('StreamService', StreamService);
|
||||||
let stream;
|
let stream;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
angular.mock.module('test');
|
angular.mock.module('test');
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(($injector) => {
|
|
||||||
stream = $injector.get('StreamService');
|
|
||||||
|
|
||||||
const onFrames = angular.noop;
|
|
||||||
const onFrameRate = angular.noop;
|
|
||||||
|
|
||||||
stream.init({ onFrames, onFrameRate });
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('calcFactors', () => {
|
|
||||||
it('returns the expected values', () => {
|
|
||||||
const params = [
|
|
||||||
[-1, [1]],
|
|
||||||
[0, [1]],
|
|
||||||
[1, [1]],
|
|
||||||
[1.0, [1]],
|
|
||||||
[1.1, [1]],
|
|
||||||
[2, [1, 2]],
|
|
||||||
['1', [1]],
|
|
||||||
[{}, [1]],
|
|
||||||
[null, [1]],
|
|
||||||
[undefined, [1]],
|
|
||||||
[250, [1, 2, 5, 10, 25, 50, 125, 250]]
|
|
||||||
];
|
|
||||||
|
|
||||||
params.forEach(([size, expected]) => expect(stream.calcFactors(size)).toEqual(expected));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('setMissingCounterThreshold', () => {
|
|
||||||
it('returns the correct counter threshold', () => {
|
|
||||||
const gt = 2;
|
|
||||||
stream.setMissingCounterThreshold(gt);
|
|
||||||
expect(stream.counters.min).toEqual(gt);
|
|
||||||
|
|
||||||
const lt = -1;
|
|
||||||
stream.setMissingCounterThreshold(lt);
|
|
||||||
expect(stream.counters.min).toEqual(gt);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isReadyToRender', () => {
|
|
||||||
it('returns false', () => {
|
|
||||||
const res = stream.isReadyToRender();
|
|
||||||
expect(res).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns true', () => {
|
beforeEach(angular.mock.inject(($injector) => {
|
||||||
stream.counters.min = 1;
|
stream = $injector.get('StreamService');
|
||||||
stream.counters.ready = 2;
|
|
||||||
stream.state.ending = true;
|
|
||||||
let res = stream.isReadyToRender();
|
|
||||||
expect(res).toBe(true);
|
|
||||||
|
|
||||||
stream.counters.total = 1;
|
const onFrames = angular.noop;
|
||||||
stream.framesPerRender = 1;
|
const onFrameRate = angular.noop;
|
||||||
|
|
||||||
res = stream.isReadyToRender();
|
stream.init({ onFrames, onFrameRate });
|
||||||
expect(res).toBe(true);
|
}));
|
||||||
|
|
||||||
|
describe('calcFactors', () => {
|
||||||
|
it('returns the expected values', () => {
|
||||||
|
const params = [
|
||||||
|
[-1, [1]],
|
||||||
|
[0, [1]],
|
||||||
|
[1, [1]],
|
||||||
|
[1.0, [1]],
|
||||||
|
[1.1, [1]],
|
||||||
|
[2, [1, 2]],
|
||||||
|
['1', [1]],
|
||||||
|
[{}, [1]],
|
||||||
|
[null, [1]],
|
||||||
|
[undefined, [1]],
|
||||||
|
[250, [1, 2, 5, 10, 25, 50, 125, 250]]
|
||||||
|
];
|
||||||
|
|
||||||
|
params.forEach(([size, expected]) =>
|
||||||
|
expect(stream.calcFactors(size)).toEqual(expected));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('getMaxCounter', () => {
|
describe('setMissingCounterThreshold', () => {
|
||||||
it('returns the same value as max counter', () => {
|
it('returns the correct counter threshold', () => {
|
||||||
const res = stream.getMaxCounter();
|
const gt = 2;
|
||||||
expect(res).toEqual(stream.counters.max);
|
stream.setMissingCounterThreshold(gt);
|
||||||
});
|
expect(stream.counters.min).toEqual(gt);
|
||||||
});
|
|
||||||
|
|
||||||
describe('getReadyCount', () => {
|
const lt = -1;
|
||||||
it('references min and max counters', () => {
|
stream.setMissingCounterThreshold(lt);
|
||||||
expect(stream.getReadyCount()).toEqual(stream.counters.max - stream.counters.min + 1);
|
expect(stream.counters.min).toEqual(gt);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('returns expected values if min or max value is a non-integer', () => {
|
|
||||||
const params = [
|
|
||||||
[null, 1, 0],
|
|
||||||
[undefined, 1, NaN],
|
|
||||||
['1', 1, 1],
|
|
||||||
[-1, -3, 3],
|
|
||||||
[0, 0, 1],
|
|
||||||
[6, 5, 2]
|
|
||||||
];
|
|
||||||
|
|
||||||
params.forEach(([x, y, z]) => {
|
describe('isReadyToRender', () => {
|
||||||
stream.counters.ready = x;
|
it("it's never ready to render unless the result of getReadyCount is greater than 0", () => {
|
||||||
stream.counters.min = y;
|
const params = [
|
||||||
expect(stream.getReadyCount()).toEqual(z);
|
[-1, false],
|
||||||
});
|
[0, false],
|
||||||
|
[1, true]
|
||||||
|
];
|
||||||
|
const spy = spyOn(stream, 'getReadyCount');
|
||||||
|
|
||||||
|
params.forEach(([readyCount, expected]) => {
|
||||||
|
spy.and.returnValue(readyCount);
|
||||||
|
expect(stream.isReadyToRender()).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getMaxCounter', () => {
|
||||||
|
it('returns the same value as max counter', () => {
|
||||||
|
const res = stream.getMaxCounter();
|
||||||
|
expect(res).toEqual(stream.counters.max);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getReadyCount', () => {
|
||||||
|
it('references min and max counters', () => {
|
||||||
|
expect(stream.getReadyCount()).toEqual(stream.counters.max - stream.counters.min + 1);
|
||||||
|
});
|
||||||
|
it('returns expected values if min or max value is a non-integer', () => {
|
||||||
|
const params = [
|
||||||
|
[null, 1, 0],
|
||||||
|
[undefined, 1, NaN],
|
||||||
|
['1', 1, 1],
|
||||||
|
[-1, -3, 3],
|
||||||
|
[0, 0, 1],
|
||||||
|
[6, 5, 2]
|
||||||
|
];
|
||||||
|
|
||||||
|
params.forEach(([max, min, expected]) => {
|
||||||
|
stream.counters.ready = max;
|
||||||
|
stream.counters.min = min;
|
||||||
|
expect(stream.getReadyCount()).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user