CSC/ECE 517 Spring 2023 - E2320. Reimplement the Question Hierarchy: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 51: Line 51:
**Ex: Question_Controller - Since all of the sub-categories inherit from the Question class we plan to make a question controller to hold all of the common functionality. One example of this can be seen with the method call 'edit' which exists in many of the subclasses like text_response.rb, text_area.rb, scale.rb, and criterion.rb. The partials will be moved into the question controller.
**Ex: Question_Controller - Since all of the sub-categories inherit from the Question class we plan to make a question controller to hold all of the common functionality. One example of this can be seen with the method call 'edit' which exists in many of the subclasses like text_response.rb, text_area.rb, scale.rb, and criterion.rb. The partials will be moved into the question controller.


===Tests===
== Tests ==
In program 3 tests were created for all of the question types (Ex: criterion_spec.rb, text_area.rb and upload_file.rb to name a few).The only new tests we plan to write for program 4 will be for the new question controller we plan to create. If any additional tests will need to be added this section will be updated to reflect that
 
'''RSpec'''
 
We reimplemented the test cases to match the changes we've made to the question-related models. Front-end testing wasn't necessary because our project doesn't involve changing any controller.
 
The most notable models that were tested are:
checkbox.rb  
criterion.rb
dropdown.rb
multiple_choice_checkbox.rb
multiple_choice_radio.rb
scale.rb
text_area.rb
text_field.rb
text_response.rb
upload_file.rb
 
One of the primary goals we had were to make sure that the existing tests still passed. Several tests were removed for the edit methods in a few of the models (such as checkbox_spec.rb and dropdown_spec.rb) because those methods were replaced with partials. Partials have not been fully implemented which is why we did not include tests for them. However, this is something that should be revisited in the future.
 
Given below is an example of the tests we've written:
describe Dropdown do
  let!(:dropdown) { Dropdown.create(id: 4, type: 'Dropdown', seq: 4.0, txt: 'Test text', weight: 13) }
  let!(:answer) { Answer.create(id: 1, question_id: 4, questionnaire_type_id: 1, answer: 1, comments: "Test comment") }
  describe '#view_question_text' do
    it 'returns the html' do
      html = dropdown.view_question_text
      expect(html).to eq('<TR><TD align="left"> Test text </TD><TD align="left">Dropdown</TD><td align="center">13</TD><TD align="center">&mdash;</TD></TR>')
    end
  end
  describe '#view_completed_question' do
    it 'returns the html' do
      html = dropdown.view_completed_question(1, answer)
      expect(html).to eq('<nowiki><b></nowiki>1. Test text<nowiki></b><BR></nowiki>&nbsp&nbsp&nbsp&nbspTest comment')
    end
  end
  describe '#complete_for_alternatives' do
    it 'returns the html' do
      alternatives = ['Alternative 1', 'Alternative 2', 'Alternative 3']
      html = dropdown.complete_for_alternatives(alternatives, answer)
      expect(html).to eq('<option value="Alternative 1">Alternative 1</option><option value="Alternative 2">Alternative 2</option><option value="Alternative 3">Alternative 3</option>')
    end
  end
  describe '#complete' do
    it 'returns the html' do
      alternatives = ['Alternative 1|Alternative 2|Alternative 3']
      allow(dropdown).to receive(:alternatives).and_return(alternatives)
      allow(dropdown).to receive(:complete_for_alternatives).and_return('')
      html = dropdown.complete(1, answer)
      <nowiki>expect(html).to eq('<p style="width: 80%;"><label for="responses_1"">Test text&nbsp;&nbsp;</label>'
      + '<input id="responses_1_score" name="responses[1][score]" type="hidden" value="" style="min-width: 100px;">'
      + '<select id="responses_1_comments" label=Test text name="responses[1][comment]"></select></p>')</nowiki>
    end
  end
end
 
Given below is the full list of tests:
 
[[File:E2320-RSpec.png]]


==Conclusions / Future Work==
==Conclusions / Future Work==

Revision as of 00:34, 8 April 2023

Design Doc

Problem Statement

The current implementation of the question hierarchy is not very clean and contains confusing variable and method names. Also, many methods return long HTML strings which are difficult to read. The goal of this project is to reimplement this part of the application to make it more readable, understandable and maintainable.

Explanation of Feature - Question Hierarchy

The Question class and its sub-classes are used to implement all rubric items, quiz questions, and survey questions in Expertiza. For example, a professor could use this feature to make up a review quiz for their class. There are 3 main types of questions in Experitza: scored, unscored, and upload file.

Here is the hierarchy:

1. Choice question

  • Scored question
    • Scale
    • Criterion
  • Unscored question
    • Dropdown
    • Multiple Choice
    • Check Box

2. Text Response

  • Text Area
  • Text Field

3. Upload File

Choice questions are types of questions that give the quiz taker a list of answers to choose from. It is broken into two subcategories scored and unscored. Scored question will give a number value depending upon if a user clicks on a particular answer. The unscored questions don't have a score associated with them and come in a few different styles. The answers could be presented in a dropdown menu which only shows the answer choices after the user clicks on the dropdown arrow and clicks on an answer. Multiple choice questions present all the answers choices with a selectable bubble beside them and allow the user to click on the bubble to indicate their answer. Checkboxes are similar to multiple choice in that they present all of the answer choices at once however, the user must click on a certain number of boxes beside the answers they think are correct.


Text response questions are different in that they allow the user to actually type in their answer instead of just being provided answers. A text area question has a height and width associated with it that can be adjusted while a text field question is just 1 input line that does not change shape.


The last type of question is upload file which allows the user to upload a file to use as a quiz (as the name suggests). This option allows a person to upload a pre-made quiz document to be which will be converted into a quiz. So, a professor could type up their quiz questions and answers in a text file then choose upload and have Expertiza convert it into a quiz for them.

List of Work Done so Far

The following list describes tasks that were accomplished in Program 3:

  • Improved naming of variables and methods
  • Included comments for further clarification
  • Implemented partials to deal with the HTML strings
  • Added RSpec test cases

Plan of work

Based on the feedback provided to us by both our mentors and also peer reviews our team has decided upon a few key design goals to work on for the continuation of our work into Program 4. These goals are outlined below.

Design Goals

  • Update code comments - Some methods and classes currently do not have any code comments, while other comments are not in depth enough to give proper context for functionality. One of our design goals will be to write more in depth comments that better explain functionality for the code. The below files are the ones which we plan too add more comments to:
    • questionnaires_controller.rb
    • checkbox.rb
    • question.rb
    • text_area.rb
    • text_response.rb
  • DRY out code with partials - Implement additional partials for certain classes. In program 3 our team had started to create partials for the 3 major types of questions. As we continue with program 4 we are going to continue to add more partials by looking at the similarities between all three types and pull out the similarities into a new class
    • Ex: Question_Controller - Since all of the sub-categories inherit from the Question class we plan to make a question controller to hold all of the common functionality. One example of this can be seen with the method call 'edit' which exists in many of the subclasses like text_response.rb, text_area.rb, scale.rb, and criterion.rb. The partials will be moved into the question controller.

Tests

RSpec

We reimplemented the test cases to match the changes we've made to the question-related models. Front-end testing wasn't necessary because our project doesn't involve changing any controller.

The most notable models that were tested are:

checkbox.rb 
criterion.rb
dropdown.rb
multiple_choice_checkbox.rb
multiple_choice_radio.rb
scale.rb
text_area.rb
text_field.rb
text_response.rb
upload_file.rb

One of the primary goals we had were to make sure that the existing tests still passed. Several tests were removed for the edit methods in a few of the models (such as checkbox_spec.rb and dropdown_spec.rb) because those methods were replaced with partials. Partials have not been fully implemented which is why we did not include tests for them. However, this is something that should be revisited in the future.

Given below is an example of the tests we've written:

describe Dropdown do
 let!(:dropdown) { Dropdown.create(id: 4, type: 'Dropdown', seq: 4.0, txt: 'Test text', weight: 13) }
 let!(:answer) { Answer.create(id: 1, question_id: 4, questionnaire_type_id: 1, answer: 1, comments: "Test comment") }
 describe '#view_question_text' do
   it 'returns the html' do
     html = dropdown.view_question_text

expect(html).to eq(' Test text Dropdown13—')

   end
 end
 describe '#view_completed_question' do
   it 'returns the html' do
     html = dropdown.view_completed_question(1, answer)
     expect(html).to eq('<b>1. Test text</b><BR>&nbsp&nbsp&nbsp&nbspTest comment')
   end
 end
 describe '#complete_for_alternatives' do
   it 'returns the html' do
     alternatives = ['Alternative 1', 'Alternative 2', 'Alternative 3']
     html = dropdown.complete_for_alternatives(alternatives, answer)
     expect(html).to eq('<option value="Alternative 1">Alternative 1</option><option value="Alternative 2">Alternative 2</option><option value="Alternative 3">Alternative 3</option>')
   end
 end
 describe '#complete' do
   it 'returns the html' do
     alternatives = ['Alternative 1|Alternative 2|Alternative 3']
     allow(dropdown).to receive(:alternatives).and_return(alternatives)
     allow(dropdown).to receive(:complete_for_alternatives).and_return()
     html = dropdown.complete(1, answer)
     expect(html).to eq('<p style="width: 80%;"><label for="responses_1"">Test text  </label>'
      + '<input id="responses_1_score" name="responses[1][score]" type="hidden" value="" style="min-width: 100px;">'
      + '<select id="responses_1_comments" label=Test text name="responses[1][comment]"></select></p>')
   end
 end
end

Given below is the full list of tests:

Conclusions / Future Work

Specific Tasks Completed

[Will be updated near final submission deadline]

Team

Mentor
  • Prof. Edward F. Gehringer
  • Priyam Garg
Members
  • Colleen Britt
  • Kimberly Jones
  • Priyanka Arghode

References

  1. Expertiza
  2. Organizing Partials
  3. Render Views and Partials Outside Controllers
  4. Github Repo
  5. Link to initial pull request
  6. GitHub Project Board