Comparison

spec/util_dataforms_spec.lua @ 9121:e5eb36ee07a2

util.dataforms: Allow passing the current values to be used in stead of omitted fields
author Kim Alvefur <zash@zash.se>
date Sun, 05 Aug 2018 15:50:06 +0200
parent 9083:5d3639e415bd
child 9242:68694c1bd960
comparison
equal deleted inserted replaced
9120:01fc8ba0a7fa 9121:e5eb36ee07a2
345 it("includes options when value is excluded", function () 345 it("includes options when value is excluded", function ()
346 local f = form_with_stuff:form({}); 346 local f = form_with_stuff:form({});
347 assert.truthy(f:find("field/option")); 347 assert.truthy(f:find("field/option"));
348 end); 348 end);
349 end); 349 end);
350
351 describe("using current values in place of missing fields", function ()
352 it("gets back the previous values when given an empty form", function ()
353 local current = {
354 ["list-multi-field"] = {
355 "list-multi-option-value#2";
356 };
357 ["list-single-field"] = "list-single-value#2";
358 ["hidden-field"] = "hidden-value";
359 ["boolean-field"] = false;
360 ["text-multi-field"] = "words\ngo\nhere";
361 ["jid-single-field"] = "alice@example.com";
362 ["text-private-field"] = "hunter2";
363 ["text-single-field"] = "text-single-value";
364 ["jid-multi-field"] = {
365 "bob@example.net";
366 };
367 };
368 local expect = {
369 -- FORM_TYPE = "xmpp:prosody.im/spec/util.dataforms#1"; -- does this need to be included?
370 ["list-multi-field"] = {
371 "list-multi-option-value#2";
372 };
373 ["list-single-field"] = "list-single-value#2";
374 ["hidden-field"] = "hidden-value";
375 ["boolean-field"] = false;
376 ["text-multi-field"] = "words\ngo\nhere";
377 ["jid-single-field"] = "alice@example.com";
378 ["text-private-field"] = "hunter2";
379 ["text-single-field"] = "text-single-value";
380 ["jid-multi-field"] = {
381 "bob@example.net";
382 };
383 };
384 local data, err = some_form:data(st.stanza("x", {xmlns="jabber:x:data"}), current);
385 assert.is.table(data, err);
386 assert.same(expect, data, "got back the same data");
387 end);
388 end);
350 end); 389 end);
351 390