-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41329b6
commit 96afdcf
Showing
18 changed files
with
3,893 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
['@babel/preset-react', { runtime: 'automatic' }], | ||
'@babel/preset-typescript', | ||
], | ||
plugins: [ | ||
['@babel/plugin-transform-runtime', { regenerator: true }] | ||
] | ||
}; |
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,11 @@ | ||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'], | ||
moduleNameMapper: { | ||
'^src/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
transform: { | ||
'^.+\\.(ts|tsx)$': 'babel-jest', | ||
}, | ||
}; |
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,36 @@ | ||
mutation GenerateArtifact($id: ID!, $level: Float!) { | ||
generateArtifact(id: $id, level: $level) { | ||
id | ||
hero { | ||
id | ||
pendingArtifact { | ||
id | ||
owner | ||
name | ||
level | ||
attributes { | ||
namePrefix { | ||
type | ||
magnitude | ||
} | ||
namePostfix { | ||
type | ||
magnitude | ||
} | ||
titlePrefix { | ||
type | ||
magnitude | ||
} | ||
titlePostfix { | ||
type | ||
magnitude | ||
} | ||
bonusAffixes { | ||
type | ||
magnitude | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,62 @@ | ||
import React, { useState } from "react"; | ||
|
||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import TextField from "@mui/material/TextField"; | ||
import Typography from "@mui/material/Typography"; | ||
import { useSnackbar } from "notistack"; | ||
|
||
import { useGenerateArtifactMutation, AdminAccountQuery } from "src/generated/graphql"; | ||
|
||
type GenerateArtifactProps = { | ||
account: AdminAccountQuery["account"]; | ||
}; | ||
|
||
export function GenerateArtifact({ account }: GenerateArtifactProps): JSX.Element { | ||
const [level, setLevel] = useState("1"); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
const [generateArtifact] = useGenerateArtifactMutation(); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
try { | ||
await generateArtifact({ | ||
variables: { | ||
id: account.id, | ||
level: parseFloat(level), | ||
}, | ||
}); | ||
enqueueSnackbar("Artifact generated successfully", { variant: "success" }); | ||
} catch (error) { | ||
enqueueSnackbar(error instanceof Error ? error.message : "Failed to generate artifact", { variant: "error" }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box component="form" onSubmit={handleSubmit} sx={{ maxWidth: 400, mb: 4 }}> | ||
<Typography variant="h6" gutterBottom>Generate Test Artifact</Typography> | ||
|
||
<TextField | ||
fullWidth | ||
label="Artifact Level" | ||
type="number" | ||
value={level} | ||
onChange={(e) => setLevel(e.target.value)} | ||
margin="normal" | ||
required | ||
inputProps={{ min: "1", step: "1" }} | ||
helperText="The level of the artifact to generate" | ||
/> | ||
|
||
<Button | ||
type="submit" | ||
variant="contained" | ||
color="primary" | ||
fullWidth | ||
sx={{ mt: 2 }} | ||
> | ||
Generate Artifact | ||
</Button> | ||
</Box> | ||
); | ||
} |
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,50 @@ | ||
import React from "react"; | ||
|
||
import Typography from "@mui/material/Typography"; | ||
import Paper from "@mui/material/Paper"; | ||
|
||
import { ArtifactItem } from "src/generated/graphql"; | ||
import { ArtifactModifiers } from "./artifact-modifiers"; | ||
|
||
type ArtifactSelectionBoxProps = { | ||
artifact: ArtifactItem | null; | ||
isSelected: boolean; | ||
title: string; | ||
onSelect: () => void; | ||
}; | ||
|
||
export function ArtifactSelectionBox({ | ||
artifact, | ||
isSelected, | ||
title, | ||
onSelect | ||
}: ArtifactSelectionBoxProps): JSX.Element { | ||
return ( | ||
<Paper | ||
sx={{ | ||
flex: 1, | ||
p: 2, | ||
cursor: 'pointer', | ||
transition: 'all 0.2s', | ||
border: '2px solid', | ||
borderColor: isSelected ? 'primary.main' : 'divider', | ||
bgcolor: isSelected ? 'action.selected' : 'background.paper', | ||
'&:hover': { | ||
bgcolor: 'action.hover', | ||
}, | ||
}} | ||
elevation={isSelected ? 8 : 1} | ||
onClick={onSelect} | ||
> | ||
<Typography variant="h6" gutterBottom>{title}</Typography> | ||
{artifact ? ( | ||
<React.Fragment> | ||
<Typography variant="subtitle1">{artifact.name}</Typography> | ||
<ArtifactModifiers artifact={artifact} title={`${title} Stats`} /> | ||
</React.Fragment> | ||
) : ( | ||
<Typography color="text.secondary">No artifact equipped</Typography> | ||
)} | ||
</Paper> | ||
); | ||
} |
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,92 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import "@testing-library/jest-dom"; | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { ArtifactModal } from "./artifact-modal"; | ||
import { MeDocument, ArtifactAttributeType } from "src/generated/graphql"; | ||
|
||
const mockArtifact = { | ||
__typename: "ArtifactItem" as const, | ||
id: "test-id", | ||
owner: "test-owner", | ||
name: "Test Artifact", | ||
level: 1, | ||
attributes: { | ||
__typename: "ArtifactAttributes" as const, | ||
namePrefix: { __typename: "ArtifactAttribute" as const, type: ArtifactAttributeType.BonusPhysicalDamage, magnitude: 1 }, | ||
namePostfix: { __typename: "ArtifactAttribute" as const, type: ArtifactAttributeType.BonusHealth, magnitude: 1 }, | ||
bonusAffixes: [], | ||
titlePrefix: null, | ||
titlePostfix: null, | ||
}, | ||
}; | ||
|
||
const mocks = [ | ||
{ | ||
request: { | ||
query: MeDocument, | ||
}, | ||
result: { | ||
data: { | ||
me: { | ||
account: { | ||
hero: { | ||
equipment: { | ||
artifact: { | ||
...mockArtifact, | ||
id: "current-id", | ||
name: "Current Artifact", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
describe("ArtifactModal", () => { | ||
it("renders both artifacts and allows selection", async () => { | ||
const user = userEvent.setup(); | ||
const { getByText } = render( | ||
<MockedProvider mocks={mocks}> | ||
<ArtifactModal artifact={mockArtifact} /> | ||
</MockedProvider> | ||
); | ||
|
||
// Check that both artifacts are rendered | ||
expect(getByText("Current Artifact")).toBeInTheDocument(); | ||
expect(getByText("Test Artifact")).toBeInTheDocument(); | ||
|
||
// Continue button should be disabled initially | ||
const continueButton = getByText("Continue with Selected"); | ||
expect(continueButton).toBeDisabled(); | ||
|
||
// Select new artifact | ||
await user.click(getByText("Test Artifact")); | ||
expect(continueButton).toBeEnabled(); | ||
|
||
// Open confirmation dialog | ||
await user.click(continueButton); | ||
expect(getByText("Confirm Your Choice")).toBeInTheDocument(); | ||
expect(getByText(/Are you sure you want to keep the new artifact/)).toBeInTheDocument(); | ||
}); | ||
|
||
it("shows warning message in confirmation dialog", async () => { | ||
const user = userEvent.setup(); | ||
const { getByText } = render( | ||
<MockedProvider mocks={mocks}> | ||
<ArtifactModal artifact={mockArtifact} /> | ||
</MockedProvider> | ||
); | ||
|
||
// Select new artifact and open confirmation | ||
await user.click(getByText("Test Artifact")); | ||
await user.click(getByText("Continue with Selected")); | ||
|
||
// Check warning message | ||
expect(getByText("This action cannot be undone.")).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.