Merge the remote pages: scope line, Remote select, remote chips and badge (wp-remote-b)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	app/static/agents.js
This commit is contained in:
Wolf committed 2026-09-30 16:22:22 +02:00
commit 5c3c187dca
7 files changed
+383 -86

No files matched your search

+101 -75
View File
@@ -24,7 +24,7 @@
(function () {
"use strict";
const { api, count } = window;
const { api, count, remoteHelpers: rh } = window;
const $ = (sel, root = document) => root.querySelector(sel);
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 };
@@ -33,12 +33,9 @@
// best `summarise_top` at `summarise_min` or more a summary.
const DEFAULT_LIMITS = { extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min: 0.65 };
const NEW = "new";
// Europe as the starter agents in config.example.yaml spell it: the EEA,
// the UK and Switzerland, and EU for a role open anywhere in Europe.
const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR",
"HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE",
"IS", "LI", "NO", "GB", "CH", "EU"];
const FIELDS = ["place", "country", "remote", "seniority", "function", "salary_min",
// Europe as the starter agents spell it (static/remote.js).
const EUROPE = rh.EUROPE;
const FIELDS = ["place", "country", "remote", "remote_from", "seniority", "function", "salary_min",
"currency", "permit", "languages", "company", "title"];
const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"], ["exclude", "not"]];
const HYBRID_WEIGHT = 0.05;
@@ -107,11 +104,33 @@
}
// The countries Where offers, by name: Europe's, without EU, which is not
// a country but "open anywhere in Europe" and is said by Remote.
// a country but "open anywhere in Europe" and is picked in the remote line.
const COUNTRIES = EUROPE.filter((c) => c !== "EU")
.map((c) => [c, countryName(c)])
.sort((a, b) => a[1].localeCompare(b[1]));
/** @type {Map<string, string>} the words of the `remote_from` values, by
* value, as `/api/places/labels` says them; a card and a chip fall back to
* `rh.fallbackLabel` until they are in */
const placeNames = new Map();
const placeLabel = (value) => placeNames.get(value) || rh.fallbackLabel(value, countryName);
// The labels of the `remote_from` tokens in `gates` that are not known yet.
// A failure is toasted by `api()` and leaves the fallbacks.
async function nameRemote(gates) {
const missing = [...new Set(gates.filter((g) => g.field === "remote_from")
.flatMap((g) => g.values.map(String)))]
.filter((v) => v !== rh.ANYWHERE && !placeNames.has(v));
if (!missing.length) return;
const p = new URLSearchParams();
missing.forEach((t) => p.append("tokens", t));
try {
for (const { token, label } of await api(`/api/places/labels?${p}`)) placeNames.set(token, label);
} catch (err) {
// the fallbacks stand
}
}
// "a, b or c": the values of one line.
function orList(items) {
return items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
@@ -196,33 +215,45 @@
}
if (gate.field === "place") return `in ${orList(towns(values))}`;
if (gate.field === "remote") return orList(values);
if (gate.field === "remote_from") return rh.remoteSentence(values, placeLabel);
if (gate.field === "company") return `at ${orList(values)}`;
if (gate.field === "salary_min") return `paying at least ${values[0]}`;
return `with ${gate.field.replace("_", " ")} ${values.join(", ")}`;
}
// The Where block in words, one sentence of the lines a role may match,
// with the one-of rows among them since they are the same group: "Keeps
// roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote within
// Europe, and leaves out the rest." The lines add up, which the first
// wording ("Roles in ...") left the owner to guess.
// The scope of the Where block in words: "Within Europe", "Within Denmark or
// Sweden", "Everywhere".
function scopeWords(scope) {
if (scope.kind === "everywhere") return "Everywhere";
if (scope.kind === "europe") return "Within Europe";
return `Within ${phrase({ field: "country", values: scope.values }).replace(/^in /, "")}`;
}
// The Where block in words, one sentence led by its scope, then the lines a
// role may match, with the one-of rows among them since they are the same
// group: "Within Europe: keeps roles anywhere in Denmark, in Malmö, Lund or
// Helsingborg, or remote, and leaves out the rest." The lines add up, which
// the first wording ("Roles in ...") left the owner to guess.
function whereSentence(where, others) {
const parts = [];
if (where.countries) parts.push(`anywhere ${phrase(where.countries)}`);
if (where.places) parts.push(phrase(where.places));
if (where.remote) parts.push(where.europe ? "remote within Europe" : "remote");
if (where.remote.mode === "scope") parts.push("remote");
if (where.remote.mode === "from" && where.remote.values.length) {
parts.push(rh.remoteSentence(where.remote.values, placeLabel));
}
parts.push(...others.map(phrase));
if (!parts.length) return "";
if (!parts.length) return where.scope.kind === "everywhere" ? "" : `${scopeWords(where.scope)}: keeps every role.`;
const list = parts.length < 2 ? parts[0] : `${parts.slice(0, -1).join(", ")}, or ${parts[parts.length - 1]}`;
return `Keeps roles ${list}, and leaves out the rest.`;
return `${scopeWords(where.scope)}: keeps roles ${list}, and leaves out the rest.`;
}
// The gates in words: where a role may be, then what it must meet, then
// what lifts it. "Keeps roles anywhere in Denmark, or remote within Europe,
// what lifts it. "Within Europe: keeps roles anywhere in Denmark, or remote,
// and leaves out the rest. Only roles with seniority senior. Prefers
// hybrid."
function rulesLine(gates) {
const { where, rest } = distribute(gates);
const { where, rest } = rh.distribute(gates);
const of = (mode) => rest.filter((g) => g.mode === mode);
const must = of("require").map(phrase);
const prefer = of("prefer").map((g) => phrase(g).replace(/^with /, ""));
@@ -382,6 +413,33 @@
return { node: chips.node, values: () => [...chips.list] };
}
// "Only when open to someone in": the values of a `remote_from` gate as
// chips, picked from the place suggestions that a remote hire can live in:
// countries and regions. `values()` are the gate's values (`country:DK`),
// the chips say them in words.
function remoteInput(values, onChange) {
const root = el("div");
root.id = "a-remote-from";
const chips = window.chipInput(root, {
suggest: async (q) => {
const rows = await api(`/api/suggest/places?${new URLSearchParams({ q })}`);
const picks = [];
for (const s of rows) {
const value = rh.fromSuggestion(s);
if (value !== null) picks.push({ value, label: s.label, hint: s.kind });
}
return picks;
},
onChange: (items) => {
items.forEach((i) => placeNames.set(i.value, i.label));
onChange();
},
placeholder: "Add a country or a region", label: "Remote, open to someone in",
});
chips.set(values.map((v) => ({ value: v, label: placeLabel(v) })));
return { node: root, values: () => chips.values().map((i) => i.value) };
}
// Words as chips of free text, added on Enter or a comma, and one chip for
// the spellings that fold alike. What is typed but not added yet counts, so
// Save does not drop it. Towns and fetch terms both.
@@ -493,47 +551,6 @@
return { node: row, read };
}
// Share out an agent's gates between the Where block and Other rules. Each
// Where line takes the first gate it can say whole; the rest are rows. A
// must or one-of gate with a weight other than the default stays a row,
// since Where would drop it. Remote within Europe is a must on country
// that is Europe and the countries line exactly, and only with Remote
// ticked; any other must on country is a row, and Remote reads anywhere.
function distribute(gates) {
const where = { countries: null, places: null, remote: null, europe: null, hybrid: null, titles: null };
const rest = [];
const musts = [];
const plain = (g) => g.weight === undefined || g.weight === 1;
const only = (g, value) => g.values.length === 1 && g.values[0] === value;
for (const g of gates) {
let slot = null;
if (g.field === "country" && g.mode === "require" && plain(g)) {
musts.push(g);
continue;
}
if (g.field === "country" && g.mode === "any" && plain(g)) slot = "countries";
else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote")) slot = "remote";
else if (g.field === "place" && g.mode === "any" && plain(g)) slot = "places";
else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid")) slot = "hybrid";
else if (g.field === "title" && g.mode === "exclude" && plain(g)) slot = "titles";
if (slot && !where[slot]) where[slot] = g;
else rest.push(g);
}
const within = new Set(europeWith(where.countries ? where.countries.values : []));
for (const g of musts) {
const same = g.values.length === within.size && g.values.every((v) => within.has(v));
if (where.remote && !where.europe && same) where.europe = g;
else rest.push(g);
}
return { where, rest };
}
// What Remote within Europe sends: Europe, and the countries line too,
// since the must holds for every role, not only the remote ones.
function europeWith(countries) {
return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))];
}
function form(row) {
const div = el("article", "agent-card editing");
const f = $("#agent-form-template").content.querySelector("form").cloneNode(true);
@@ -562,24 +579,29 @@
changed(f);
});
const { where, rest } = distribute(row ? row.gates : []);
const { where, rest } = rh.distribute(row ? row.gates : []);
const scope = $("#a-scope", f);
scope.value = where.scope.kind;
const scoped = countryInput(where.scope.values);
const countries = countryInput(where.countries ? where.countries.values : []);
const places = wordInput(where.places ? where.places.values : [], "Add a town");
const titles = wordInput(where.titles ? where.titles.values : [], "account executive");
const terms = wordInput(row ? row.fetch_terms || [] : [], "machine learning, data science");
$("#a-titles", f).replaceWith(titles.node);
$("#a-terms", f).replaceWith(terms.node);
$("#a-scope-countries", f).replaceWith(scoped.node);
$("#a-countries", f).replaceWith(countries.node);
$("#a-towns", f).replaceWith(places.node);
const remote = $("#a-remote", f);
const scope = $("#a-remote-scope", f);
remote.checked = Boolean(where.remote);
// Anywhere when a must on country is a row, so ticking Remote does not
// stack a second one on it; else Europe, the usual answer.
const mustRow = rest.some((g) => g.field === "country" && g.mode === "require");
scope.value = where.europe || !(where.remote || mustRow) ? "europe" : "anywhere";
const offerScope = () => { scope.disabled = !remote.checked; };
offerScope();
const remoteMode = $("#a-remote", f);
remoteMode.value = where.remote.mode;
const remoteFrom = remoteInput(where.remote.mode === "from" ? where.remote.values : [], () => changed(f));
$("#a-remote-from", f).replaceWith(remoteFrom.node);
// Only the pick that is on shows its chips.
const offer = () => {
scoped.node.hidden = scope.value !== "countries";
remoteFrom.node.hidden = remoteMode.value !== "from";
};
offer();
// The hybrid weight shows only when it is not the default; either way it
// is sent back as it came.
const hybridWeight = where.hybrid && where.hybrid.weight !== undefined ? where.hybrid.weight : HYBRID_WEIGHT;
@@ -607,17 +629,20 @@
});
// The gates the Where block says, in the order the starter agents have
// them: the must on country, the lines, then hybrid; and the titles left
// out, the block under it.
// them: the scope, the lines, then hybrid; and the titles left out, the
// block under it.
function whereGates() {
const out = [];
const within = countries.values();
const towns = places.values();
if (remote.checked && scope.value === "europe") {
out.push({ field: "country", values: europeWith(within), mode: "require" });
const from = remoteFrom.values();
if (scope.value === "europe") out.push({ field: "country", values: rh.europeWith(within), mode: "require" });
if (scope.value === "countries" && scoped.values().length) {
out.push({ field: "country", values: scoped.values(), mode: "require" });
}
if (within.length) out.push({ field: "country", values: within, mode: "any" });
if (remote.checked) out.push({ field: "remote", values: ["remote"], mode: "any" });
if (remoteMode.value === "scope") out.push({ field: "remote", values: ["remote"], mode: "any" });
if (remoteMode.value === "from" && from.length) out.push({ field: "remote_from", values: from, mode: "any" });
if (towns.length) out.push({ field: "place", values: towns, mode: "any" });
if ($("#a-hybrid", f).checked) {
out.push({ field: "remote", values: ["hybrid"], mode: "prefer", weight: Number($("#a-hybrid-weight", f).value) });
@@ -630,7 +655,7 @@
// under Where says them all, as the card will, rows included.
const gates = () => whereGates().concat(rules.map((r) => r.read()));
const view = () => {
offerScope();
offer();
$("#a-gates", f).value = JSON.stringify(gates(), null, 2);
$("#a-where-sum", f).textContent = rulesLine(gates()) || "Keeps roles anywhere.";
};
@@ -804,6 +829,7 @@
async function load() {
agents = await api("/api/agents");
await nameRemote(agents.flatMap((a) => a.gates || []));
// A card is only worded by it, so a failure leaves the cards as they were.
try {
stageOn = Object.fromEntries((await api("/api/stages")).map((s) => [s.name, s.on]));
+1
View File
@@ -1250,6 +1250,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.where-line { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .9rem; }
.where-line > span, .where-line > label { flex: none; min-width: 9rem; }
.where-line .chips { flex: 1 1 12rem; }
.where-line .chip-input { flex: 1 1 12rem; min-width: 0; margin: 0; }
/* Hybrid ranks rather than filters, so it stands apart from the lines, and
the sentence under it says the whole block. */
.agent-form .where-rank { margin-top: .4rem; }
+111
View File
@@ -0,0 +1,111 @@
/* Where a remote role may be worked from, as the pages say it: the words of
* the badge, the picks of the agent's "Remote, open to someone in" chips, and
* how an agent's gates share out between the Where block and Other rules. No
* DOM in it, so `tests/js/remote.test.mjs` can walk it without a browser.
*
* The area is a place token in three spellings, one per layer: `remote:<place
* token>` on the Roles rail and in the address, `<place token>` in a
* `remote_from` gate, and a label on a row (`remote_where`). `anywhere` is
* the one place that is no gazetteer town, region or country.
*/
(function () {
"use strict";
const ANYWHERE = "anywhere";
/** The badge of a row and the reader: "remote · Europe", "remote · anywhere",
"remote · Denmark" from `remote_where`, "remote" alone when the area is
not stated, and the other words (hybrid, onsite) as they are. */
function remoteBadge(role) {
const word = role && role.remote;
if (!word) return "";
const where = word === "remote" ? String(role.remote_where || "").trim() : "";
return where ? `${word} · ${where}` : word;
}
/** A `/api/suggest/places` answer as the value of a `remote_from` gate, or
null when the Where block does not offer it: countries and regions. A
town or a remote token is left out; the block's own country pick is the
plain one. */
function fromSuggestion(s) {
const token = String(s.token || "");
return token.startsWith("country:") || token.startsWith("region:") ? token : null;
}
/** The chip label of a gate value when the server has not said it yet. */
function fallbackLabel(value, countryName) {
if (value === ANYWHERE) return "Anywhere";
if (value === "country:EU") return "Europe";
if (value.startsWith("country:")) return countryName(value.slice(8));
return value.slice(value.indexOf(":") + 1);
}
/** "remote from Denmark, Sweden or Germany", "remote from anywhere". */
function remoteSentence(values, label) {
const names = values.map((v) => (v === ANYWHERE ? "anywhere" : label(v)));
const list = names.length < 2 ? names.join("")
: `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}`;
return `remote from ${list}`;
}
/** Europe as the starter agents in config.example.yaml spell it: the EEA,
the UK and Switzerland, and EU for a role open anywhere in Europe. */
const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR",
"HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE",
"IS", "LI", "NO", "GB", "CH", "EU"];
/** What "Only roles in: Europe" sends: Europe, and the countries line too,
since the require gate holds for every role, not only the remote ones. */
function europeWith(countries) {
return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))];
}
/** Share out an agent's gates between the Where block and Other rules. Each
Where line takes the first gate it can say whole; the rest are rows. A
must or one-of gate with a weight other than the default stays a row,
since Where would drop it.
The scope line is the first plain require gate on country: `europe`
when it is exactly Europe and the countries line (`europeWith`),
`countries` with its codes as chips otherwise, `everywhere` when there
is none. Any other require gate on country is a row. The remote line is
`scope` for the one-of on `remote: [remote]` (remote, within the
scope), `from` for a one-of on `remote_from`, else `none`; when both
are there `remote_from` wins and the plain one stays a row. */
function distribute(gates) {
const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, hybrid: null, titles: null };
const rest = [];
const plain = (g) => g.weight === undefined || g.weight === 1;
const only = (g, value) => g.values.length === 1 && g.values[0] === value;
let must = null;
let older = null;
let from = null;
for (const g of gates) {
if (g.field === "country" && g.mode === "require" && plain(g) && !must) must = g;
else if (g.field === "country" && g.mode === "any" && plain(g) && !where.countries) where.countries = g;
else if (g.field === "place" && g.mode === "any" && plain(g) && !where.places) where.places = g;
else if (g.field === "remote_from" && g.mode === "any" && plain(g) && !from) from = g;
else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote") && !older) older = g;
else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid") && !where.hybrid) where.hybrid = g;
else if (g.field === "title" && g.mode === "exclude" && plain(g) && !where.titles) where.titles = g;
else rest.push(g);
}
if (from) {
where.remote = { mode: "from", values: from.values.map(String) };
if (older) rest.push(older);
} else if (older) {
where.remote = { mode: "scope", values: [] };
}
if (!must) {
where.scope = { kind: "everywhere", values: [] };
} else {
const values = must.values.map(String);
const within = new Set(europeWith(where.countries ? where.countries.values.map(String) : []));
const europe = values.length === within.size && values.every((v) => within.has(v));
where.scope = europe ? { kind: "europe", values: [] } : { kind: "countries", values };
}
return { where, rest };
}
window.remoteHelpers = { ANYWHERE, EUROPE, europeWith, remoteBadge, fromSuggestion, fallbackLabel, remoteSentence, distribute };
})();
+14 -7
View File
@@ -85,7 +85,7 @@
"use strict";
const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, overridesControl,
judgeButtons, loadTracked, chipInput } = window;
judgeButtons, loadTracked, chipInput, remoteHelpers } = window;
const $ = (sel, root = document) => root.querySelector(sel);
// Below this the rail is over the feed rather than beside it, and the reader
@@ -128,8 +128,10 @@
};
// The place suggestion's kind, as its hint says it: a `place:` token is a
// town (`places.suggest`).
const PLACE_KINDS = { country: "country", region: "region", place: "town" };
// town, a `remote:` token remote roles (`remote:any` within the viewing
// agent's scope, `remote:country:DK` those a person there can take), its
// count the roles it would find (`places.suggest`).
const PLACE_KINDS = { country: "country", region: "region", place: "town", remote: "remote" };
// Everything `clearFilters` has to put back, in one place, so a new filter
// added here cannot be forgotten there. `company` and `place` are the
@@ -890,7 +892,7 @@
/** Closed, pay, remote, function and seniority, as the row and the reader
both show them. */
function badges(role) {
const words = [role.remote, role.function, role.seniority].filter(Boolean);
const words = [remoteHelpers.remoteBadge(role), role.function, role.seniority].filter(Boolean);
const pay = payBadge(role);
return (role.closed_at ? `<span class="badge closed">closed</span>` : "")
+ (pay ? `<span class="badge">${esc(pay)}</span>` : "")
@@ -1659,11 +1661,16 @@
placeholder: "Company", label: "Company",
});
placeChips = chipInput($("#f-place"), {
suggest: (q) => api(`/api/suggest/places?${new URLSearchParams({ q })}`)
.then((rows) => rows.map((s) => ({
suggest: (q) => {
// The viewing agent, so "Remote" counts the remote roles within its
// scope; the server may ignore it.
const p = new URLSearchParams({ q });
if (state.filter.agent !== null) p.set("agent", String(state.filter.agent));
return api(`/api/suggest/places?${p}`).then((rows) => rows.map((s) => ({
value: s.token, label: s.label,
hint: `${PLACE_KINDS[s.kind] || s.kind} · ${number.format(s.count)}`,
}))),
})));
},
onChange: (items) => {
items.forEach((i) => placeLabels.set(i.value, i.label));
setFilter({ places: items.map((i) => i.value) });
+1
View File
@@ -166,6 +166,7 @@
applies all the same, and chips.css only adds to app.css. #}
<link rel="stylesheet" href="{{ asset('chips.css') }}">
<script src="{{ asset('chips.js') }}"></script>
<script src="{{ asset('remote.js') }}"></script>
<script src="{{ asset('judge.js') }}"></script>
<script src="{{ asset('roles.js') }}"></script>
{% endblock %}
+21 -4
View File
@@ -29,6 +29,16 @@
<fieldset class="where">
<legend>Where can the role be?</legend>
<span class="hint">Each line adds places. A role is kept when it fits at least one line, so a line more means more roles, never fewer. With every line empty a role can be anywhere. A role whose location is not known yet ranks until extract reads the posting.</span>
<div class="where-line">
<span>Only roles in:</span>
<select id="a-scope" aria-label="Only roles in">
<option value="europe">Europe</option>
<option value="countries">Chosen countries</option>
<option value="everywhere">Everywhere</option>
</select>
<div id="a-scope-countries"></div>
</div>
<span class="hint">Every role must be in this, whatever the lines below add. A company set to All countries is read within this.</span>
<div class="where-line">
<span>Anywhere in</span>
<div id="a-countries"></div>
@@ -39,12 +49,15 @@
</div>
<span class="hint">Towns are for places outside the countries above: with Denmark above, Malmö here adds Malmö to all of Denmark. A town inside a country above changes nothing, since the whole country is in already.</span>
<div class="where-line">
<label class="inline"><input type="checkbox" id="a-remote"> or remote</label>
<select id="a-remote-scope" aria-label="Remote from where">
<option value="europe">within Europe</option>
<option value="anywhere">anywhere</option>
<span>Remote:</span>
<select id="a-remote" aria-label="Remote">
<option value="none">no</option>
<option value="scope">anywhere within the scope</option>
<option value="from">only when open to someone in:</option>
</select>
<div id="a-remote-from"></div>
</div>
<span class="hint">Remote roles are kept on top of the lines above. A remote role whose area is not stated yet ranks until extract reads the posting.</span>
<label class="inline where-rank"><input type="checkbox" id="a-hybrid"> Prefer hybrid<span id="a-hybrid-weight-line">, adding <input type="number" id="a-hybrid-weight" min="0" step="0.05" value="0.05" aria-label="Weight of hybrid"></span></label>
<span class="hint">This one ranks rather than filters: a hybrid role gains a little.</span>
<p id="a-where-sum" class="where-sum" role="status"></p>
@@ -104,5 +117,9 @@
{% endblock %}
{% block scripts %}
{# chips.css only adds to app.css; base.html has no head block for it. #}
<link rel="stylesheet" href="{{ asset('chips.css') }}">
<script src="{{ asset('chips.js') }}"></script>
<script src="{{ asset('remote.js') }}"></script>
<script src="{{ asset('agents.js') }}"></script>
{% endblock %}
+134
View File
@@ -0,0 +1,134 @@
// static/remote.js without a browser: the badge, the suggestions the agent's
// remote line offers, and how gates share out between Where and Other rules.
//
// node --test tests/js/*.test.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import vm from "node:vm";
const window = {};
Object.assign(globalThis, { window });
vm.runInThisContext(readFileSync(new URL("../../app/static/remote.js", import.meta.url), "utf8"));
const rh = window.remoteHelpers;
const name = (code) => ({ DK: "Denmark", SE: "Sweden", DE: "Germany" })[code] || code;
const label = (v) => rh.fallbackLabel(v, name);
test("the badge says the area after remote, and remote alone when it is not stated", () => {
assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "Europe" }), "remote · Europe");
assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "anywhere" }), "remote · anywhere");
assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "United States, Canada" }), "remote · United States, Canada");
assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "" }), "remote");
assert.equal(rh.remoteBadge({ remote: "remote" }), "remote");
});
test("the badge leaves the other words as they are, and a role with none blank", () => {
assert.equal(rh.remoteBadge({ remote: "hybrid", remote_where: "Europe" }), "hybrid");
assert.equal(rh.remoteBadge({ remote: "onsite", remote_where: "" }), "onsite");
assert.equal(rh.remoteBadge({ remote: "" }), "");
assert.equal(rh.remoteBadge(null), "");
});
test("a suggestion is offered to the remote line as a country or a region only", () => {
assert.equal(rh.fromSuggestion({ token: "country:DK", kind: "country" }), "country:DK");
assert.equal(rh.fromSuggestion({ token: "country:EU", kind: "country" }), "country:EU");
assert.equal(rh.fromSuggestion({ token: "region:oresund", kind: "region" }), "region:oresund");
assert.equal(rh.fromSuggestion({ token: "remote:any", kind: "remote" }), null);
assert.equal(rh.fromSuggestion({ token: "remote:country:DK", kind: "remote" }), null);
assert.equal(rh.fromSuggestion({ token: "place:1", kind: "place" }), null);
});
test("a value has a label before the server has said it", () => {
assert.equal(label("anywhere"), "Anywhere");
assert.equal(label("country:DK"), "Denmark");
assert.equal(label("country:EU"), "Europe");
assert.equal(label("region:oresund"), "oresund");
});
test("the sentence lists the areas, and says anywhere in lower case", () => {
assert.equal(rh.remoteSentence(["country:DK", "country:SE", "country:DE"], label), "remote from Denmark, Sweden or Germany");
assert.equal(rh.remoteSentence(["anywhere"], label), "remote from anywhere");
assert.equal(rh.remoteSentence(["country:DK"], label), "remote from Denmark");
});
// ------------------------------------------------------------- distribute
const older = { field: "remote", values: ["remote"], mode: "any" };
const from = (...values) => ({ field: "remote_from", values, mode: "any" });
const hybrid = { field: "remote", values: ["hybrid"], mode: "prefer", weight: 0.05 };
const dk = { field: "country", values: ["DK"], mode: "any" };
const must = (...values) => ({ field: "country", values, mode: "require" });
const europe = must(...rh.EUROPE);
test("no gates: everywhere, no remote", () => {
const { where, rest } = rh.distribute([]);
assert.deepEqual(where.scope, { kind: "everywhere", values: [] });
assert.deepEqual(where.remote, { mode: "none", values: [] });
assert.deepEqual(rest, []);
});
test("the Europe list is the Europe scope", () => {
const { where, rest } = rh.distribute([europe, dk, older]);
assert.equal(where.scope.kind, "europe");
assert.equal(where.countries.values[0], "DK");
assert.deepEqual(rest, []);
});
test("Europe with the countries line added is still the Europe scope", () => {
const us = { field: "country", values: ["US"], mode: "any" };
const { where } = rh.distribute([must(...rh.europeWith(["US"])), us]);
assert.equal(where.scope.kind, "europe");
// The same gate without the line's country is not exactly Europe: chips.
assert.equal(rh.distribute([europe, us]).where.scope.kind, "countries");
});
test("any other require gate on country is the scope with its codes as chips", () => {
const { where, rest } = rh.distribute([must("DK", "SE"), dk]);
assert.deepEqual(where.scope, { kind: "countries", values: ["DK", "SE"] });
assert.deepEqual(rest, []);
});
test("a second or weighted require gate on country stays a row", () => {
const second = must("NO");
const weighted = { ...must("DE"), weight: 2 };
const { where, rest } = rh.distribute([europe, second, weighted]);
assert.equal(where.scope.kind, "europe");
assert.deepEqual(rest, [second, weighted]);
});
test("a require gate on another field is a row and leaves the scope everywhere", () => {
const level = { field: "seniority", values: ["senior"], mode: "require" };
const { where, rest } = rh.distribute([level]);
assert.equal(where.scope.kind, "everywhere");
assert.deepEqual(rest, [level]);
});
test("remote, three modes: the plain gate is within the scope", () => {
const scope = rh.distribute([older, hybrid]);
assert.deepEqual(scope.where.remote, { mode: "scope", values: [] });
assert.equal(scope.where.hybrid, hybrid);
assert.deepEqual(scope.rest, []);
assert.deepEqual(rh.distribute([hybrid]).where.remote, { mode: "none", values: [] });
const named = rh.distribute([from("country:DK", "region:oresund")]);
assert.deepEqual(named.where.remote, { mode: "from", values: ["country:DK", "region:oresund"] });
assert.deepEqual(named.rest, []);
});
test("a remote_from gate wins over the plain one, which stays a row", () => {
for (const gates of [[older, from("country:DK")], [from("country:DK"), older]]) {
const { where, rest } = rh.distribute(gates);
assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] });
assert.deepEqual(rest, [older]);
}
});
test("a second remote_from gate, a weighted one or a must stays a row", () => {
const second = from("country:SE");
const weighted = { ...from("country:DE"), weight: 2 };
const required = { field: "remote_from", values: ["country:DK"], mode: "require" };
const { where, rest } = rh.distribute([from("country:DK"), second, weighted, required]);
assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] });
assert.deepEqual(rest, [second, weighted, required]);
});