Merge pull request 'field unit test + jest and babel-jest versions upgraded + readme update' (#322) from 2185_field_unit_tests into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-06-23 07:19:19 +00:00
commit c600576b7a
4 changed files with 7208 additions and 1135 deletions

View File

@ -13,8 +13,15 @@ Required applications.
You will need to install globally the following items.
```
# sudo npm install -g jest gulp-cli
$ sudo npm install -g jest gulp-cli
```
For the usage of jest --watch on macOs.
```
$ brew install watchman
```
* [watchman](https://facebook.github.io/watchman/)
## Linux Only Prerequisites
Your user must be on the docker group to use it so you will need to run this command:

View File

@ -1,6 +1,6 @@
describe('Component vnField', () => {
let $element;
let controller;
let $element;
beforeEach(ngModule('vnCore'));
@ -13,12 +13,84 @@ describe('Component vnField', () => {
$element.remove();
});
// Remove this block
describe('clearDisabled binding', () => {
it(`should enable the show property`, () => {
controller.clearDisabled = true;
describe('field get/set', () => {
it('should do nothing when trying to set the same value again', () => {
controller.field = '';
jest.spyOn(controller, 'validateValue');
expect(controller.clearDisabled).toEqual(true);
controller.field = '';
expect(controller.validateValue).toHaveBeenCalledTimes(0);
expect(controller.classList).not.toContain('not-empty');
});
it('should add the class no empty and then call validateValue()', () => {
controller.field = '';
jest.spyOn(controller, 'validateValue');
controller.field = 'someField';
expect(controller.validateValue).toHaveBeenCalledTimes(1);
expect(controller.classList).toContain('not-empty');
});
});
describe('refreshHint()', () => {
it('should add the class invalid if there is an error in the controller', () => {
controller._error = true;
controller.refreshHint();
expect(controller.classList).toContain('invalid');
});
});
describe('onFocus()', () => {
it('should add the class focus', () => {
controller.onFocus(true);
expect(controller.classList).toContain('focused');
});
it('should not add the class focus', () => {
controller.onFocus(false);
expect(controller.classList).not.toContain('focuses');
});
});
describe('buildInput()', () => {
it('should build an input based on the received type', () => {
controller.buildInput('number');
expect(controller.input.tagName).toEqual('INPUT');
expect(controller.input.type).toEqual('number');
});
});
describe('validateValue()', () => {
it('should do nothing if there is no new error to show', () => {
jest.spyOn(controller, 'refreshHint');
controller.inputError = 'old validation message';
controller.buildInput('number');
controller.input.setCustomValidity('old validation message');
controller.validateValue();
expect(controller.refreshHint).not.toHaveBeenCalled();
expect(controller.inputError).toEqual('old validation message');
});
it('should update the input error and call refreshHint', () => {
jest.spyOn(controller, 'refreshHint');
controller.inputError = 'OLD validation message';
controller.buildInput('number');
controller.input.setCustomValidity('NEW validation message');
controller.validateValue();
expect(controller.refreshHint).toHaveBeenCalled();
expect(controller.inputError).toEqual('NEW validation message');
});
});
});

8188
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
"@babel/preset-env": "^7.7.7",
"@babel/register": "^7.7.7",
"angular-mocks": "^1.7.9",
"babel-jest": "^24.9.0",
"babel-jest": "^26.0.1",
"babel-loader": "^8.0.6",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^2.1.0",
@ -70,7 +70,7 @@
"jasmine": "^3.5.0",
"jasmine-reporters": "^2.3.2",
"jasmine-spec-reporter": "^4.2.1",
"jest": "^24.9.0",
"jest": "^26.0.1",
"jest-junit": "^8.0.0",
"json-loader": "^0.5.7",
"merge-stream": "^1.0.1",