Skip to content

Commit

Permalink
demo: create rule
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Oct 17, 2023
1 parent ba47852 commit 2875be1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/component-library/Demos/03_1_Create_Rules.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CreateRuleQuery, TypedDIDValidationQuery, TypedDIDValidationResponse } from "@/lib/infrastructure/data/view-model/create-rule";
import { Meta, StoryObj } from "@storybook/react";
import { fixtureDIDLongViewModel, fixtureRSEAccountUsageLimitViewModel, mockUseComDOM } from "test/fixtures/table-fixtures";
import { CreateRule as CR} from "../Pages/Rule/CreateRule.stories";

export default {
title: 'Demos/03_CreateRule',
component: CR,
} as Meta<typeof CR>;

type Story = StoryObj<typeof CR>

export const CreateRule: Story = {
args: {
onSubmit: (query: CreateRuleQuery) => {
return Promise.resolve({
success: true,
})
},
didListComDOM: mockUseComDOM(Array.from({ length: 100 }, () => fixtureDIDLongViewModel())),
didValidation: (query: TypedDIDValidationQuery) => {
// if the DID contains the string "error", it will be added to the error list
var localErrorDIDs: TypedDIDValidationResponse = { ErrorList: [] }
query.DIDList.map((DID: string, index: number) => {
if (DID.includes("error")) {
localErrorDIDs.ErrorList.push({ DID: DID, ErrorCodes: [421], Message: "This DID is invalid" })
}
})
// if the error list is empty, the promise will resolve, otherwise it will reject
if (localErrorDIDs.ErrorList.length === 0) {
return Promise.resolve(localErrorDIDs)
}
else {
return Promise.reject(localErrorDIDs)
}
},
rseListComDOM: mockUseComDOM(Array.from({ length: 100 }, () => fixtureRSEAccountUsageLimitViewModel())),

}
}

0 comments on commit 2875be1

Please sign in to comment.