summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_todolist.js
blob: dac26d2be1ea6ad34db423f1f004ce5a851fa8ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const { TodoList, TodoEntry, getDefaultList, setDefaultList } =
  ChromeUtils.importESModule("resource://gre/modules/RustTodolist.sys.mjs");

add_task(async function () {
  const todo = await TodoList.init();
  const entry = new TodoEntry("Write bindings for strings in records");

  await todo.addItem("Write JS bindings");
  Assert.equal(await todo.getLast(), "Write JS bindings");

  await todo.addItem("Write tests for bindings");
  Assert.equal(await todo.getLast(), "Write tests for bindings");

  await todo.addEntry(entry);
  Assert.equal(await todo.getLast(), "Write bindings for strings in records");
  Assert.equal(
    (await todo.getLastEntry()).text,
    "Write bindings for strings in records"
  );
  Assert.ok((await todo.getLastEntry()).equals(entry));

  await todo.addItem(
    "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣"
  );
  Assert.equal(
    await todo.getLast(),
    "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣"
  );

  const entry2 = new TodoEntry(
    "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣"
  );
  await todo.addEntry(entry2);
  Assert.equal(
    (await todo.getLastEntry()).text,
    "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣"
  );

  const todo2 = await TodoList.init();
  Assert.notEqual(todo, todo2);
  Assert.notStrictEqual(todo, todo2);

  Assert.strictEqual(await getDefaultList(), null);

  await setDefaultList(todo);
  Assert.deepEqual(
    await todo.getItems(),
    await (await getDefaultList()).getItems()
  );

  todo2.makeDefault();
  Assert.deepEqual(
    await todo2.getItems(),
    await (await getDefaultList()).getItems()
  );

  await todo.addItem("Test liveness after being demoted from default");
  Assert.equal(
    await todo.getLast(),
    "Test liveness after being demoted from default"
  );

  todo2.addItem("Test shared state through local vs default reference");
  Assert.equal(
    await (await getDefaultList()).getLast(),
    "Test shared state through local vs default reference"
  );
});