3350-Smart_table_unit_tests #803

Merged
joan merged 6 commits from 3350-Smart_table_unit_tests into dev 2021-11-24 06:42:32 +00:00
3 changed files with 116 additions and 15 deletions
Showing only changes of commit e53af13b3c - Show all commits

View File

@ -54,20 +54,6 @@ export default class SmartTable extends Component {
set viewConfigId(value) {
this._viewConfigId = value;
/* if (value) {
this.defaultViewConfig = {};
const url = 'DefaultViewConfigs';
const filter = {where: {tableCode: value}};
this.$http.get(url, {filter})
.then(res => {
if (res && res.data.length) {
const columns = res.data[0].columns;
this.defaultViewConfig = columns;
}
});
} */
}
getDefaultViewConfig() {
@ -163,7 +149,7 @@ export default class SmartTable extends Component {
}
}
let styleElement = document.querySelector('style[id="smart-table"]');
const styleElement = document.querySelector('style[id="smart-table"]');
if (styleElement)
styleElement.parentNode.removeChild(styleElement);

View File

@ -0,0 +1,97 @@
describe('Component smartTable', () => {
let $element;
let controller;
let $httpBackend;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$element = $compile(`<smart-table></smart-table>`)($rootScope);
controller = $element.controller('smartTable');
}));
afterEach(() => {
$element.remove();
});
describe('options setter()', () => {
it(`should throw an error if the table doesn't have an identifier`, () => {
const options = {activeButtons: {shownColumns: []}};
expect(() => controller.options = options).toThrowError(/View identifier not defined/);
});
it('should not throw an error if the table does have an identifier', () => {
const options = {activeButtons: {shownColumns: []}};
controller.viewConfigId = 'test';
expect(() => controller.options = options).not.toThrow();
});
});
describe('getDefaultViewConfig()', () => {
it('should perform a query and return the default view columns', done => {
const expectedResponse = [{
columns: {}
}];
$httpBackend.expectGET('DefaultViewConfigs').respond(expectedResponse);
controller.getDefaultViewConfig().then(columns => {
expect(columns).toEqual(expectedResponse[0].columns);
done();
}).catch(done.fail);
$httpBackend.flush();
});
});
describe('viewConfig setter', () => {
it('should just call applyViewConfig() if a viewConfig was provided', () => {
spyOn(controller, 'applyViewConfig');
controller.viewConfig = [{}];
expect(controller.applyViewConfig).toHaveBeenCalled();
});
it('should not get a defaultConfig then insert a new one', () => {
spyOn(controller, 'applyViewConfig');
controller.$.userViewModel = {
insert: jest.fn()
};
const emptyResponse = [{
columns: {}
}];
controller.columns = [
{field: 'test1'},
{field: 'test2'}
];
$httpBackend.expectGET('DefaultViewConfigs').respond(emptyResponse);
controller.viewConfig = [];
$httpBackend.flush();
const expectedObject = {configuration: {'test1': true, 'test2': true}};
expect(controller.$.userViewModel.insert).toHaveBeenCalledWith(expect.objectContaining(expectedObject));
expect(controller.applyViewConfig).toHaveBeenCalled();
});
});
describe('applyViewConfig()', () => {
it('should ', () => {
controller.$.userViewModel = {
viewConfig: {'test1': true, 'test2': false}
};
controller._columns = [
{field: 'test1'},
{field: 'test2'}
];
controller.applyViewConfig();
});
});
});

View File

@ -123,6 +123,24 @@ describe('Component vnMonitorSalesTickets', () => {
});
});
describe('dateRange()', () => {
it('should return two dates with the hours at the start and end of the given date', () => {
const now = new Date();
const today = now.getDate();
const dateRange = controller.dateRange(now);
const start = dateRange[0].toString();
const end = dateRange[1].toString();
expect(start).toContain(today);
expect(start).toContain('00:00:00');
expect(end).toContain(today);
expect(end).toContain('23:59:59');
});
});
describe('preview()', () => {
it('should show the dialog summary', () => {
controller.$.summary = {show: () => {}};