-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
had to fix some weird webpack problem by setting the webpack version had to config next a bit more because of that same webpack problem
- Loading branch information
1 parent
6719d95
commit df34dd7
Showing
15 changed files
with
19,191 additions
and
9,392 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
25 changes: 25 additions & 0 deletions
25
...resources/GearPageTemplate/GearTable/ResourceButtons/SettingRating/SettingRating.test.tsx
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,25 @@ | ||
import { otherElectronics } from "@/data/electronics" | ||
import { render, SliderHelper } from "@/test/testUtils" | ||
import { SettingRating } from "./index" | ||
|
||
describe("<SettingRating />", () => { | ||
const setup = () => { | ||
const headJammer = otherElectronics[2] | ||
const dispatch = jest.fn() | ||
return { | ||
...render(<SettingRating gear={headJammer} setRating={dispatch} />), | ||
dispatch, | ||
} | ||
} | ||
it("should call setRating after changing the slider", () => { | ||
const { getByTestId, dispatch } = setup() | ||
|
||
expect(getByTestId("Headjammer-rating").querySelector("input")).toHaveValue( | ||
"1", | ||
) | ||
|
||
SliderHelper.change(getByTestId("Headjammer-rating"), 5, 1, 6) | ||
|
||
expect(dispatch).toHaveBeenCalledWith(5) | ||
}) | ||
}) |
27 changes: 27 additions & 0 deletions
27
...nents/runner/resources/GearPageTemplate/GearTable/ResourceButtons/SettingRating/index.tsx
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 { GearTyped } from "@/types/Resources" | ||
import { Slider } from "@material-ui/core" | ||
import { FC } from "react" | ||
|
||
export interface Props { | ||
setRating: (rating: number) => void | ||
gear: GearTyped | ||
} | ||
|
||
export const SettingRating: FC<Props> = ({ | ||
setRating, | ||
gear: { name, maxRating = 6, currentRating = 1 }, | ||
}) => ( | ||
<Slider | ||
data-testid={`${name}-rating`} | ||
onChange={(event, value) => setRating(+value)} | ||
defaultValue={1} | ||
getAriaValueText={(value) => value.toString()} | ||
aria-labelledby={`${name} rating slider`} | ||
valueLabelDisplay="auto" | ||
step={1} | ||
marks | ||
min={1} | ||
max={maxRating} | ||
value={currentRating} | ||
/> | ||
) |
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 |
---|---|---|
|
@@ -33,3 +33,5 @@ export const RemoveResourceButton: FC<RemoveGearButtonProps> = ({ | |
/> | ||
) | ||
} | ||
|
||
export * from "./SettingRating" |
56 changes: 56 additions & 0 deletions
56
components/runner/resources/GearPageTemplate/GearTable/Row/RatingRow.test.tsx
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,56 @@ | ||
import { otherElectronics } from "@/data/electronics" | ||
import { render, SliderHelper } from "@/test/testUtils" | ||
import { | ||
DispatchContext, | ||
gearRatingTableConfigOption, | ||
gearTableConfigOptions, | ||
} from "../../../util" | ||
import { RatingRow } from "./index" | ||
|
||
describe("<RatingRow/>", () => { | ||
const headJammer = otherElectronics[2] | ||
const setup = () => { | ||
const cols = [ | ||
gearTableConfigOptions.buy, | ||
gearRatingTableConfigOption.setRating, | ||
] | ||
const dispatch = jest.fn() | ||
|
||
return { | ||
...render( | ||
<DispatchContext.Provider value={dispatch}> | ||
<table> | ||
<tbody> | ||
<RatingRow gear={headJammer} index={1} cols={cols} /> | ||
</tbody> | ||
</table> | ||
</DispatchContext.Provider>, | ||
), | ||
dispatch, | ||
} | ||
} | ||
|
||
it("set current rating to 1 if not set", () => { | ||
const { getByLabelText, dispatch } = setup() | ||
|
||
getByLabelText(`Add ${headJammer.name}`).click() | ||
|
||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: undefined, | ||
payload: { ...headJammer, currentRating: 1 }, | ||
}) | ||
}) | ||
|
||
it("should update rating and purchase gear", () => { | ||
const { getByLabelText, getByTestId, dispatch } = setup() | ||
|
||
SliderHelper.change(getByTestId("Headjammer-rating"), 5, 1, 6) | ||
|
||
getByLabelText(`Add ${headJammer.name}`).click() | ||
|
||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: undefined, | ||
payload: { ...headJammer, currentRating: 5, cost: 750 }, | ||
}) | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
components/runner/resources/GearPageTemplate/GearTable/Row/index.tsx
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,45 @@ | ||
import { FC, useMemo, useState } from "react" | ||
import { Gear, GearTyped } from "@/types/Resources" | ||
import { TableCell, TableRow } from "@material-ui/core" | ||
import { Columns } from "../../../util" | ||
|
||
export interface Props { | ||
cols: Columns<Gear>[] | ||
gear: Gear | ||
index: number | ||
} | ||
|
||
export const StandardDisplayRow: FC<Props> = ({ cols, gear, index }) => ( | ||
<TableRow> | ||
{cols.map(({ display, label }) => ( | ||
<TableCell key={label}>{display(gear, index)}</TableCell> | ||
))} | ||
</TableRow> | ||
) | ||
|
||
interface RatingRowProps extends Props { | ||
cols: Columns<GearTyped>[] | ||
gear: GearTyped | ||
} | ||
|
||
export const RatingRow: FC<RatingRowProps> = ({ cols, gear, index }) => { | ||
const [currentRating, setRating] = useState(1) | ||
const gearWithRating = useMemo( | ||
() => ({ | ||
...gear, | ||
currentRating, | ||
cost: gear.cost * currentRating, | ||
}), | ||
[currentRating], | ||
) | ||
|
||
return ( | ||
<TableRow> | ||
{cols.map(({ display, label }) => ( | ||
<TableCell key={label}> | ||
{display(gearWithRating, index, setRating)} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { ReactNode } from "react" | ||
|
||
export interface Columns<G> { | ||
display: (gear: G, index: number) => ReactNode | ||
display: ( | ||
gear: G, | ||
index?: number, | ||
update?: (update: number) => void, | ||
) => ReactNode | ||
label: string | ||
} |
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
Oops, something went wrong.