filiph / egamebook

A procedural sword & sorcery adventure
https://egamebook.com/
BSD 3-Clause "New" or "Revised" License
192 stars 21 forks source link

Feature/tests documentation #7

Closed Janamou closed 9 years ago

Janamou commented 9 years ago

Comments/needs to be fixed in order to run the tests.

FormElement

/// Getter for the visibility of the element. This works like CSS [:display:],
/// meaning that when set to [:true:], the element will not occupy its
/// space (there will be no 'white rectange' in the place of a hidden element
/// like with CSS [:visibility:]).
bool get hidden => attributes["hidden"] == "true";

I changed the [:false:] to [:true:] in the comment - because its hidden.

FormSection

Why is this class not named FormSectionBase? Comparing to the functionality in other classes, it has similar functionality as “Base" classes. And for example TextOutput is empty class because TextOutputBase exists. Should not be for FormSection something similar?

README

I updated README with the tool/tester. Can I also mention running through the egamebook.dart and running doc via docgen script?

Tests

Disabled

When I do with test this:

form2.disabled = true;
FormProxy formProxy = new FormProxy.fromMap(form2.toMap());
presenter.showForm(formProxy);

The button is never set to disabled in HTML. This is correct behavior? The reason is that when you are converting from JSONML in FormProxy.fromMap, not all attributes are set (like disabled, hidden etc.).

Disabled in FormProxy

When I then test FormProxy it doesn’t have these attributes set and the test fails:

FormSection section = new FormSection("Test")
    ..children.add(input1)
    ..disabled = true;
form.children.add(section);
Map map = form.toMap();
FormProxy formProxy = new FormProxy.fromMap(map);
print("${formProxy.disabled}"); //THIS RETURNS FALSE - is it CORRECT?
expect((formProxy.children.single as FormSection).disabled, true);

Stripping of HTML tags

When I do this test, the commented part (because it fails) and the second print statement returns text without html. Is this correct behavior? E.g. instead of <p>Initial text.</p> it returns Initial text.:

test("creates text output", () {
      textOutput.html = "<p>Initial text.</p>";
      form.children.add(textOutput);
      form.children.add(input1);

      form.onInput = (_) {
        textOutput.html = "<p>You are currently <strong>${input1.current}"
            "</strong> years old.</p>";
      };

      Map map = form.toMap();
      print(JSON.encode(map));

      FormProxy formProxy = new FormProxy.fromMap(form.toMap());
      Stream<CurrentState> stream = presenter.showForm(formProxy);

      expect((formProxy.children.first as PresenterTextOutput).current,
          textOutput.html);
      print((formProxy.children.first as PresenterTextOutput).current);
      /*expect((formProxy.children.first as PresenterTextOutput).uiElement.current,
          textOutput.html);*/
      print((formProxy.children.first as PresenterTextOutput).uiElement.current);

      stream.listen((CurrentState values) {
        FormConfiguration changedConfig = form.receiveUserInput(values);
        presenter.updateForm(changedConfig);

        ParagraphElement textOutputParagraph = querySelector(
            "#${formProxy.children.first.id} p");
        expect(textOutputParagraph.text, "You are currently 35 years old.");
      });

Competer.complete missing

Method showChoices() never calls completer.complete() and this is the reason why the async tests will not work (because of problem with timeout - changing timeout doesn’t work) - it has to call completer.complete.

Similar problem with showDialog() - it has competer.complete() only in condition so the test expires.

EgbChoice toMapForPresenter()

Map<String, Object> toMapForPresenter() => {
    "string": string,
    "hash": hash,
    "submenu": submenu
  };

doesn’t save also goto and other attributes to the map. Is it correct?

Failing test because of Future already completed

I can’t make work commented part of “Show simple dummy choices” test - when the click() on button is called, the test fails with “Future already completed“. Do you have idea where could be problem?

filiph commented 9 years ago

Hi, amazing work. CIL below. What I don't comment on explicitly, I agree on. When I agree there's a bug, please put it in pivotal so we have one canonical place to track work. Thanks a zillion!

The button is never set to disabled in HTML. This is correct behavior?

That definitely seems like a bug. Well spotted.

When I then test FormProxy it doesn’t have these attributes set and the test fails:

Same here, also a bug.

When I do this test, the commented part (because it fails) and the second print statement returns text without html. Is this correct behavior? E.g. instead of

Initial text.

it returns Initial text.:

I think that's a bug, but please put it as low priority. I think that users shouldn't actually have access to uiElement.html (as it stands behind proxy). But I'll dig into this.

Competer.complete missing

Absolutely. File a bug or feel free to fix if it's a small one and you'd like to.

EgbChoice toMapForPresenter() doesn’t save also goto and other attributes to the map. Is it correct?

That's correct, at least for goto. Presenter shouldn't worry about the value of goto (it doesn't display it) and, in fact, it's better if it doesn't know. For example, it would then be easier to "hack" the game by checking goto attributes of every choice (these are page names, and the author can have internal info in them — something like "Part 3: Death").

There might be a better (type-safe) way to do this (like an intermediate class?) but I don't want to increase complexity of the code by yet another proxy class. If I'm missing some obvious solution, please let me know.

Failing test because of Future already completed

I'll look into it. Can you please file a bug in pivotal against me? Just point me to the file. I don't know when I'll be able to get to it.