Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman committed Apr 12, 2024
1 parent fdef3ff commit b8e8ad0
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 121 deletions.
120 changes: 120 additions & 0 deletions src/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'power-assert';
import Harness from '../test/harness';
import WebformBuilder from './WebformBuilder';
import Builders from './builders';
import { Formio } from './Formio';
import { uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, columnsForm, resourceKeyCamelCase } from '../test/formtest';
import sameApiKeysLayoutComps from '../test/forms/sameApiKeysLayoutComps';
import testApiKeysUniquifying from '../test/forms/testApiKeysUniquifying';
Expand Down Expand Up @@ -269,3 +270,122 @@ describe('WebformBuilder tests', function() {
}).catch(done);
});
});

describe('Select Component selectData property', () => {
const originalMakeRequest = Formio.makeRequest;

before((done) => {
Formio.makeRequest = () => {
return new Promise(resolve => {
const values = [{
label: 'Label 1',
value: 'value1',
}, {
label: 'Label 2',
value: 'value2',
}];

resolve(values);
});
};
Harness.builderBefore(done);
});
afterEach(() => Harness.getBuilder().setForm({ display: 'form', components: [] }));

it('Should calculate selectData property for url dataSource', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('url');
const url = builder.editForm.getComponent(['data.url']);
const valueProperty = builder.editForm.getComponent('valueProperty');
url.setValue('htts//fakeurl.com');
valueProperty.setValue('value');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.deepEqual(builder.editForm.data.selectData, {
label: 'Label 1',
});
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

it('Should calculate selectData property for resource dataSource', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('resource');
const resource = builder.editForm.getComponent(['data.resource']);
const valueProperty = builder.editForm.getComponent('valueProperty');
resource.setValue('12345678');
valueProperty.setValue('value');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.deepEqual(builder.editForm.data.selectData, {
label: 'Label 1',
});
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

it('Should not calculate selectData property without valueProperty', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('url');
const url = builder.editForm.getComponent(['data.url']);
url.setValue('https://fakeurl.com');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.equal(builder.editForm.data.selectData, undefined);
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

after((done) => {
Formio.makeRequest = originalMakeRequest;
Harness.builderAfter(done);
});
});
121 changes: 0 additions & 121 deletions src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { expect } from 'chai';
import { Formio } from './../../Formio';
import _ from 'lodash';

global.requestAnimationFrame = (cb) => cb();
global.cancelAnimationFrame = () => { };

import {
comp1,
comp2,
Expand Down Expand Up @@ -1216,121 +1213,3 @@ describe('Select Component with Entire Object Value Property', () => {
});
});

describe('Select Component selectData property', () => {
const originalMakeRequest = Formio.makeRequest;

before((done) => {
Formio.makeRequest = (formio, type, url) => {
return new Promise(resolve => {
const values = [{
label: 'Label 1',
value: 'value1',
}, {
label: 'Label 2',
value: 'value2',
}];

resolve(values);
});
};
Harness.builderBefore(done);
});
afterEach(() => Harness.getBuilder().setForm({ display: 'form', components: [] }));

it('Should calculate selectData property for url dataSource', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('url');
const url = builder.editForm.getComponent(['data.url']);
const valueProperty = builder.editForm.getComponent('valueProperty');
url.setValue('htts//fakeurl.com');
valueProperty.setValue('value');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.deepEqual(builder.editForm.data.selectData, {
label: 'Label 1',
});
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

it('Should calculate selectData property for resource dataSource', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('resource');
const resource = builder.editForm.getComponent(['data.resource']);
const valueProperty = builder.editForm.getComponent('valueProperty');
resource.setValue('12345678');
valueProperty.setValue('value');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.deepEqual(builder.editForm.data.selectData, {
label: 'Label 1',
});
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

it('Should not calculate selectData property without valueProperty', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('select');

setTimeout(() => {
const dataSrc = builder.editForm.getComponent('dataSrc');
dataSrc.setValue('url');
const url = builder.editForm.getComponent(['data.url']);
url.setValue('https://fakeurl.com');

setTimeout(() => {
const defaultValue = builder.editForm.getComponent('defaultValue');
defaultValue.setValue('value1');
defaultValue.updateItems(null, true);

setTimeout(() => {
assert.equal(builder.editForm.data.selectData, undefined);
Harness.saveComponent();
setTimeout(() => {
done();
}, 150);
}, 250);
}, 250);
}, 150);
}).catch(done);
});

after((done) => {
Formio.makeRequest = originalMakeRequest;
Harness.builderAfter(done);
});
});

0 comments on commit b8e8ad0

Please sign in to comment.