CSC/ECE 517 Spring 2018- Project E1804: OSS project Yellow: Topic management: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 575: Line 575:
==== '''Further Testing Required''' ====
==== '''Further Testing Required''' ====
::More tests need to be added to test whether an instructor can edit a comment or not.
::More tests need to be added to test whether an instructor can edit a comment or not.
== Testing Specifics ==
=== Issue 971 ===
::The tests were written in these files:
::*app/spec/controllers/assignments_controller_spec.rb
::*app/spec/controllers/sign_up_sheet_controller_spec.rb
::As mentioned previously they are still a work in progress. You can run the tests that were made by running these rspec files.
=== Issue 926 ===
::
=== Issue 718 ===
::

Revision as of 00:08, 29 March 2018

This page provides a description of our Expertiza project.


>>>>>>>>>>>>> RUN "./setup.sh" BEFORE RUNNING APP; CONTENTS OF "bower.json" HAVE CHANGED <<<<<<<<<<<<<<

Introduction < https://github.com/dburcal/expertiza > PR: < https://github.com/expertiza/expertiza/pull/1144 >

Expertiza Background

Expertiza is a web-based framework designed in Ruby on Rails to serve as a medium for students and professors to interact, provide feedback, and manage their assignments. It facilitates all of the electronic turn-ins and provides a good place to review your peers' work.

Problem Statement

To enhance topic management for instructors and students.

  • Issue 971: Change create topic UI to AJAX
  • Issue 926: Sort topics by topic number in assignment#edit
  • Issue 718: Allow instructors to give feedback when accepting or rejecting suggestions

Our Goals

We planned to improve the functionality such that when instructors have to manage the topics for an assignment, they can do so much quicker and more reliably.

Files Edited

  • app/spec/controllers/assignments_controller_spec.rb
  • app/spec/controllers/sign_up_sheet_controller_spec.rb
  • app/spec/features/topic_suggestion_spec.rb
  • app/assets/javascripts/application.js
  • app/assets/javascripts/signup.js
  • app/assets/stylesheets/application.scss
  • app/assets/stylesheets/signup.scss.erb
  • app/controllers/sign_up_sheet_controller.rb
  • app/controllers/suggestion_controller.rb
  • app/models/sign_up_topic.rb
  • app/views/sign_up_sheet/_add_signup_topics.html.erb
  • app/views/sign_up_sheet/_add_topics.html.erb
  • app/views/sign_up_sheet/_topic.html.erb
  • app/views/signup/signup_topics.html.erb
  • app/views/suggestion/show.html.erb
  • app/views/suggestion/update_comment.html.erb
  • app/views/suggestion/edit_comment.html.erb
  • app/views/suggestion/_form_comment.html.erb
  • config/routes.rb
  • bower.json

Issue 971

Implementation

The implementation of this functionality was started using < http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1781_Topic_Management > as a baseline. This issue calls for the replacement of the html table with a javascript table using jsGrid. The use of jsGrid in conjunction with AJAX calls allow for the user to complete actions such as edit and add for topics from a single page.

Further Implementation Required

There is logic implemented in the views that needs to be moved back to the controller. This logic deals with conditional display of fields based on the current role of the user or status of the assignment. Additional tests need to be created to test this controller logic.

Testing

Testing is still in progress. After a merge, aspects of the code need to be changed.

For testing the newly created JSGrid, it is important to ensure it maintains correct functionality from before. To that end, we created quite a few tests that test manage topic functionality.
  • Testing that if an assignment due date has passed:
    • Topics are no longer editable and you can no longer add/delete topics
app/spec/controllers/assignments_controller_spec.rb
    context 'assignment due dates have not passed' do
      before(:each) do
        due_date.due_at = DateTime.now.in_time_zone + 1.day
        allow(assignment.due_dates).to receive(:find_by).with(deadline_type_id: 6).and_return(due_date)
      end
      it 'allows a topic to be edited' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).to respond_to(:edit)
      end

      it 'allows a topic to be deleted' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).to respond_to(:destroy)
      end

      it 'allows a new topic to be added' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).to respond_to(:new)
      end
    end

  • Testing that if an assignment due date has not passed:
    • Topics are editable and you can add/delete topics
app/spec/controllers/assignments_controller_spec.rb

    context 'all assignment due dates have passed' do
      before(:each) do
        due_date.due_at = DateTime.now.in_time_zone - 1.day
        allow(assignment.due_dates).to receive(:find_by).with(deadline_type_id: 6).and_return(due_date)
      end
      it 'does not allow a topic to be edited' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).not_to respond_to(:edit)
      end

      it 'does not allow a topic to be deleted' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).not_to respond_to(:destroy)
      end

      it 'does not allow a new topic to be added' do
        params = {id: 1, anchor: 'tabs-2'}
        get :edit, params, xhr: true
        expect(response).not_to respond_to(:new)
      end
    end

  • Testing that default topic available slots is 1
app/spec/controllers/sign_up_sheet_controller_spec.rb
  define '#new' do
    it 'has default available slots of 1' do
      params = {id: 1}
      get :new, params
      expect(response).to have_field('max_choosers', with: '1')
    end
  end

Further Testing Required

Unfortunately we were unable to exhaustively test the topic table, but here are the things we plan to test about managing topics over the next week:
  • If assignment deadline has passed, you can not add students to a topic
  • Ensure students cant see which students are on other topics
  • Check that Advertisement Horn shows in the table if a team has an ad open
  • If you login as student, you can't add/delete topics in the table

Issue 926

Implementation

We let JSGrid handle the sorting of topics by the headers in the table. We altered the AJAX controller to enable this sorting.

Further Implementation Required

While the table is able to be sorted by the header row, whenever you make a new topic the initial list of topics is not resorted right away. This leads to say E1502, a new topic just made, to be at the bottom of the list when it would normally precede say E1700, if it were in the same topic list.

Testing

There is no testing required in this aspect, since sorting is a feature of the AJAX table itself, and therefore it wouldn't make sense to test the implementation.

Issue 718

Implementation

We implemented the functionality for approving and rejecting any topic suggestions made by the students. Furthermore we have included comments which the instructor can give for a particular topic suggestion. Some tests have been added to verify the above functionality. We are currently working on editing comments and have listed the changes made in subsequent sections.
Files which have been changed to reflect the changes:
1. app/view/suggestion/show.html.erb
  • To see all the comments and to edit individual comments:
<table class="general" cellpadding=5 border="1">
    <colgroup>
      <col width=15% />
      <col width=15% />
      <col width=25% />
    </colgroup>
    <tr>
      <th>Commenter</th>
      <th>Vote</th>
      <th>Comment</th>
    </tr>

    <% for suggestioncomment in @suggestion.suggestion_comments %>
        <tr>

          <td class="listingRow" align="center"><%=suggestioncomment.commenter %></td>
          <td class="listingRow" align="center">
            <%if suggestioncomment.vote == 'Y' %>
                Yes
            <%elsif suggestioncomment.vote == 'N'%>
                No
            <%elsif suggestioncomment.vote == 'R'%>
                Revise
                <!-- Two more crieteria for displaying comments. During Approval and Denial. Issue #1781-718 -->
            <%elsif suggestioncomment.vote == 'A'%>
                Approved
            <%elsif suggestioncomment.vote == 'D'%>
                Denied
            <%else%>
                --
            <%end%>
          </td>
          <td class="listingRow" align="center"><%= suggestioncomment.comments%></td>

          <td><%= link_to "Edit Comment",{:controller=>"suggestion",:action=>"update_comment",:suggestion=>suggestioncomment}%></td>
        </tr>

        <%end%>
  </table>
  • To add a comment:
<% if @suggestion.status != 'Approved' && @suggestion.status != 'Rejected' %>
  <b>Add new comment and vote</b> <br>
  <%= form_tag :action => 'submit', :id => @suggestion do %>
    <%= text_area "suggestion_comment", "comments", :rows => 5, :cols => 50 %>
    <p>
      <%= "Vote"%>
      <%= select("suggestion_comment","vote",{"Yes" =>"Y","No"=>"N","Revise"=>"R"}) %>
    </p>

    <%= submit_tag "Submit vote", :name => 'add_comment' %>
        <% if @suggestion.status != 'Approved' && @suggestion.status != 'Rejected' && session[:user] != nil && (session[:user].role_id == 2 || session[:user].role_id == 3 || session[:user].role_id == 4) %>
            <%= submit_tag "Approve suggestion", :name => 'approve_suggestion' %>
            <%= submit_tag "Reject suggestion", :name => 'reject_suggestion' %>
        <% end %>
  <% end %>

<% end %>
2. app/views/suggestion/update_comment.html.erb
  • Link to form for editing
< Editing suggestion comments>
<tr><%= render :partial =>"form_comment", suggestion_comment: @suggestioncomment %></tr>
<tr><%#= link_to 'Back', :action => 'show', :id => suggestion %></tr>
3. app/views/suggestion/_form_comment.html.erb
  • Form for editing:
<%= form_for :suggestioncomment  do |form|%>
    <div class="field">
      <%= form.label :comments %>
      <%= form.text_field :comments%>
    </div>

    <div class = "field">
      <%= form.label :vote%>
      <%= form.text_field :vote%>
    </div>
    <div class="actions">
      Click to Update
      <%= form.submit %>
    </div>
<% end %>
4. app/controllers/suggestion_controller.rb
  • For adding a comment:
def add_comment
    @suggestioncomment = SuggestionComment.new(vote: params[:suggestion_comment][:vote], comments: params[:suggestion_comment][:comments])
    @suggestioncomment.suggestion_id = params[:id]
    @suggestioncomment.commenter = session[:user].name
    if @suggestioncomment.save
      flash[:notice] = "Your comment has been successfully added."
    else
      flash[:error] = "There was an error in adding your comment."
    end
    if current_role_name.eql? 'Student'
      redirect_to action: "student_view", id: params[:id]
    else
      redirect_to action: "show", id: params[:id]
    end
  end
  • For approving and rejecting suggestions:
def approve_suggestion
    # 1781 - 718 issue
    # The Instructor should be able to give feed backs during the times of approval as well.
    # Thus we are getting the comments through the request when approval is made and saving those in
    # Database with Vote type as A - meaning approval
    if params[:suggestion_comment][:comments] && params[:suggestion_comment][:comments] != ""
      @suggestioncomment = SuggestionComment.new(vote: 'A', comments: params[:suggestion_comment][:comments])
      @suggestioncomment.suggestion_id = params[:id]
      @suggestioncomment.commenter = session[:user].name
      @suggestioncomment.save
    end
    @suggestion = Suggestion.find(params[:id])

    if @suggestion.update_attribute('status', 'Accepted')
      flash[:notice] = 'The suggestion has been successfully accepted.'
    else
      flash[:error] = 'An error occurred when accepting the suggestion.'
    end

    redirect_to action: 'show', id: @suggestion
  end

  def reject_suggestion
    # 1781 - 718 issue
    # The Instructor should be able to give feed backs during the times of rejection as well.
    # Thus we are getting the comments through the request when denial is made and saving those in
    # Database with Vote type as D - meaning reject
    if params[:suggestion_comment][:comments] && params[:suggestion_comment][:comments] != ""
      @suggestioncomment = SuggestionComment.new(vote: 'D', comments: params[:suggestion_comment][:comments])
      @suggestioncomment.suggestion_id = params[:id]
      @suggestioncomment.commenter = session[:user].name
      @suggestioncomment.save
      end
    @suggestion = Suggestion.find(params[:id])

    if @suggestion.update_attribute('status', 'Rejected')
      flash[:notice] = 'The suggestion has been successfully rejected.'
    else
      flash[:error] = 'An error occurred when rejecting the suggestion.'
    end
    redirect_to action: 'show', id: @suggestion
  end
  • For editing comments:
def update_comment
    @suggestioncomment = SuggestionComment.find(params[:suggestion])
  end

Further Implementation Required

The comments have to be editable(in process). We have almost implemented this. The part remaining is that the submit form button isn't working as expected; an error is being thrown after clicking the button.

Testing

Tests have been added to the spec for testing the above functionality.The following changes are made to the related spec files.
spec/features/topic_suggestion_spec.rb
#part 2###########################
      #######part 2#####################
      #############part 2###############issue 718
      ###################part 2#########
      #########################part 2###
      describe "topic_suggestion" do
        it "Instructor set an assignment which allow student suggest topic and register student2066" do
          user = User.find_by(name: 'student2066')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          expect(page).to have_content "Assignment_suggest_topic"

          # student2066 suggest topic
          click_link('Assignment_suggest_topic',match: :first)
          expect(page).to have_content "Suggest a topic"
          click_link('Suggest a topic',match: :first)
          fill_in 'suggestion_title', with: 'suggested_topic'
          fill_in 'suggestion_description', with: 'suggested_description'
          click_button 'Submit',match: :first
          expect(page).to have_content "Thank you for your suggestion"

          user = User.find_by(name: 'instructor6')
          stub_current_user(user, user.role.name, user.role)

          # instructor approve the suggestion topic
          # DUE date need to be added here
          visit '/suggestion/list?id=1&type=Assignment'
          expect(page).to have_content "Assignment_suggest_topic"
          click_link('View',match: :first)
          expect(page).to have_content "suggested_description"
          click_button 'Approve suggestion',match: :first
          expect(page).to have_content "The suggestion was successfully approved."
        end

        it " student2066 hold suggest topic and suggest a new one and student2064 enroll on waitlist of suggested topic", js: true do
          # login_as "student2064"
          user = User.find_by(name: 'student2064')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          expect(page).to have_content "Assignment_suggest_topic"

          # student2064 suggest topic
          click_link('Assignment_suggest_topic',match: :first)
          expect(page).to have_content "Suggest a topic"
          click_link('Suggest a topic',match: :first)
          fill_in 'suggestion_title', with: 'suggested_topic'
          fill_in 'suggestion_description', with: 'suggested_description'
          click_button 'Submit',match: :first
          expect(page).to have_content "Thank you for your suggestion"

          user = User.find_by(name: 'instructor6')
          stub_current_user(user, user.role.name, user.role)

          # instructor approve the suggestion topic
          visit '/suggestion/list?id=1&type=Assignment'
          expect(page).to have_content "Suggested topics for Assignment_suggest_topic"
          expect(page).to have_content "suggested_topic"
          click_link('View',match: :first)
          expect(page).to have_content "suggested_description"
          click_button 'Approve suggestion',match: :first
          expect(page).to have_content "The suggestion was successfully approved."



          # case 2 student already have topic switch to new topic
          # need two students one to be on the waitlist of previous suggested topic,
          # the other one (student2064) is holding it and suggest another topic and wish to switch to the new one
          user = User.find_by(name: 'student2066')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          click_link('Assignment_suggest_topic',match: :first)
          click_link('Signup sheet',match: :first)
          first("img[title='Signup']").click

          # log in student2064
          user = User.find_by(name: 'student2064')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          click_link('Assignment_suggest_topic',match: :first)
          expect(page).to have_content "Suggest a topic"
          click_link('Suggest a topic',match: :first)
          fill_in 'suggestion_title', with: 'suggested_topic2_will_switch'
          fill_in 'suggestion_description', with: 'suggested_description_2'
          click_button 'Submit',match: :first
          expect(page).to have_content "Thank you for your suggestion"

          # login_as instructor6 to approve the 2nd suggested topic
          user = User.find_by(name: 'instructor6')
          stub_current_user(user, user.role.name, user.role)

          # instructor approve the suggestion topic
          visit '/tree_display/list'
          visit '/suggestion/list?id=1&type=Assignment'
          expect(page).to have_content "Suggested topics for Assignment_suggest_topic"
          expect(page).to have_content "suggested_topic2_will_switch"
          # find link for new suggested view
          visit '/suggestion/2'
          # click_link('View')
          expect(page).to have_content "suggested_description"
          click_button 'Approve suggestion',match: :first
          expect(page).to have_content "The suggestion was successfully approved."

          # login as student 2064 to switch to new approved topic
          user = User.find_by(name: 'student2064')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          click_link('Assignment_suggest_topic',match: :first)
          click_link('Signup sheet',match: :first)
          expect(page).to have_content "Your approved suggested topic"
          expect(page).to have_content "suggested_topic"
          expect(page).to have_content "suggested_topic2_will_switch"
          first("img[title='Switch Topic']").click

          # login as student 2066 to see if it's holding the topic rather than on the wait list
          user = User.find_by(name: 'student2066')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          expect(page).to have_content "suggested_topic"

          # login as studnet 2064 to see if it's already shifted to the new suggested topic
          user = User.find_by(name: 'student2064')
          stub_current_user(user, user.role.name, user.role)
          visit '/student_task/list'
          expect(page).to have_content "suggested_topic2_will_switch"
        end



    ########################################
    # Case 3:
    # One team is holding a topic. They sent a suggestion for new topic, and keep themselves in old topic
    ########################################
    it "student2066 hold suggest topic and suggest a new one, but wish to stay in the old topic", js: true do
      # login_as "student2066"
      user = User.find_by(name: 'student2066')
      stub_current_user(user, user.role.name, user.role)
      visit '/student_task/list'
      expect(page).to have_content "Assignment_suggest_topic"

      # student2066 suggest topic
      click_link('Assignment_suggest_topic',match: :first)
      expect(page).to have_content "Suggest a topic"
      click_link('Suggest a topic',match: :first)
      fill_in 'suggestion_title', with: 'suggested_topic'
      fill_in 'suggestion_description', with: 'suggested_description'
      click_button 'Submit',match: :first
      expect(page).to have_content "Thank you for your suggestion"

      # login_as "instructor6"
      user = User.find_by(name: 'instructor6')
      stub_current_user(user, user.role.name, user.role)

      # instructor approve the suggestion topic
      # DUE date need to be added here
      visit '/suggestion/list?id=1&type=Assignment'
      click_link('View',match: :first)
      expect(page).to have_content "suggested_description"
      click_button 'Approve suggestion',match: :first
      expect(page).to have_content "The suggestion was successfully approved."

      ######################################
      # One team is holding a topic. They sent a suggestion for new topic
      ######################################
      # login_as "student2066"
      user = User.find_by(name: 'student2066')
      stub_current_user(user, user.role.name, user.role)
      visit '/student_task/list'
      expect(page).to have_content "Assignment_suggest_topic"

      # student2066 suggest topic
      click_link('Assignment_suggest_topic',match: :first)
      expect(page).to have_content "Suggest a topic"
      click_link('Suggest a topic',match: :first)
      fill_in 'suggestion_title', with: 'suggested_topic2_without_switch'
      fill_in 'suggestion_description', with: 'suggested_description2_without_switch'
      find('#suggestion_signup_preference').find(:xpath, 'option[2]').select_option
      click_button 'Submit',match: :first
      expect(page).to have_content "Thank you for your suggestion"

      # login_as "instructor6"
      user = User.find_by(name: 'instructor6')
      stub_current_user(user, user.role.name, user.role)

      # instructor approve the suggestion topic
      visit '/tree_display/list'
      visit '/suggestion/list?id=1&type=Assignment'
      expect(page).to have_content "Suggested topics for Assignment_suggest_topic"
      expect(page).to have_content "suggested_topic2_without_switch"
      find(:xpath, "//tr[contains(.,'suggested_topic2_without_switch')]/td/a", text: 'View').click
      # click_link('View')

      expect(page).to have_content "suggested_description2_without_switch"
      click_button 'Approve suggestion',match: :first
      expect(page).to have_content "The suggestion was successfully approved."

      # login_as "student2066"
      user = User.find_by(name: 'student2066')
      stub_current_user(user, user.role.name, user.role)
      visit '/student_task/list'
      expect(page).to have_content "Assignment_suggest_topic"
      click_link('Assignment_suggest_topic',match: :first)
      expect(page).to have_content "Signup sheet"
      click_link('Signup sheet',match: :first)
      expect(page).to have_content "suggested_topic2_without_switch"
      # click_link('publish_approved_suggested_topic')
      visit '/sign_up_sheet/publish_approved_suggested_topic/2?assignment_id=1'
      # find(:xpath, "//tr[contains(.,'suggested_topic2_without_switch')]/td/a", :figure=>"Publish Topic").click
      visit '/student_task/list'
      expect(page).to have_content "suggested_topic"

      # login_as "student2064"
      user = User.find_by(name: 'student2064')
      stub_current_user(user, user.role.name, user.role)
      visit '/student_task/list'
      expect(page).to have_content "Assignment_suggest_topic"
      click_link('Assignment_suggest_topic',match: :first)
      expect(page).to have_content "Signup sheet"
      click_link('Signup sheet',match: :first)
      expect(page).to have_content " suggested_topic2_without_switch"
      find(:xpath, "(//img[@title='Signup'])[2]").click
      visit '/student_task/list'
      expect(page).to have_content " suggested_topic2_without_switch"
    end

    it "professor could approve anonymous suggestion topic" do
      # login_as "student2064"
      user = User.find_by(name: 'student2064')
      stub_current_user(user, user.role.name, user.role)
      visit '/student_task/list'
      expect(page).to have_content "Assignment_suggest_topic"

      # student2064 suggest topic
      click_link('Assignment_suggest_topic',match: :first)
      expect(page).to have_content "Suggest a topic"
      click_link('Suggest a topic',match: :first)
      fill_in 'suggestion_title', with: 'suggested_topic'
      fill_in 'suggestion_description', with: 'suggested_description'
      find(:xpath, "//input[@name='suggestion_anonymous']").click
      click_button 'Submit',match: :first
      expect(page).to have_content "You have submitted an anonymous suggestion."

      user = User.find_by(name: 'instructor6')
      stub_current_user(user, user.role.name, user.role)

      # instructor approve the suggestion topic
      visit '/suggestion/list?id=1&type=Assignment'
      expect(page).to have_content "Suggested topics for Assignment_suggest_topic"
      expect(page).to have_content "suggested_topic"
      click_link('View',match: :first)
      expect(page).to have_content "suggested_description"
      click_button 'Approve suggestion',match: :first
      expect(page).to have_content "The suggestion was successfully approved."
    end
  end

Further Testing Required

More tests need to be added to test whether an instructor can edit a comment or not.

Testing Specifics

Issue 971

The tests were written in these files:
  • app/spec/controllers/assignments_controller_spec.rb
  • app/spec/controllers/sign_up_sheet_controller_spec.rb
As mentioned previously they are still a work in progress. You can run the tests that were made by running these rspec files.

Issue 926

Issue 718