Skip to content

Commit

Permalink
Merge pull request #432 from cailloumajor/target-cycle-time-config-api
Browse files Browse the repository at this point in the history
feat!: get target cycle time from config API
  • Loading branch information
cailloumajor authored Sep 1, 2023
2 parents 6b9e58d + 30abb83 commit 5c14d26
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions integration/e2e-tests-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ app.all(/\/centrifugo\/(emulation|connection\/sse)/, (req, res) => {
app.get("/config-api/*", (req, res) => {
res.json({
title: "End-to-end tests",
targetCycleTime: 54.78,
})
})

Expand Down
1 change: 1 addition & 0 deletions src/api-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const handlers = [
res(
ctx.json({
title: "Test Title",
targetCycleTime: 12.34,
}),
),
),
Expand Down
1 change: 1 addition & 0 deletions src/pages/LineDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ const statusDuration = computed(() => {
const resp = await mande(configApiPath).get(props.id)
const config = await lineDashboardConfigSchema.parseAsync(resp)
commonStore.title = config.title
campaignDataStore.targetCycleTime = config.targetCycleTime
const timelineApiUrl = `${computeApiPath}/timeline/${props.id}`
const timelinePalette = ["negative", "warning", "positive", "info"].map(
Expand Down
33 changes: 25 additions & 8 deletions src/pages/__tests__/LineDashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe("LineDashboard", () => {
.as("schema-parse-stub")
.resolves({
title: "",
targetCycleTime: 0,
})
cy.intercept(`${computeApiPath}/performance/*`, { body: 0.0 })

Expand Down Expand Up @@ -128,17 +129,19 @@ describe("LineDashboard", () => {
})

it("requests the config API according to id prop", () => {
const handled = { count: 0 }
cy.wrap(handled).as("handled")

cy.intercept(`${configApiPath}/testid`, (req) => {
handled.count += 1
req.reply({})
})
cy.intercept(
`${configApiPath}/testid`,
cy
.stub()
.as("response-stub")
.callsFake((req: CyHttpMessages.IncomingHttpRequest) => {
req.reply({})
}),
)

mountComponent({ id: "testid" })

cy.get("@handled").its("count").should("equal", 1)
cy.get<SinonStub>("@response-stub").should("have.been.calledOnce")
})

it("validates config data against schema", () => {
Expand All @@ -157,6 +160,7 @@ describe("LineDashboard", () => {
it("sets the title in the common line interface store", () => {
cy.get<SinonStub>("@schema-parse-stub").invoke("resolves", {
title: "Stubbed Title",
targetCycleTime: 0,
})

mountComponent()
Expand All @@ -166,6 +170,19 @@ describe("LineDashboard", () => {
.should("equal", "Stubbed Title")
})

it("sets the target cycle time in the campaign store", () => {
cy.get<SinonStub>("@schema-parse-stub").invoke("resolves", {
title: "",
targetCycleTime: 42.42,
})

mountComponent()

cy.wrap(useCampaignDataStore())
.its("targetCycleTime")
.should("equal", 42.42)
})

it("calls machine data link bootstrap function", () => {
mountComponent({ id: "anid" })

Expand Down
4 changes: 3 additions & 1 deletion src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export const commonLineInterfaceConfigSchema = z.object({
})

export const lineDashboardConfigSchema = commonLineInterfaceConfigSchema.extend(
{},
{
targetCycleTime: z.number().positive(),
},
)
2 changes: 1 addition & 1 deletion src/stores/campaign-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const useCampaignDataStore = defineStore("campaign-data", {
state: () => ({
currentCampaign: "?",
dataValidForCampaign: "!INVALID!",
targetCycleTime: 21.24, // TODO: restore to 0 after implementing
targetCycleTime: 0,
}),

actions: {
Expand Down

0 comments on commit 5c14d26

Please sign in to comment.