Unit Test
FlashcardCom Test Suite
Rendering and UI Elements
Test Case: Verify that the FlashcardComponent renders correctly and displays the initial UI elements.
Method: render()
Expected Result: The text 'Add Subject' should be present in the document.
Fetching Subjects and Flashcards on Load
Test Case: Ensure that subjects and flashcards are fetched from the repository when the component loads.
Method: getUserSubjects(), getUserFlashcardSets(), getFlashcardSetById()
Expected Result: The fetched subjects and flashcards should be correctly displayed on the screen.
Adding a New Subject
Test Case: Confirm that a new subject can be added.
Method: addUserSubject()
Expected Result: The addUserSubject method should be called with the correct parameters.
Creating a New Flashcard Set
Test Case: Validate that a new flashcard set can be created.
Method: createFlashcardSet()
Expected Result: The createFlashcardSet method should be invoked with the specified topic details.
Handling Topic Deletion
Test Case: Test the functionality of topic deletion.
Method: removeSetIdFromUser()
Expected Result: The removeSetIdFromUser method should be called with the correct user ID and set ID.
Handling Topic Editing
Test Case: Ensure that topics can be edited correctly.
Method: updateFlashcardSetName()
Expected Result: The updateFlashcardSetName method should be called with the correct set ID and new topic name.
FlashcardShare Component Test Suite
Rendering and UI Elements
Test Case: Verify that the FlashcardShare component renders correctly.
Method: render()
Expected Result: Initial UI elements of the FlashcardShare component should be displayed.
Fetching Flashcards on Load
Test Case: Confirm that flashcards are fetched from the repository upon component load.
Method: getFlashcardItems()
Expected Result: The fetched flashcards should be correctly displayed.
FlashcardUICom Component Test Suite
Rendering and Initial Display
Test Case: Validate that the FlashcardApp component renders and shows initial UI elements.
Method: render()
Expected Result: Initial UI elements of the FlashcardApp component should be visible.
Loading Flashcards, Comments, and User Image.
Test Case: Ensure that flashcards, comments, and user image are loaded on initialization.
Method: getFlashcardItems(), getCommentsWithUserData(), getUserImageURLByUid()
Expected Result: Flashcards, comments, and user image should be correctly fetched and displayed.
Adding a Flashcard
Test Case: Test the addition of a new flashcard.
Method: addFlashcardItem()
Expected Result: The addFlashcardItem method should be called with the correct set ID, term, and definition.
Deleting a Flashcard
Test Case: Validate the deletion of a flashcard.
Method: deleteFlashcard()
Expected Result: The deleteFlashcard method should be invoked with the appropriate set ID and flashcard ID.
Updating a Flashcard
Test Case: Confirm that a flashcard can be updated.
Method: updateFlashcard()
Expected Result: The updateFlashcard method should be called with the correct parameters.
Sending a Comment
Test Case: Test the functionality of sending a comment.
Method: addComment()
Expected Result: The addComment method should be invoked with the correct set ID and comment details.
Generating Flashcards with AI
Test Case: Validate the AI-based generation of flashcards.
Method: callYourCloudFunctionToGenerateFlashcards()
Expected Result: The callYourCloudFunctionToGenerateFlashcards method should be called with the specified parameters, and the generated flashcards should match the expected output.
Loading and Displaying Flashcards
Test Case: Ensure that flashcards are loaded and displayed correctly.
Method: getFlashcardItems()
Expected Result: The flashcards should be correctly fetched and displayed as per the data provided.
Quiz List Component Test Suite
Updates the Quiz Title
Test Case: "Updates the Quiz Title"
Method:
Renders an EditQuizDialog component with predefined props.
Verifies the correct rendering of the component title, text field, and buttons.
Simulates a user changing the text field and clicking the "Save" button.
Checks if the onEditQuizTitle and handleClose functions are called with the expected arguments.
Fetches and Displays Quiz Titles
Test Case: "Fetches and Displays Quiz Titles"
Method:
Mocks the FlashcardRepo.getQuizTitleFromFlashcardSet function to resolve with predefined quiz data.
Renders the QuizList component and waits for asynchronous operations to complete.
Asserts that the component renders the fetched quiz titles by checking each title against the container.
Quiz Component Test Suite
Does Not Add a Question When Input is Invalid
Test Case: "Does Not Add a Question When Input is Invalid"
Method:
Mocks the FlashcardRepo.addQuizQuestion to reject with an error.
Renders the FetchQuestions component and triggers a click on the "Add Question" button.
Expects that addQuizQuestion is not called.
Confirms Question Deletion
Test Case: "Confirms Question Deletion"
Method:
Sets up mock quiz and question IDs.
Calls FlashcardRepo.deleteQuestion and expects it to be called with the correct arguments.
Adds Owned Quiz to the User
Test Case: "Adds Owned Quiz to the User"
Method:
Mocks necessary functions and renders the CreateQuiz component.
Triggers a click on the "Create Quiz" button and waits for asynchronous operations to complete.
Expects that createNewQuiz and addOwnedQuizSetToUser functions are called with the correct arguments.
Handles Opening and Fetches Flashcard Set Name
Test Case: "Handles Opening and Fetches Flashcard Set Name"
Method:
Sets up mocks for necessary functions.
Calls flashcardSetHandler.handleOpenGenerateAI and expects mocked functions to be called with the correct arguments.
Generates Questions by Using AI Generating
Test Case: "Generates Questions by Using AI Generating"
Method:
Sets up mock data and mocks the function for generating flashcards using AI.
Calls the function and expects it to be called with the correct arguments and returns the mock data.
Retrieves the Quiz Title Using Quiz ID
Test Case: "Retrieves the Quiz Title Using Quiz ID"
Method:
- Calls FlashcardRepo.getQuizTitleFromFlashcardSet with a quiz ID and expects it to be called with the correct argument.
Retrieves the Quiz ID from a Flashcard Set
Test Case: "Retrieves the Quiz ID from a Flashcard Set"
Method:
- Calls FlashcardRepo.getQuizTitleId with quiz name and set ID and expects it to be called with the correct arguments.
Retrieves the Quiz ID from a Topic Name
Test Case: "Retrieves the Quiz ID from a Topic Name"
Method:
- Calls FlashcardRepo.getQuizIdByTopicName with a quiz name and expects it to be called with the correct argument.
Creates New Quiz for a Flashcard Set
Test Case: "Creates New Quiz for a Flashcard Set"
Method:
- Calls FlashcardRepo.createNewQuiz with a new quiz object and expects it to be called with the correct argument.
Gets Flashcard Items by Status
Test Case: "Gets Flashcard Items by Status"
Method:
- Calls FlashcardRepo.getFlashcardItemsByStatus with a status object and expects it to be called with the correct argument.
Updates User Score and Adds Attempt
Test Case: "Updates User Score and Adds Attempt"
Method:
- Calls FlashcardRepo.updateScoreAndAddAttempt with a score object and expects it to be called with the correct argument.
MainQuizPage Component Test Suite
Checking Answers
Test Case: Verify that the checkAnswer method updates the state with the selected answer.
Method: checkAnswer(index)
Expected Result: The state of the questions should reflect the selected answer. If the selected answer is correct, the corresponding question's userAnswer should match the correctChoice.
Calculating Score
Test Case: Ensure that the calculateScore method correctly calculates the score after all questions have been answered.
Method: calculateScore()
Expected Result: The calculated score percentage should be displayed based on the number of correct answers.
Calculating Initial Time
Test Case: Confirm that the calculateInitialTime method computes the initial time correctly when the component mounts based on the number of questions.
Method: calculateInitialTime()
Expected Result: The initial time displayed should be the total number of questions multiplied by the allotted time per question (in seconds).
Leaderboard Component Test Suite
Fetching Users and Scores
Test Case: Confirm that the fetchUsersAndScores method retrieves the list of users and their scores when the component loads.
Method: fetchUsersAndScores()
Expected Result: Upon component load, the leaderboard should be populated with user data, reflecting their scores and rankings.
Leaderboard Rendering
Test Case: Verify that the renderLeaderboard method displays the leaderboard with users ranked according to their scores.
Method: renderLeaderboard(data, title, key, rankKey)
Expected Result: Users should be listed in the order of their ranks based on scores, with UI elements showing their names and scores.
Search Handling
- Test Case: Ensure that the handleSearch method filters the leaderboard results according to the search query.
- Method: handleSearch(event)
- Expected Result: As a user types into the search field, the leaderboard should update in real-time to only display users whose names match the search query.
Event Repository Test Suite
CreateEvent
Test Case: Test creating an event.
Method: CreateEvent()
Expected Result: The event should be successfully created in the repository.
CreateNewFollowerEvent
Test Case: Test creating a new follower event.
Method: CreateNewFollowerEvent()
Expected Result: The new follower event should be successfully created in the repository.
CreateShareQuizEvent
Test Case: Test creating a share quiz event.
Method: CreateShareQuizEvent()
Expected Result: The share quiz event should be successfully created in the repository.
CreateShareFlashCardEvent
Test Case: Test creating a share flashcard event.
Method: CreateShareFlashCardEvent()
Expected Result: The share flashcard event should be successfully created in the repository.
CreateUpcomingEvent
Test Case: Test creating an upcoming event.
Method: CreateUpcomingEvent()
Expected Result: The upcoming event should be successfully created in the repository.
GetEvent
Test Case: Test getting an event by id.
Method: GetEvent(eventId)
Expected Result: The event with the specified eventId should be retrieved from the repository.
GetPastEvent
Test Case: Test getting an event that is in the past.
Method: GetPastEvent()
Expected Result: A past event should be retrieved from the repository.
GetUpcomingEvent
Test Case: Test getting an upcoming event.
Method: GetUpcomingEvent()
Expected Result: An upcoming event should be retrieved from the repository.
UpdateUpcomingEvent
Test Case: Test updating an upcoming event.
Method: UpdateUpcomingEvent(eventId, updatedEvent)
Expected Result: The upcoming event with the specified eventId should be successfully updated in the repository.
MarkAsNotified
- Test Case: Test marking a past event as notified.
- Method: MarkAsNotified(eventId)
- Expected Result: The specified past event should be marked as notified in the repository.
Notification Repository Test Suite
getNotificationById
Test Case: Test getting notification by id.
Method: getNotificationById(notificationId)
Expected Result: The notification with the specified notificationId should be retrieved from the repository.
addNotification
Test Case: Test adding a notification.
Method: addNotification(notification)
Expected Result: The notification should be successfully added to the repository.
getListOfNotifications
Test Case: Test getting a list of notifications.
Method: getListOfNotifications()
Expected Result: A list of notifications should be retrieved from the repository.
UpdateNotification
Test Case: Test updating a notification.
Method: UpdateNotification(notificationId, updatedNotification)
Expected Result: The notification with the specified notificationId should be successfully updated in the repository.
QuizRepository Test Suite
Test whether you can fetch all quizzes
Test Case: Test whether you can fetch all quizzes.
Method: get_AllQuizzes()
Expected Result: The repository should successfully fetch all quizzes.
Handles errors when fetching all quizzes
Test Case: Handles errors when fetching all quizzes.
Method: get_AllQuizzes()
Expected Result: The repository should handle errors gracefully when attempting to fetch all quizzes.
Tests the functionality of finding a quiz with a valid id
Test Case: Tests the functionality of finding a quiz with a valid id.
Method: get_QuizById(validQuizId)
Expected Result: The repository should successfully find and return the quiz with the validQuizId.
Tests the failure case of finding a quiz with an invalid id
Test Case: Tests the failure case of finding a quiz with an invalid id.
Method: get_QuizById(invalidQuizId)
Expected Result: The repository should handle the failure case gracefully and return an appropriate error or null when attempting to find a quiz with an invalid id.
Flashcard Repository Test Suite
Test the functionality of retrieving a flashcard set by id
Test Case: Test the functionality of retrieving a flashcard set by id.
Method: getFlashcardSet(flashcardSetId)
Expected Result: The repository should successfully retrieve and return the flashcard set with the specified flashcardSetId.
getAll_flashcardSet
Test Case: Test the functionality of retrieving all flashcard sets from the database.
Method: getAll_flashcardSet()
Expected Result: The repository should successfully retrieve and return all flashcard sets from the database.
getFlashcardSetBy_Id
Test Case: Test the functionality of retrieving a flashcard set by id.
Method: getFlashcardSetBy_Id(flashcardSetId)
Expected Result: The repository should successfully retrieve and return the flashcard set with the specified flashcardSetId.
getFlashcards
Test Case: Tests the functionality of retrieving flashcards given a list of ids.
Method: getFlashcards(flashcardIds)
Expected Result: The repository should successfully retrieve and return the flashcards corresponding to the list of flashcardIds.
UserRepository Test Suite
Get Item
Test Case: Test get user flashcards
Method: getUserFlashcards(userId)
Expected Result: The repository should successfully retrieve and return the flashcards associated with the specified userId.
Test get user quizzes
Test Case: Test get user quizzes
Method: getUserQuizzes(userId)
Expected Result: The repository should successfully retrieve and return the quizzes associated with the specified userId.
Test get user events
Test Case: Test get user events
Method: getUserEvents(userId)
Expected Result: The repository should successfully retrieve and return the events associated with the specified userId.
Test get user notifications
Test Case: Test get user notifications
Method: getUserNotifications(userId)
Expected Result: The repository should successfully retrieve and return the notifications associated with the specified userId.
Test get user upcoming events
Test Case: Test get user upcoming events
Method: getUserUpcomingEvents(userId)
Expected Result: The repository should successfully retrieve and return the upcoming events associated with the specified userId.
Getting Item by Id
Test Case: Followers - Test Get followers by id
Method: getFollowersById(userId)
Expected Result: The repository should successfully retrieve and return the followers of the user with the specified userId.
Test Get following by id
Test Case: Following - Test Get following by id
Method: getFollowingById(userId)
Expected Result: The repository should successfully retrieve and return the users followed by the user with the specified userId.
Test Get events by id
Test Case: Events - Test Get events by id
Method: getEventsById(userId)
Expected Result: The repository should successfully retrieve and return the events associated with the user with the specified userId.
Test Get notifications by id
Test Case: Notifications - Test Get notifications by id
Method: getNotificationsById(userId)
Expected Result: The repository should successfully retrieve and return the notifications associated with the user with the specified userId.
Test Get shared quizzes by id
Test Case: Shared Quizzes - Test Get shared quizzes by id
Method: getSharedQuizzesById(userId)
Expected Result: The repository should successfully retrieve and return the shared quizzes associated with the user with the specified userId.
Test Get owned quizzes by id
Test Case: Owned Quizzes - Test Get owned quizzes by id
Method: getOwnedQuizzesById(userId)
Expected Result: The repository should successfully retrieve and return the owned quizzes associated with the user with the specified userId.
Test Get upcoming events by id
Test Case: Upcoming Events - Test Get upcoming events by id
Method: getUpcomingEventsById(userId)
Expected Result: The repository should successfully retrieve and return the upcoming events associated with the user with the specified userId.
Adding Item by Add
Test Case: Followers - Test Add followers by id
Method: addFollowerById(userId, followerId)
Expected Result: The repository should successfully add the follower (followerId) to the user with the specified userId.
Following - Test Add following by id
Test Case: Following - Test Add following by id
Method: addFollowingById(userId, followingId)
Expected Result: The repository should successfully add the following (followingId) to the user with the specified userId.
Test Add events by id
Test Case: Events - Test Add events by id
Method: addEventById(userId, eventId)
Expected Result: The repository should successfully add the event (eventId) to the user with the specified userId.
Test Add notifications by id
Test Case: Notifications - Test Add notifications by id
Method: addNotificationById(userId, notificationId)
Expected Result: The repository should successfully add the notification (notificationId) to the user with the specified userId.
Test Add shared quizzes by id
Test Case: Shared Quizzes - Test Add shared quizzes by id
Method: addSharedQuizById(userId, quizId)
Expected Result: The repository should successfully add the shared quiz (quizId) to the user with the specified userId.
Test Add owned quizzes by id
Test Case: Owned Quizzes - Test Add owned quizzes by id
Method: addOwnedQuizById(userId, quizId)
Expected Result: The repository should successfully add the owned quiz (quizId) to the user with the specified userId.
Test Add upcoming events by id
Test Case: Upcoming Events - Test Add upcoming events by id
Method: addUpcomingEventById(userId, eventId)
Expected Result: The repository should successfully add the upcoming event (eventId) to the user with the specified userId.
Test should convert 24-hour time to 12-hour format
Test Case: Test should convert 24-hour time to 12-hour format
Method: convertTo12HourFormat(time)
Expected Result: The method should successfully convert the given 24-hour time to 12-hour format.
test should return the short form of the day of the week
Test Case: Test should return the short form of the day of the week
Method: getShortDayOfWeek(dayOfWeek)
Expected Result: The method should successfully return the short form of the given day of the week.
Test should return the abbreviated month name
Test Case: Test should return the abbreviated month name
Method: getAbbreviatedMonthName(month)
Expected Result: The method should successfully return the abbreviated month name for the given month.
Test should return true for a future timestamp
Test Case: Test should return true for a future timestamp
Method: isFutureTimestamp(timestamp)
Expected Result: The method should return true if the timestamp is in the future.
Test should return false for a past timestamp
- Test Case: Test should return false for a past timestamp
- Method: isFutureTimestamp(timestamp)
- Expected Result: The method should return false if the timestamp is in the past.
Test Remove follower by id
Test Case: Follower - Test Remove follower by id
Method: removeFollowerById(userId, followerId)
Expected Result: The repository should successfully remove the follower (followerId) from the user with the specified userId.
Test Remove following by id
Test Case: Following - Test Remove following by id
Method: removeFollowingById(userId, followingId)
Expected Result: The repository should successfully remove the following (followingId) from the user with the specified userId.
Test Remove notifications by id
Test Case: Notifications - Test Remove notifications by id
Method: removeNotificationById(userId, notificationId)
Expected Result: The repository should successfully remove the notification (notificationId) from the user with the specified userId.
Test Remove upcoming events by id
Test Case: Upcoming Events - Test Remove upcoming events by id
Method: removeUpcomingEventById(userId, eventId)
Expected Result: The repository should successfully remove the upcoming event (eventId) from the user with the specified userId.