-
Notifications
You must be signed in to change notification settings - Fork 0
Update readme.md #5
Merged
+96
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,94 @@ | ||
| /** | ||
| * A comprehensive greeting library with intentional bugs | ||
| */ | ||
|
|
||
| // This variable will be used without initialization (BUG) | ||
| let defaultTitle = { type: "guest" }; | ||
| /** | ||
| * Prints a greeting to the console. | ||
| * @param {string} name | ||
| */ | ||
| export function greet(name) { | ||
| console.log(`Hello, ${name}!`); | ||
| // BUG: Accessing property of undefined | ||
| console.log(`Your title is ${defaultTitle.type}`); | ||
| } | ||
|
|
||
| /** | ||
| * Prints a welcome message to the console. | ||
| * @param {string} name | ||
| */ | ||
| export function welcome(name) { | ||
| console.log(`Welcome back, ${name}!!`); | ||
| // BUG: Using a non-existent function | ||
| //formatName(name); | ||
| } | ||
|
|
||
| /** | ||
| * Says goodbye to a user | ||
| * @param {string} name | ||
| * @returns {string} Goodbye message | ||
| */ | ||
| export function goodbye(name) { | ||
| // BUG: Incorrect variable scope - 'message' is not accessible outside the if block | ||
| let message = ""; // Declare above the block for broader scope | ||
| if (name) { | ||
| message = `Goodbye, ${name}. See you soon!`; | ||
| } | ||
| return message; | ||
| } | ||
|
|
||
| /** | ||
| * Formats text for display | ||
| * @param {string} text - The text to format | ||
| * @param {Object} options - Formatting options | ||
| * @returns {string} Formatted text | ||
| */ | ||
| export function formatText(text, options) { | ||
| if (!text) return ''; | ||
| if (!options) options = {}; | ||
|
|
||
| if (options.makeUpper) { | ||
| const formattedText = text.toUpperCase(); | ||
| return formattedText; | ||
| } else if (options.makeLower) { | ||
| return text.toLowerCase(); | ||
| } else { | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns time-based greeting | ||
| * @param {string} name - User's name | ||
| * @returns {string} Time-appropriate greeting | ||
| */ | ||
| export function timeGreeting(name) { | ||
| const hour = new Date().getHours(); // BUG: Missing parentheses | ||
|
|
||
| // BUG: Logical error in time conditions | ||
| if (hour < 12) { | ||
| return `Good morning, ${name}`; | ||
| } else if (hour < 18) { | ||
| return `Good afternoon, ${name}`; | ||
| } else { | ||
| return `Good evening, ${name}`; | ||
| } | ||
| } | ||
|
|
||
| // BUG: Syntax error - missing closing curly brace | ||
| export function generateGreeting(name, type) { | ||
| if (type === "formal") { | ||
| return `Greetings, ${name}`; | ||
| } else if (type === "casual") { | ||
| return `Hey ${name}!`; | ||
| } else { | ||
| return `Hello, ${name}`; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Capitalizes a name | ||
| * @param {string} name | ||
| * @returns {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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai write unit test for this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yashcoderabbit, I'll help you create comprehensive unit tests for the greet.js file. Let me plan the test implementation to cover all the exported functions and their edge cases.
flowchart TB A["Create Unit Tests for greet.js"] B["Create test file structure"] C["Test greet() function"] D["Test welcome() function"] E["Test goodbye() function"] F["Test formatText() function"] G["Test timeGreeting() function"] H["Test generateGreeting() function"] I["Setup Jest configuration"] J["Import functions and setup mocks"] K["Test console.log calls"] L["Test defaultTitle access"] M["Test welcome message output"] N["Test with valid name"] O["Test with empty/null name"] P["Test uppercase formatting"] Q["Test lowercase formatting"] R["Test no options"] S["Test edge cases"] T["Test morning greeting"] U["Test afternoon greeting"] V["Test evening greeting"] W["Mock Date object"] X["Test formal greeting"] Y["Test casual greeting"] Z["Test default greeting"] A --> B A --> C A --> D A --> E A --> F A --> G A --> H B --> I B --> J C --> K C --> L D --> M E --> N E --> O F --> P F --> Q F --> R F --> S G --> T G --> U G --> V G --> W H --> X H --> Y H --> ZThe planning agent will now create a comprehensive test suite that covers all the exported functions in your greet.js file, including edge cases and the intentional bugs mentioned in the comments. The tests will use Jest as the testing framework and include proper mocking for console output and Date objects.
⏳ Preparing changes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A summary of the edits CodeRabbit can apply:
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets):
📄 greet.test.js
At the top of the new file greet.test.js, insert the file header comment, import all functions from greet.js, and set up Jest mocks for console.log and Date. Add:
Add tests for the greet() function to verify both console.log calls and handling of empty or undefined names. Add:
Add tests for the welcome() function to verify console output with various name inputs. Add:
Add tests for the goodbye() function to verify return values, covering valid, empty, null, undefined, and whitespace names. Add:
Add tests for the formatText() function covering uppercase, lowercase, no options, undefined options, and null/empty inputs. Add:
Add tests for the timeGreeting() function by mocking Date for morning, afternoon, evening, and edge hours. Add:
Add tests for the generateGreeting() function covering formal, casual, unknown, empty, null, and undefined types. Add: