tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_ChatMessage.js (2744B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 do_get_profile();
      5 
      6 const { ChatMessage } = ChromeUtils.importESModule(
      7  "moz-src:///browser/components/aiwindow/ui/modules/ChatStore.sys.mjs"
      8 );
      9 
     10 add_task(function test_ChatMessage_constructor_defaults() {
     11  const message = new ChatMessage({
     12    ordinal: 0,
     13    role: 0,
     14    turnIndex: 0,
     15    content: "some content",
     16    pageUrl: new URL("https://www.mozilla.com"),
     17  });
     18 
     19  Assert.withSoftAssertions(function (soft) {
     20    soft.equal(message.id.length, 12);
     21    soft.equal(message.revisionRootMessageId, message.id);
     22    soft.ok(!isNaN(message.createdDate));
     23    soft.ok(message.isActiveBranch);
     24    const nullFields = [
     25      "parentMessageId",
     26      "modelId",
     27      "params",
     28      "usage",
     29      "convId",
     30      "insightsEnabled",
     31      "insightsFlagSource",
     32      "insightsApplied",
     33      "webSearchQueries",
     34    ];
     35 
     36    nullFields.forEach(nullField => {
     37      soft.equal(
     38        message[nullField],
     39        null,
     40        `message.${nullField} should default to null`
     41      );
     42    });
     43  });
     44 });
     45 
     46 add_task(function test_pageUrl_as_URL_ChatConversation() {
     47  const message = new ChatMessage({
     48    ordinal: 0,
     49    role: 0,
     50    turnIndex: 0,
     51    content: "some content",
     52    pageUrl: new URL("https://www.mozilla.com"),
     53  });
     54 
     55  Assert.withSoftAssertions(function (soft) {
     56    soft.ok(URL.isInstance(message.pageUrl));
     57    soft.equal(message.pageUrl.href, "https://www.mozilla.com/");
     58  });
     59 });
     60 
     61 add_task(function test_pageUrl_as_string_ChatConversation() {
     62  const message = new ChatMessage({
     63    ordinal: 0,
     64    role: 0,
     65    turnIndex: 0,
     66    content: "some content",
     67    pageUrl: "https://www.mozilla.com",
     68  });
     69 
     70  Assert.withSoftAssertions(function (soft) {
     71    soft.ok(URL.isInstance(message.pageUrl));
     72    soft.equal(message.pageUrl.href, "https://www.mozilla.com/");
     73  });
     74 });
     75 
     76 add_task(function test_invalid_pageUrl_ChatConversation() {
     77  Assert.throws(
     78    function () {
     79      new ChatMessage({
     80        ordinal: 0,
     81        role: 0,
     82        turnIndex: 0,
     83        content: "some content",
     84        pageUrl: "www.mozilla.com",
     85      });
     86    },
     87    new RegExp("URL constructor: www.mozilla.com is not a valid URL"),
     88    "Did not get correct error message"
     89  );
     90 });
     91 
     92 add_task(function test_missing_pageUrl_ChatConversation() {
     93  const message = new ChatMessage({
     94    ordinal: 0,
     95    role: 0,
     96    turnIndex: 0,
     97    content: "some content",
     98  });
     99 
    100  Assert.equal(message.pageUrl, null);
    101 });
    102 
    103 add_task(function test_empty_pageUrl_ChatConversation() {
    104  const message = new ChatMessage({
    105    ordinal: 0,
    106    role: 0,
    107    turnIndex: 0,
    108    content: "some content",
    109    pageUrl: "",
    110  });
    111 
    112  Assert.equal(message.pageUrl, null);
    113 });