Skip to content

Commit

Permalink
refactor(tests): ✅ updated tests for meter & progress
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Oct 20, 2020
1 parent e199382 commit 6ebb5c8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/meter/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { METER_KEYS } from "./__keys";
import { MeterStateReturn } from "./MeterState";

export type MeterOptions = BoxOptions &
Pick<MeterStateReturn, "value" | "max" | "min">;
Pick<MeterStateReturn, "value" | "max" | "min" | "ariaValueText">;

export type MeterHTMLProps = BoxHTMLProps;

Expand All @@ -16,8 +16,9 @@ const useMeter = createHook<MeterOptions, MeterHTMLProps>({
compose: useBox,
keys: METER_KEYS,

useProps(options, { "aria-valuetext": ariaValueText, ...htmlProps }) {
const { value, max, min } = options;
useProps(options, htmlProps) {
const { value, max, min, ariaValueText } = options;
console.log("%c ariaValueText", "color: #99adcc", ariaValueText);

// Use the meter role if available, but fall back to progressbar if not
// Chrome currently falls back from meter automatically, and Firefox
Expand Down
2 changes: 1 addition & 1 deletion src/meter/MeterState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ export const useMeterState = (
percent,
ariaValueText: isFunction(ariaValueText)
? ariaValueText?.(value, percent)
: `${value}%`,
: `${percent}%`,
};
};
7 changes: 4 additions & 3 deletions src/meter/__keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const METER_STATE_KEYS = [
"min",
"max",
"low",
"optimum",
"high",
"status",
"optimum",
"ariaValueText",
"percent",
"status",
] as const;
export const METER_KEYS = [...METER_STATE_KEYS, "getAriaValueText"] as const;
export const METER_KEYS = METER_STATE_KEYS;
2 changes: 1 addition & 1 deletion src/meter/__tests__/Meter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Meter", () => {
role="meter progressbar"
/>
</div>
`);
`);
});

it("checks role", function () {
Expand Down
2 changes: 1 addition & 1 deletion src/progress/ProgressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ export function useProgressState(
percent,
ariaValueText: isFunction(ariaValueText)
? ariaValueText?.(value, percent)
: `${value}%`,
: `${percent}%`,
};
}
2 changes: 1 addition & 1 deletion src/progress/__keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const PROGRESS_STATE_KEYS = [
"min",
"max",
"isIndeterminate",
"percent",
"ariaValueText",
"percent",
"setValue",
] as const;
export const PROGRESS_KEYS = PROGRESS_STATE_KEYS;
2 changes: 1 addition & 1 deletion src/progress/__tests__/Progress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Progress", () => {
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="10"
aria-valuetext="10"
aria-valuetext="10%"
data-testid="progress"
role="progressbar"
/>
Expand Down

0 comments on commit 6ebb5c8

Please sign in to comment.