Commit adaeabc2 authored by Nicolas Chevobbe's avatar Nicolas Chevobbe
Browse files

Bug 1672935 - [devtools] Remove l10N fixtures in webconsole mocha tests. r=ladybenko.

Now that the l10n module handles node environment, we no
longer need the existing fixtures for the mocha tests.
A couple tests needed to be updated to pass.

Depends on D94570

Differential Revision: https://phabricator.services.mozilla.com/D94571
parent 42ad3be6
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ describe("FilterBar component:", () => {
    // Text filter input
    const textFilter = textInput.children().eq(0);
    expect(textFilter.attr("class")).toBe("devtools-filterinput");
    expect(textFilter.attr("placeholder")).toBe("Filter output");
    expect(textFilter.attr("placeholder")).toBe("Filter Output");
    expect(textFilter.attr("type")).toBe("search");
    expect(textFilter.attr("value")).toBe("");

@@ -193,7 +193,8 @@ describe("FilterBar component:", () => {
        label: "CSS",
        filterKey: "css",
        active: false,
        title: "webconsole.cssFilterButton.inactive.tooltip",
        title:
          "Stylesheets will be reparsed to check for errors. Refresh the page to also see errors from stylesheets modified from Javascript.",
      }),
      filterBtn({ label: "XHR", filterKey: "netxhr", active: false }),
      filterBtn({ label: "Requests", filterKey: "net", active: false }),
+0 −82
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const strings = {
  "level.error": "Error",
  consoleCleared: "Console was cleared.",
  webConsoleXhrIndicator: "XHR",
  webConsoleMoreInfoLabel: "Learn More",
  "webconsole.clearButton.tooltip": "Clear the Web Console output",
  "webconsole.toggleFilterButton.tooltip": "Toggle filter bar",
  "webconsole.filterInput.placeholder": "Filter output",
  "webconsole.errorsFilterButton.label": "Errors",
  "webconsole.warningsFilterButton.label": "Warnings",
  "webconsole.logsFilterButton.label": "Logs",
  "webconsole.infoFilterButton.label": "Info",
  "webconsole.debugFilterButton.label": "Debug",
  "webconsole.cssFilterButton.label": "CSS",
  "webconsole.xhrFilterButton.label": "XHR",
  "webconsole.requestsFilterButton.label": "Requests",
  "messageRepeats.tooltip2": "#1 repeat;#1 repeats",
  "webconsole.filteredMessagesByText.label": "#1 hidden;#1 hidden",
  "webconsole.filteredMessagesByText.tooltip":
    "#1 item hidden by text filter;#1 items hidden by text filter",
  cdFunctionInvalidArgument:
    "Cannot cd() to the given window. Invalid argument.",
  "webconsole.group.cookieSameSiteLaxByDefaultEnabled2":
    "Some cookies are misusing the SameSite attribute, so it won't work as expected",
  "webconsole.group.cookieSameSiteLaxByDefaultDisabled2":
    "Some cookies are misusing the recommended SameSite attribute",
};

// @TODO Load the actual strings from webconsole.properties instead.
class L10n {
  getStr(str) {
    return strings[str] || str;
  }

  getFormatStr(str, ...rest) {
    switch (str) {
      case "counterDoesntExist":
        return `Counter “${rest[0]}” doesn’t exist.`;
      case "timerDoesntExist":
        return `Timer “${rest[0]}” doesn’t exist.`;
      case "timerAlreadyExists":
        return `Timer “${rest[0]}” already exists.`;
      case "timeLog":
        return `${rest[0]}: ${rest[1]}ms`;
      case "console.timeEnd":
        return `${rest[0]}: ${rest[1]}ms - timer ended`;
      default:
        return this.getStr(str);
    }
  }

  timestampString(milliseconds) {
    const d = new Date(milliseconds ? milliseconds : null);
    let hours = d.getHours(),
      minutes = d.getMinutes();
    let seconds = d.getSeconds();
    milliseconds = d.getMilliseconds();

    // String.prototype.padStart isn't supported in node
    function padZeros(str, len) {
      str = new String(str);
      while (str.len < len) {
        str = "0" + str;
      }
      return str;
    }

    hours = padZeros(hours, 2);
    minutes = padZeros(minutes, 2);
    seconds = padZeros(seconds, 2);
    milliseconds = padZeros(milliseconds, 3);

    return `${hours}:${minutes}:${seconds}.${milliseconds}`;
  }
}

module.exports = L10n;
+0 −10
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const LocalizationHelper = require("devtools/client/webconsole/test/node/fixtures/L10n");

module.exports = {
  LocalizationHelper,
};
+0 −17
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

module.exports = {
  PluralForm: {
    get: function(occurence, str) {
      if (str.includes(";")) {
        const [singular, plural] = str.split(";");
        return occurence > 1 ? plural : singular;
      }

      return str;
    },
  },
};
+0 −6
Original line number Diff line number Diff line
@@ -129,12 +129,6 @@ requireHacker.global_hook("default", (path, module) => {
      `module.exports = { addProfilerMarker: () => {}, import: () => ({}) }`,
    // Some modules depend on Chrome APIs which don't work in mocha. When such a module
    // is required, replace it with a mock version.
    "devtools/shared/l10n": () =>
      getModule(
        "devtools/client/webconsole/test/node/fixtures/LocalizationHelper"
      ),
    "devtools/shared/plural-form": () =>
      getModule("devtools/client/webconsole/test/node/fixtures/PluralForm"),
    Services: () => `module.exports = require("devtools-services")`,
    "devtools/server/devtools-server": () =>
      `module.exports = {DevToolsServer: {}}`,