-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Datagrid's number cell paste issue for certain values (#4811)
* fix datagrid paste issue * use regex and add tests * changeset * ignore strict * remove comment --------- Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
- Loading branch information
Showing
3 changed files
with
85 additions
and
9 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,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Fixes an issue that prevented users from pasting values smaller than 10 into datagrid cells |
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,77 @@ | ||
// @ts-strict-ignore | ||
import { Locale } from "@dashboard/components/Locale"; | ||
|
||
import { | ||
numberCellEmptyValue, | ||
NumberCellProps, | ||
numberCellRenderer, | ||
} from "./NumberCell"; | ||
|
||
const locale = Locale.EN; | ||
|
||
describe("NumberCell renderer", () => { | ||
it("should paste integer value", () => { | ||
// Arrange | ||
const { onPaste } = numberCellRenderer(locale); | ||
const value = "10"; | ||
const data = { value: 0 } as NumberCellProps; | ||
|
||
// Act | ||
const result = onPaste(value, data); | ||
|
||
// Assert | ||
expect(result.value).toBe(10); | ||
}); | ||
|
||
it("should paste float value", () => { | ||
// Arrange | ||
const { onPaste } = numberCellRenderer(locale); | ||
const value = "10.5"; | ||
const data = { value: 0 } as NumberCellProps; | ||
|
||
// Act | ||
const result = onPaste(value, data); | ||
|
||
// Assert | ||
expect(result.value).toBe(10.5); | ||
}); | ||
|
||
it("should return empty cell if value is negative", () => { | ||
// Arrange | ||
const { onPaste } = numberCellRenderer(locale); | ||
const value = "-10"; | ||
const data = { value: 0 } as NumberCellProps; | ||
|
||
// Act | ||
const result = onPaste(value, data); | ||
|
||
// Assert | ||
expect(result.value).toBe(numberCellEmptyValue); | ||
}); | ||
|
||
it("should return empty cell if value is not a number", () => { | ||
// Arrange | ||
const { onPaste } = numberCellRenderer(locale); | ||
const value = "UwU"; | ||
const data = { value: 0 } as NumberCellProps; | ||
|
||
// Act | ||
const result = onPaste(value, data); | ||
|
||
// Assert | ||
expect(result.value).toBe(numberCellEmptyValue); | ||
}); | ||
|
||
it("should paste integer value under 10", () => { | ||
// Arrange | ||
const { onPaste } = numberCellRenderer(locale); | ||
const value = "5"; | ||
const data = { value: 0 } as NumberCellProps; | ||
|
||
// Act | ||
const result = onPaste(value, data); | ||
|
||
// Assert | ||
expect(result.value).toBe(5); | ||
}); | ||
}); |
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