Skip to content

Commit d2c786d

Browse files
author
Joscha Rohmann
committed
Added Tests for new options behaviour.
1 parent a43764d commit d2c786d

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

test/spec/query/queries.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,126 @@
832832
expect($('#testElement').children().eq(2)).toHaveText('Mihaela');
833833
expect($('#testElement').children().eq(2)).toHaveValue('2');
834834
});
835+
836+
it('updates correctly text and value after reset', function () {
837+
setQuery('options(items, options)');
838+
839+
var items = blocks.observable([
840+
{
841+
Id: 0,
842+
Name: blocks.observable('Joscha')
843+
},
844+
{
845+
Id: 1,
846+
Name: blocks.observable('Unknown')
847+
}]
848+
);
849+
850+
query({
851+
items: items,
852+
options: {
853+
text: 'Name',
854+
value: 'Id'
855+
}
856+
});
857+
858+
expect($('#testElement').children().eq(0)).toHaveText('Joscha');
859+
expect($('#testElement').children().eq(0)).toHaveValue('0');
860+
expect($('#testElement').children().eq(1)).toHaveText('Unknown');
861+
expect($('#testElement').children().eq(1)).toHaveValue('1');
862+
863+
items.reset([{
864+
Id: 0,
865+
Name: blocks.observable('Someone else')
866+
}]);
867+
868+
expect($('#testElement').children.length).toBe(2);
869+
870+
expect($('#testElement').children().eq(0)).toHaveText('Someone else');
871+
expect($('#testElement').children().eq(0)).toHaveValue('0');
872+
873+
});
874+
875+
it('updates selected correctly after reset', function () {
876+
setQuery('options(items, options).val(val)');
877+
878+
var items = blocks.observable([
879+
{
880+
Id: 0,
881+
Name: blocks.observable('Joscha')
882+
},
883+
{
884+
Id: 1,
885+
Name: blocks.observable('Unknown')
886+
}]
887+
);
888+
889+
var val = blocks.observable('1');
890+
query({
891+
val: val,
892+
items: items,
893+
options: {
894+
text: 'Name',
895+
value: 'Id'
896+
}
897+
});
898+
899+
expect($('#testElement').children().eq(0)).toHaveText('Joscha');
900+
expect($('#testElement').children().eq(0)).toHaveValue('0');
901+
expect($('#testElement').children().eq(1)).toHaveText('Unknown');
902+
expect($('#testElement').children().eq(1)).toHaveValue('1');
903+
904+
items.reset([{
905+
Id: 0,
906+
Name: blocks.observable('Someone else')
907+
}]);
908+
909+
expect(val()).toBe('0');
910+
911+
expect($('#testElement').children().eq(0)).toHaveText('Someone else');
912+
expect($('#testElement').children().eq(0)).toHaveValue('0');
913+
});
914+
915+
it('updates selected correctly after reset to the caption', function () {
916+
setQuery('options(items, options).val(val)');
917+
918+
var items = blocks.observable([
919+
{
920+
Id: 0,
921+
Name: blocks.observable('Joscha')
922+
},
923+
{
924+
Id: 1,
925+
Name: blocks.observable('Unknown')
926+
}]
927+
);
928+
929+
var val = blocks.observable('1');
930+
query({
931+
val: val,
932+
items: items,
933+
options: {
934+
caption: 'select something',
935+
text: 'Name',
936+
value: 'Id'
937+
}
938+
});
939+
940+
expect($('#testElement').children().eq(1)).toHaveText('Joscha');
941+
expect($('#testElement').children().eq(1)).toHaveValue('0');
942+
expect($('#testElement').children().eq(2)).toHaveText('Unknown');
943+
expect($('#testElement').children().eq(2)).toHaveValue('1');
944+
945+
items.reset([{
946+
Id: 0,
947+
Name: blocks.observable('Someone else')
948+
}]);
949+
950+
expect(val()).toBe('select something');
951+
952+
expect($('#testElement').children().eq(0)).toHaveText('select something');
953+
expect($('#testElement').children().eq(0)).toHaveValue('select something');
954+
});
835955
});
836956

837957
describe('blocks.queries.template', function () {

0 commit comments

Comments
 (0)