1
0
Fork 0
firefox/toolkit/components/nimbus/test/unit/test_NimbusTestUtils.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

73 lines
1.8 KiB
JavaScript

"use strict";
add_task(async function test_recipe_fake_validates() {
const recipe = NimbusTestUtils.factories.recipe("foo");
await NimbusTestUtils.validateExperiment(recipe);
});
add_task(async function test_enrollmentHelper() {
let recipe = NimbusTestUtils.factories.recipe.withFeatureConfig("bar", {
featureId: "aboutwelcome",
});
let manager = NimbusTestUtils.stubs.manager();
Assert.deepEqual(
recipe.featureIds,
["aboutwelcome"],
"Helper sets correct featureIds"
);
await manager.store.init();
await manager.onStartup();
const doEnrollmentCleanup = await NimbusTestUtils.enroll(recipe, {
manager,
});
Assert.ok(manager.store.getAllActiveExperiments().length === 1, "Enrolled");
Assert.equal(
manager.store.getAllActiveExperiments()[0].slug,
recipe.slug,
"Has expected slug"
);
Assert.ok(
Services.prefs.prefHasUserValue("nimbus.syncdatastore.aboutwelcome"),
"Sync pref cache set"
);
await doEnrollmentCleanup();
Assert.ok(manager.store.getAll().length === 0, "Cleanup done");
Assert.ok(
!Services.prefs.prefHasUserValue("nimbus.syncdatastore.aboutwelcome"),
"Sync pref cache is cleared"
);
});
add_task(async function test_enrollWithFeatureConfig() {
const { manager, cleanup } = await NimbusTestUtils.setupTest({
features: [new ExperimentFeature("enrollWithFeatureConfig", {})],
});
let doEnrollmentCleanup = await NimbusTestUtils.enrollWithFeatureConfig(
{
featureId: "enrollWithFeatureConfig",
value: { enabled: true },
},
{ manager }
);
Assert.ok(
manager.store.hasExperimentForFeature("enrollWithFeatureConfig"),
"Enrolled successfully"
);
await doEnrollmentCleanup();
Assert.ok(
!manager.store.hasExperimentForFeature("enrollWithFeatureConfig"),
"Unenrolled successfully"
);
await cleanup();
});