CSC/ECE 517 Spring 2024 - E2440 Testing for questionnaire helper, review bids helper: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 103: Line 103:
     - Determines the proportion of bids compared to the total number of participants and adjusts the color accordingly.
     - Determines the proportion of bids compared to the total number of participants and adjusts the color accordingly.
     - Returns a string representing the RGB value of the background color.
     - Returns a string representing the RGB value of the background color.
== Hamer value calculation ==
[[File:Step1.PNG|400px]]
<br>
[[File:Step2.PNG|400px]]
<br>
[[File:Step3.PNG|400px]]
<br>
[[File:Step4.PNG|400px]]


== Objective 1: Develop code testing scenarios for questionnaire_helper ==
== Objective 1: Develop code testing scenarios for questionnaire_helper ==

Revision as of 00:35, 9 April 2024

This page describes the changes made for the Spring 2024 E2440. Testing for questionnaire_helper, review_bids_helper

Project Overview

Problem Statement

Our project involves writing test cases for the `questionnaire_helper` and `review_bids_helper` files in Expertiza, an open-source assignment/project management portal built on the Ruby on Rails framework. This platform facilitates collaborative learning and feedback among both instructors and students. Instructors can create and customize assignments, define topics for student sign-ups, and manage teams for various projects. Students, on the other hand, can sign up for topics, form teams, and participate in peer reviews to enhance each other's learning experiences. Our goal is to develop comprehensive test plans and increase code coverage for these helper files to ensure their reliability and effectiveness in the Expertiza platform.

Current Code Coverage

Objectives

  • Develop test plans/scenarios for questionnaire_helper.rb
  • Develop test plans/scenarios for review_bids_helper.rb
  • Improve code coverage for questionnaire_helper.rb
  • Improve code coverage for review_bids_helper.rb

Files Involved

  • Questionnaire_helper.rb: /app/helpers/questionnaire_helper.rb
  • Review_bids_helper.rb: /app/helpers/review_bids_helper.rb

Mentor

  • Muhammet Mustafa Olmez (molmez@ncsu.edu)

Team Members

  • Neha Vijay Patil (npatil2@ncsu.edu)
  • Prachit Mhalgi (psmhalgi@ncsu.edu)
  • Sahil Santosh Sawant (ssawant2@ncsu.edu)

Class and Method Overview

QuestionnaireHelper

The QuestionnaireHelper module contains several methods to assist with managing questionnaires in expertiza. QuestionnaireHelper provides methods for adjusting advice size, updating questionnaire questions, and creating questionnaire instances based on types. It also defines constants to facilitate these functionalities. These methods are likely used within the application to handle questionnaire-related tasks efficiently. Let's break down the class and its methods:

Constants

CSV_QUESTION, CSV_TYPE, CSV_PARAM, CSV_WEIGHT

  - These constants define indices for specific columns in a CSV file.

QUESTIONNAIRE_MAP

  - This constant is a hash that maps questionnaire types to their respective questionnaire classes.
  - It's used by the `questionnaire_factory` method to determine the appropriate class to instantiate.

Methods

1. adjust_advice_size(questionnaire, question)

  - This method adjusts the size of advice associated with a given question in a questionnaire.
  - Parameters:
    - `questionnaire`: The questionnaire object.
    - `question`: The question object whose advice size needs adjustment.
  - Functionality:
    - Checks if the question is a `ScoredQuestion`.
    - Deletes any existing advice for the question outside the score range.
    - Iterates over the score range and ensures each score has an associated advice.
    - Deletes any duplicate advice records.
  

2. update_questionnaire_questions

  - This method updates attributes of questionnaire questions based on form data, without modifying unchanged attributes.
  - Functionality:
    - Checks for presence of `params[:question]`.
    - Iterates through each question and its attributes in the parameters.
    - Compares each attribute's current value with the new value from the parameters and updates if changed.
    - Saves the question.

3. questionnaire_factory(type)

  - This method acts as a factory to create an appropriate questionnaire object based on the type provided.
  - Parameters:
    - `type`: The type of questionnaire.
  - Functionality:
    - Retrieves the questionnaire class from `QUESTIONNAIRE_MAP` based on the provided type.
    - If the type is not found in the map, it sets an error flash message.
    - Otherwise, it initializes a new instance of the corresponding questionnaire class and returns it.

ReviewBidsHelper

This Ruby module, `ReviewBidsHelper` serves as a helper module for views related to reviewing bids in expertiza. `ReviewBidsHelper` provides helper methods for rendering topic rows and determining the background color for topics based on their bid status and the number of participants. These methods are likely used in the views associated with reviewing bids in the application. Let's break down the class and its methods:

Methods

1. get_intelligent_topic_row_review_bids(topic, selected_topics, num_participants)

  - This method seems to be responsible for generating HTML markup for a row in a table displaying topics for review bids.
  - Parameters:
    - `topic`: Represents a specific topic being reviewed.
    - `selected_topics`: An array of topics that have been selected.
    - `num_participants`: The number of participants involved in the review process.
  - Functionality:
    - Iterates through the `selected_topics`.
    - Depending on the conditions (whether the topic is selected and not waitlisted, or selected and waitlisted), it generates a specific row HTML.
    - Returns the generated row HTML as safe HTML.

2. get_topic_bg_color_review_bids(topic, num_participants)

  - This method calculates the background color for a topic based on the number of participants and the number of bids for that topic.
  - Parameters:
    - `topic`: Represents the topic for which the background color is being determined.
    - `num_participants`: The total number of participants.
  - Functionality:
    - Calculates the number of bids for the given `topic`.
    - Determines the proportion of bids compared to the total number of participants and adjusts the color accordingly.
    - Returns a string representing the RGB value of the background color.

Objective 1: Develop code testing scenarios for questionnaire_helper

We follow the single responsibility principle so that each test only tests After reviewing the QuestionnaireHelper class, we identified three methods in the class that require testing. These methods are as follows:

  • adjust_advice_size
  • update_questionnaire_questions
  • questionnaire_factory

For testing purposes, we mock the following items:

let(:questionnaire) { double('Questionnaire', max_question_score: 5, min_question_score: 1) }
let(:question) { double('ScoredQuestion', id: 1) }

adjust_advice_size

To test this method, we mock a questionnaire and a scored question. We verify that the method correctly adjusts the size of advice for a scored question. We identify the following test cases:

  • When the question is a ScoredQuestion: Verify that the method adjusts advice size by ensuring the correct number of advices are created, advices outside the range are deleted, and duplicate advices are removed. Test scenarios when the question's score is within the defined range, above the range, and below the range.
  • When the question is not a ScoredQuestion: Verify that the method does not adjust advice size for non-scored questions.

update_questionnaire_questions

This method updates attributes of questionnaire questions based on form data. To test this method, we mock a question and its associated form data. We identify the following test cases:

  • When params contain questions: Verify that the method updates question attributes when parameters contain questions. Test scenarios for updating various attributes of a question.
  • When params do not contain questions: Verify that the method does not update any question attributes when parameters do not contain questions.

questionnaire_factory

This method creates a questionnaire instance based on its type. To test this method, we provide various valid and invalid types. We identify the following test cases:

  • When a valid type is provided: Verify that the method creates a questionnaire instance for a valid type. Test scenarios for each valid questionnaire type.
  • When an undefined type is provided: Verify that the method sets a flash error message when an undefined questionnaire type is provided.

We have structured the test plan to cover each method comprehensively and ensure that they function correctly under various scenarios.

Objective 2: Develop code testing scenarios for review_bids_helper

After reviewing the ReviewBidsHelper module, we identified two methods that require testing:

get_intelligent_topic_row_review_bids

  • Objective: Verify that the method get_intelligent_topic_row_review_bids correctly renders the topic row for the topics table in review_bids/show.html.erb.
  • Test Scenario: When called with a topic, selected topics, and the number of participants, the method should generate HTML code for the topic row with appropriate background color based on its status.
  • Preconditions: Ensure that the topic, selected topics, and the number of participants are available for rendering. Set up a scenario with a topic and relevant data for selected topics and the number of participants.
  • Test Steps: Provide a topic, selected topics, and the number of participants to the method. Call the get_intelligent_topic_row_review_bids method with the provided parameters.
  • Expected Result: The method should return HTML code for the topic row with appropriate background color based on its status.
  • Pass Criteria: The method returns the correct HTML code for the topic row. The background color of the row is determined correctly based on the topic's status and selection.
  • Fail Criteria: The method returns incorrect HTML code for the topic row. The background color of the row is not determined correctly based on the topic's status and selection.

get_topic_bg_color_review_bids

  • Objective: Verify that the method get_topic_bg_color_review_bids correctly calculates the background color for a topic in the review_bids/show.html.erb template.
  • Test Scenario: When called with a topic and the number of participants, the method should calculate the background color based on the number of bids and the number of participants.
  • Preconditions: Ensure that the topic and the number of participants are available for calculation. Set up a scenario with a topic and the number of participants.
  • Test Steps: Provide a topic and the number of participants to the method. Call the get_topic_bg_color_review_bids method with the provided parameters.
  • Expected Result: The method should return a string representing the RGB color code for the topic's background color.
  • Pass Criteria: The method returns the correct RGB color code for the topic's background color. The background color is calculated accurately based on the number of bids and the number of participants.
  • Fail Criteria: The method returns an incorrect RGB color code for the topic's background color. The background color is not calculated accurately based on the number of bids and the number of participants.

Conclusion

The design document outlines a comprehensive plan for the upcoming project focused on enhancing the testing and code coverage for the `questionnaire_helper` and `review_bids_helper` files in Expertiza. With a clear problem statement and objectives defined, the project aims to address the current code coverage gaps by developing thorough test plans and scenarios for both helpers. The document provides an overview of the classes and methods involved. Key objectives include developing code testing scenarios, improving code coverage, and ensuring the reliability and effectiveness of the helpers. Moving forward, the project will involve the implementation of the outlined test plans, execution of test scenarios, and iterative refinement of the codebase to achieve the desired objectives.

Links

Link to Expertiza repository: here

References

1. Expertiza on GitHub (https://github.com/expertiza/expertiza)
2. The live Expertiza website (http://expertiza.ncsu.edu/)
3. Pluggable reputation systems for peer review: A web-service approach (https://doi.org/10.1109/FIE.2015.7344292)