-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comments): add new object (#124)
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 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,26 @@ | ||
import Field from "./Field"; | ||
|
||
class Comments extends Field { | ||
/** | ||
* Height of the comments component | ||
*/ | ||
_height: number | undefined = undefined; | ||
|
||
get height(): number | undefined { | ||
return this._height; | ||
} | ||
|
||
set height(value: number | undefined) { | ||
this._height = value; | ||
} | ||
|
||
constructor(props: any) { | ||
super(props); | ||
if (props.height) { | ||
const parsedHeight = parseInt(props.height); | ||
this._height = isNaN(parsedHeight) ? undefined : parsedHeight; | ||
} | ||
} | ||
} | ||
|
||
export default Comments; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Write specs for the Comments component here with vitest | ||
import { describe, it, expect } from "vitest"; | ||
import Comments from "../Comments"; | ||
|
||
describe("Comments", () => { | ||
it("sets height when provided in props", () => { | ||
const comments = new Comments({ height: "150" }); | ||
expect(comments.height).toBe(150); | ||
}); | ||
|
||
it("defaults height to undefined when not provided in props", () => { | ||
const comments = new Comments({}); | ||
expect(comments.height).toBeUndefined(); | ||
}); | ||
|
||
it("sets height to undefined when provided height is not a number", () => { | ||
const comments = new Comments({ height: "invalid" }); | ||
expect(comments.height).toBeUndefined(); | ||
}); | ||
|
||
it("updates height when set with a valid number", () => { | ||
const comments = new Comments({}); | ||
comments.height = 200; | ||
expect(comments.height).toBe(200); | ||
}); | ||
|
||
it("updates height to undefined when set with an invalid value", () => { | ||
const comments = new Comments({}); | ||
comments.height = undefined; | ||
expect(comments.height).toBeUndefined(); | ||
}); | ||
}); |
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