CSC/ECE 517 Spring 2017/Test heat map for viewing scores

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Expertiza

Expertiza is an open source project maintained by the students and faculty of NCSU. It is a web application based on Ruby on Rails that facilitates the submission and peer-review of course work.

Capybara

Capybara is a program designed to help with testing web applications. It is able to simulate regular user interactions like clicking buttons and filling in forms. It supports a number of testing drivers, including Rack::Test and Selenium.

Project Description

Expertiza's heat map display is an alternative way to view assignment review scores. Instead of the standard list of reviews that are expanded one at a time, the heat map displays all reviews together in a table with scores both color coded and displayed numerically. This allows the user to quickly view all scores received and see an easily understood representation of how high or low they are. Scores show as green when they are high, and shift through shades of yellow down to red as they approach the minimum possible.

Purpose

The purpose of this assignment was to write functional tests for the heat map display, which it previously lacked entirely. Functional tests are a kind of block-box testing and allow the user experience to be simulated and tested. This ensures that features work as expected and meet design goals. With active development, having these tests in place ensures that any features that break due to future changes won't go unnoticed.

Design Pattern

Since our assignment was simply to implement functional tests for a small part of the Expertiza project and we only changed a single method, there wasn't an opportunity to implement any particular design pattern.

Files Modified

We created a single file and didn't modify any existing ones.

  • heat_map_spec.rb

Test Plan

Running Tests Locally

To run these test locally, run the following commands on a linux system

git clone https://github.com/balesj/expertiza.git
sudo apt-get install npm
sudo npm install -g bower
bower install
cd into the repository folder
rspec spec/features/heat_map_spec.rb

This will run the tests we wrote and you will be able to see the results displayed in the command prompt.

Tests

For testing the heat map functionality, we used factories to create test users, groups, and assignments that reset prior to each test.

before(:each) do
    create(:assignment, name: "TestAssignment", directory_path: 'test_assignment')
    create_list(:participant, 3)
    create(:assignment_node)
    create(:deadline_type, name: "submission")
    create(:deadline_type, name: "review")
    create(:deadline_type, name: "metareview")
    create(:deadline_type, name: "drop_topic")
    create(:deadline_type, name: "signup")
    create(:deadline_type, name: "team_formation")
    create(:deadline_right)
    create(:deadline_right, name: 'Late')
    create(:deadline_right, name: 'OK')
    create(:assignment_due_date, deadline_type: DeadlineType.where(name: 'review').first, due_at: Time.now.in_time_zone + 1.day)
    create(:topic)
    create(:topic, topic_name: "TestReview")
    create(:team_user, user: User.where(role_id: 2).first)
    create(:team_user, user: User.where(role_id: 2).second)
    create(:assignment_team)
    create(:team_user, user: User.where(role_id: 2).third, team: AssignmentTeam.second)
    create(:signed_up_team)
    create(:signed_up_team, team_id: 2, topic: SignUpTopic.second)
    create(:assignment_questionnaire)
    create(:question)
  end

A test user was used to fill in and submit a review using capybara. This review then displays for the other test users. This is called to setup the review before the test is run for every case that requires a review to be present.

 def create_review
    # NOTE: this function does not work since it stubs: login_as('student2064')
    user = User.find_by_name('student2064')
    visit root_path
    fill_in 'login_name', with: 'student2064'
    fill_in 'login_password', with: 'password'
    click_button 'SIGN IN'

    click_link "TestAssignment"
    click_link "Others' work"

    choose "topic_id"
    click_button "Request a new submission to review"

    click_link "Begin"

    fill_in 'responses[0][comment]', with: 'HelloWorld'
    select 5, from: "responses[0][score]"
    click_button 'Submit Review'

    # click ok on the pop-up box that warns you that responses can not be edited
    page.driver.browser.switch_to.alert.accept

    visit root_path
    click_link "Logout"
    Capybara.default_max_wait_time = 10
    expect(page).to have_content('Password')
  end

To begin testing, the test user is logged in after the first user creates the review and logs out.

First, a test to verify that when no reviews are present for a user, the page does not display scores.

 it 'should show an empty table with no reviews' do
    # Log in as the student with an assignment and reviews
    login_as('student2064')

    click_link 'TestAssignment'
    click_link 'Alternate View'

    expect(page).to_not have_content('Review 1')
  end

Second, the ability to view existing review scores in a heat map was tested.

  it 'should be able to view a heat map of review scores' do
    create_review

    # Log in as the student with an assignment and reviews
    login_as('student2065')

    # Select the assignment and follow the link to the heat map
    click_link 'TestAssignment'
    click_link 'Alternate View'

    expect(page).to have_content('Summary Report for assignment')
  end

This test checks that the user can click through to a specific reviewer to view the detailed feedback.

  it 'should be able to follow the link to a specific review' do
    create_review

    # Log in as the student with an assignment and reviews
    login_as('student2066')

    # Select the assignment and follow the link to the heat map
    click_link 'TestAssignment'
    click_link 'Alternate View'

    new_window = window_opened_by { click_link 'Review 1' }
    within_window new_window do
      expect(page).to have_content('Review for')
    end
  end

A list of the questions on the review assignment should be at the top of the screen, and should be expandable by the user.

  it 'should be able to toggle the question list' do
    create_review

    # Log in as the student with an assignment and reviews
    login_as('student2066')

    # Select the assignment and follow the link to the heat map
    click_link 'TestAssignment'
    click_link 'Alternate View'

    # TODO: don't realize how to add to question list, so no content to toggle
    #click_link 'toggle question list'
    #expect(page).to have_content('Question')

    expect(page).to have_content('toggle question list')
  end

Pull Request

Here is a link to the pull request we submitted.