-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests, moved logic to utils folder, fixed prop injection bug, a…
…nd refactored code
- Loading branch information
1 parent
c38dc8c
commit 021b83b
Showing
7 changed files
with
641 additions
and
56 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
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
53 changes: 53 additions & 0 deletions
53
packages/perseus-editor/src/util/modernize-widgets-utils.test.ts
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,53 @@ | ||
import {convertDeprecatedWidgets} from "./modernize-widgets-utils"; | ||
import { | ||
inputNumberNested, | ||
inputNumberNestedWithNumeric, | ||
inputNumberSimple, | ||
numericInputNested, | ||
numericInputNestedWithNumeric, | ||
numericInputSimple, | ||
} from "./modernize-widgets-utils.testdata"; | ||
|
||
describe("convertDeprecatedWidgets", () => { | ||
it("should be able to convert a simple input number widget into numeric input", () => { | ||
// Arrange | ||
const input = inputNumberSimple; | ||
const expected = numericInputSimple; | ||
|
||
// Act | ||
const result = convertDeprecatedWidgets(input); | ||
|
||
// Assert | ||
expect(result.content).toEqual(expected.content); | ||
expect(result.widgets).toEqual(expected.widgets); | ||
}); | ||
|
||
it("should be able to convert a nested input number widget", () => { | ||
// This test has the inputNumber widget nested within a gradedGroup widget | ||
|
||
// Arrange | ||
const input = inputNumberNested; | ||
const expected = numericInputNested; | ||
|
||
// Act | ||
const result = convertDeprecatedWidgets(input); | ||
|
||
// Assert | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it("should be able to continue id numbering even with nested widgets", () => { | ||
// This test has 2 pre-existing numericInput widgets, with one of them being nested | ||
// within a graded group. As a result, the inputNumber widget should become "numeric-input 3". | ||
|
||
// Arrange | ||
const input = inputNumberNestedWithNumeric; | ||
const expected = numericInputNestedWithNumeric; | ||
|
||
// Act | ||
const result = convertDeprecatedWidgets(input); | ||
|
||
// Assert | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.