-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move ProductArea index and fetch into service * Update tests * Update test selector
- Loading branch information
Showing
10 changed files
with
125 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Service, { inject as service } from "@ember/service"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { action } from "@ember/object"; | ||
import RouterService from "@ember/routing/router-service"; | ||
import { task, timeout } from "ember-concurrency"; | ||
import FetchService from "./fetch"; | ||
|
||
export type ProductArea = { | ||
abbreviation: string; | ||
}; | ||
|
||
export default class ProductAreasService extends Service { | ||
@service("fetch") declare fetchSvc: FetchService; | ||
|
||
@tracked index: Record<string, ProductArea> | null = null; | ||
|
||
fetch = task(async () => { | ||
try { | ||
this.index = await this.fetchSvc | ||
.fetch("/api/v1/products") | ||
.then((resp) => resp?.json()); | ||
} catch (err) { | ||
this.index = null; | ||
throw err; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { module, test, todo } 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"; | ||
|
||
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" | ||
) as ProductAreasService; | ||
|
||
this.server.create("product", { | ||
name: "Labs", | ||
abbreviation: "LABS", | ||
}); | ||
|
||
const expectedResponse = { | ||
Labs: { | ||
abbreviation: "LABS", | ||
}, | ||
}; | ||
|
||
assert.equal(productAreas.index, null); | ||
|
||
await productAreas.fetch.perform(); | ||
|
||
assert.deepEqual(productAreas.index, expectedResponse); | ||
}); | ||
}); |