(hbs`
diff --git a/web/tests/integration/components/inputs/product-select/item-test.ts b/web/tests/integration/components/inputs/product-select/item-test.ts
index 661f5cc2e..8e45118b7 100644
--- a/web/tests/integration/components/inputs/product-select/item-test.ts
+++ b/web/tests/integration/components/inputs/product-select/item-test.ts
@@ -13,7 +13,7 @@ const CHECK = "[data-test-check]";
interface InputsProductSelectItemContext extends MirageTestContext {
product: string;
isSelected?: boolean;
- abbreviation?: boolean;
+ abbreviation?: string;
}
module(
@@ -64,5 +64,23 @@ module(
assert.dom("[data-test-empty-state]").hasText("Select a product/area");
});
+
+ test("it shows an abbreviation when one exists, unless its the same as the product name", async function (this: InputsProductSelectItemContext, assert) {
+ this.set("product", "Vault");
+ this.set("abbreviation", "VLT");
+
+ await render(hbs`
+
+ `);
+
+ assert.dom(ABBREVIATION).hasText("VLT");
+
+ this.set("abbreviation", "Vault");
+
+ assert.dom(ABBREVIATION).doesNotExist();
+ });
},
);
diff --git a/web/tests/mirage-helpers/utils.ts b/web/tests/mirage-helpers/utils.ts
new file mode 100644
index 000000000..cd117ab25
--- /dev/null
+++ b/web/tests/mirage-helpers/utils.ts
@@ -0,0 +1,14 @@
+import { MirageTestContext } from "ember-cli-mirage/test-support";
+import ProductAreasService from "hermes/services/product-areas";
+
+export function startFactories(mirage: MirageTestContext) {
+ mirage.server.create("product");
+}
+
+export const setupProductIndex = async (mirage: MirageTestContext) => {
+ const productAreas = mirage.owner.lookup(
+ "service:product-areas",
+ ) as ProductAreasService;
+
+ await productAreas.fetch.perform();
+};
diff --git a/web/tests/unit/services/product-areas-test.ts b/web/tests/unit/services/product-areas-test.ts
index a9a060084..423681bd5 100644
--- a/web/tests/unit/services/product-areas-test.ts
+++ b/web/tests/unit/services/product-areas-test.ts
@@ -1,37 +1,58 @@
-import { module, test, todo } from "qunit";
+import { module, test } from "qunit";
import { setupTest } from "ember-qunit";
import ProductAreasService from "hermes/services/product-areas";
import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support";
import { authenticateSession } from "ember-simple-auth/test-support";
+interface ProductAreasServiceTestContext extends MirageTestContext {
+ productAreas: ProductAreasService;
+}
+
module("Unit | Service | product-areas", function (hooks) {
setupTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
authenticateSession({});
- });
-
- test("can set or close an active modal", async function (this: MirageTestContext, assert) {
const productAreas = this.owner.lookup(
- "service:product-areas"
+ "service:product-areas",
) as ProductAreasService;
+ this.set("productAreas", productAreas);
+ });
+
+ test("it fetches product areas from the back end", async function (this: ProductAreasServiceTestContext, assert) {
+ const key = "Labs";
+ const abbreviation = "LABS";
+
this.server.create("product", {
- name: "Labs",
- abbreviation: "LABS",
+ name: key,
+ abbreviation,
});
- const expectedResponse = {
- Labs: {
- abbreviation: "LABS",
- },
- };
+ await this.productAreas.fetch.perform();
- assert.equal(productAreas.index, null);
+ assert.equal(Object.keys(this.productAreas.index)[0], key);
+
+ assert.equal(
+ Object.values(this.productAreas.index)[0]?.abbreviation,
+ abbreviation,
+ );
+ });
+
+ test("it returns a product abbreviation if it exists", async function (this: ProductAreasServiceTestContext, assert) {
+ const key = "Labs";
+ const abbreviation = "LABS";
+
+ this.server.create("product", {
+ name: key,
+ abbreviation,
+ });
- await productAreas.fetch.perform();
+ await this.productAreas.fetch.perform();
- assert.deepEqual(productAreas.index, expectedResponse);
+ assert.equal(this.productAreas.getAbbreviation(key), abbreviation);
+ assert.equal(this.productAreas.getAbbreviation("foo"), undefined);
+ assert.equal(this.productAreas.getAbbreviation(), undefined);
});
});