mirror of
https://github.com/ansible/awx.git
synced 2026-01-24 16:01:20 -03:30
add unit test for file input component
This commit is contained in:
parent
cc8b5bc808
commit
5baa371739
@ -21,7 +21,7 @@ function AtInputFileController (baseInputController, eventService) {
|
||||
baseInputController.call(vm, 'input', _scope_, element, form);
|
||||
|
||||
scope = _scope_;
|
||||
[input] = element.find('input');
|
||||
input = element.find('input')[0]; // eslint-disable-line prefer-destructuring
|
||||
|
||||
vm.listeners = vm.setFileListeners(input);
|
||||
|
||||
|
||||
@ -22,8 +22,8 @@ function AtModalController (eventService, strings) {
|
||||
vm.strings = strings;
|
||||
|
||||
vm.init = (scope, el) => {
|
||||
[overlay] = el;
|
||||
[modal] = el.find('.at-Modal-window');
|
||||
overlay = el[0]; // eslint-disable-line prefer-destructuring
|
||||
modal = el.find('.at-Modal-window')[0]; // eslint-disable-line prefer-destructuring
|
||||
|
||||
vm.modal = scope[scope.ns].modal;
|
||||
vm.modal.show = vm.show;
|
||||
|
||||
61
awx/ui/test/unit/components/file.unit.js
Normal file
61
awx/ui/test/unit/components/file.unit.js
Normal file
@ -0,0 +1,61 @@
|
||||
describe('Components | Input | File', () => {
|
||||
let $scope;
|
||||
let element;
|
||||
let state;
|
||||
let controller;
|
||||
|
||||
const getMockFileEvent = file => ({ target: { files: [file] } });
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('at.lib.services');
|
||||
angular.mock.module('at.lib.components');
|
||||
});
|
||||
|
||||
describe('AtInputFileController', () => {
|
||||
beforeEach(angular.mock.inject(($rootScope, $compile) => {
|
||||
const component = '<at-input-file id="unit" state="vm.form.unit"></at-input-file>';
|
||||
const dom = angular.element(`<at-form state="vm.form">${component}</at-form>`);
|
||||
|
||||
$scope = $rootScope.$new();
|
||||
$scope.vm = { form: { disabled: false, unit: {} } };
|
||||
|
||||
$compile(dom)($scope);
|
||||
$scope.$digest();
|
||||
|
||||
element = dom.find('#unit');
|
||||
state = $scope.vm.form.unit;
|
||||
controller = element.controller('atInputFile');
|
||||
}));
|
||||
|
||||
it('should initialize without a value by default', () => {
|
||||
expect(state._value).not.toBeDefined();
|
||||
expect(state._displayValue).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should update display value with file name when file is read', () => {
|
||||
const name = 'notavirus.exe';
|
||||
const reader = { result: 'AAAAAAA' };
|
||||
|
||||
controller.check = jasmine.createSpy('check');
|
||||
|
||||
controller.readFile(reader, getMockFileEvent({ name }));
|
||||
|
||||
$scope.$digest();
|
||||
|
||||
expect(state._value).toBeDefined();
|
||||
expect(state._displayValue).toEqual(name);
|
||||
|
||||
expect(controller.check).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should notify handler on file input change event', () => {
|
||||
controller.handleFileChangeEvent = jasmine.createSpy('handleFileChangeEvent');
|
||||
|
||||
element.find('input')[0].dispatchEvent(new Event('change'));
|
||||
|
||||
$scope.$digest();
|
||||
|
||||
expect(controller.handleFileChangeEvent).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -2,6 +2,7 @@
|
||||
import 'angular-mocks';
|
||||
|
||||
// Import tests
|
||||
import './file.unit';
|
||||
import './layout.unit';
|
||||
import './side-nav.unit';
|
||||
import './side-nav-item.unit';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user