<commit_before>import React from 'react';
import ReactDOM from 'react-dom';
import renderer from 'react-test-renderer';
import _ from 'lodash';
import serviceTypesIndex from '../testing/fixtures/serviceTypesIndex';
import eventNoteTypesIndex from '../testing/fixtures/eventNoteTypesIndex';
import FixtureStudents from './schoolOverviewStudents.fixture';
import SlicePanels from './SlicePanels';

function testProps(props = {}) {
  return {
    districtKey: 'somerville',
    filters: [],
    serviceTypesIndex,
    eventNoteTypesIndex,
    school: {
      school_type: 'ES'
    },
    students: [],
    allStudents: [],
    onFilterToggled: jest.fn(),
    ...props
  };
}

function testRender(props) {
  const el = document.createElement('div');
  ReactDOM.render(<SlicePanels {...props} />, el);
  return {el};
}

const helpers = {
  // Returns a matrix of the kinds of things that users can slice by in each
  // column (eg., disability, STAR reading quartile).
  columnTitlesMatrix(el) {
    const columnEls = $(el).find('.column').toArray();
    return columnEls.map(columnEl => {
      return $(columnEl).find('.fixed-table-title').toArray().map(titleEl => {
        return $(titleEl).text();
      });
    });
  },

  // Count how many attributes there are for each table in each column
  // (e.g., how many "Disability" options are there, and how many
  // "STAR Reading" options are there for slicing by.
  rowsPerColumnMatrix(el) {
    const columnEls = $(el).find('.column').toArray();
    return columnEls.map(columnEl => {
      return $(columnEl).find('table').toArray().map(tableEl => {
        return $(tableEl).find('tbody tr').length;
      });
    });
  },

  // Returns an array of text values the users can filter by for student
  // Disability
  disabilityFilters(el) {
    return $(el).find('table:first td.caption-cell').toArray().map(el => $(el).text());
  }
};

describe('high-level integration tests', () => {
  it(`renders everything on the happy path for elementary school with
      no student registration dates`, () => {
    const {el} = testRender(testProps());

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade', 'Risk level' ],
      [ 'STAR Reading', 'MCAS ELA Score', 'MCAS ELA SGP' ],
      [ 'STAR Math', 'MCAS Math Score', 'MCAS Math SGP' ],
      [ 'Discipline incidents', 'Absences', 'Tardies' ],
      [ 'Services', 'Summer', 'Notes', 'Program', 'Homeroom' ]
    ]);
  });

  it(`renders everything on the happy path for elementary school with
       student registration dates`, () => {
    
    const studentsWithRegistration = FixtureStudents.map((student) => {
      return _.merge(student, {registration_date: '2018-02-13T22:17:30.338Z'});
    });

    const {el} = testRender(testProps({
      students: studentsWithRegistration,
      allStudents: studentsWithRegistration
    }));

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade', 'Years enrolled', 'Risk level' ],
      [ 'STAR Reading', 'MCAS ELA Score', 'MCAS ELA SGP' ],
      [ 'STAR Math', 'MCAS Math Score', 'MCAS Math SGP' ],
      [ 'Discipline incidents', 'Absences', 'Tardies' ],
      [ 'Services', 'Summer', 'Notes', 'Program', 'Homeroom' ]
    ]);
  });

  it('renders everything on the happy path for high school', () => {
    const {el} = testRender(testProps({
      school: {
        school_type: 'HS',
        local_id: 'SHS'
      }
    }));

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade', 'House', 'Counselor', 'Risk level' ],<commit_msg>Update a few tests<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import renderer from 'react-test-renderer';
import _ from 'lodash';
import serviceTypesIndex from '../testing/fixtures/serviceTypesIndex';
import eventNoteTypesIndex from '../testing/fixtures/eventNoteTypesIndex';
import FixtureStudents from './schoolOverviewStudents.fixture';
import SlicePanels from './SlicePanels';

function testProps(props = {}) {
  return {
    districtKey: 'somerville',
    filters: [],
    serviceTypesIndex,
    eventNoteTypesIndex,
    school: {
      school_type: 'ES'
    },
    students: [],
    allStudents: [],
    onFilterToggled: jest.fn(),
    ...props
  };
}

function testRender(props) {
  const el = document.createElement('div');
  ReactDOM.render(<SlicePanels {...props} />, el);
  return {el};
}

const helpers = {
  // Returns a matrix of the kinds of things that users can slice by in each
  // column (eg., disability, STAR reading quartile).
  columnTitlesMatrix(el) {
    const columnEls = $(el).find('.column').toArray();
    return columnEls.map(columnEl => {
      return $(columnEl).find('.fixed-table-title').toArray().map(titleEl => {
        return $(titleEl).text();
      });
    });
  },

  // Count how many attributes there are for each table in each column
  // (e.g., how many "Disability" options are there, and how many
  // "STAR Reading" options are there for slicing by.
  rowsPerColumnMatrix(el) {
    const columnEls = $(el).find('.column').toArray();
    return columnEls.map(columnEl => {
      return $(columnEl).find('table').toArray().map(tableEl => {
        return $(tableEl).find('tbody tr').length;
      });
    });
  },

  // Returns an array of text values the users can filter by for student
  // Disability
  disabilityFilters(el) {
    return $(el).find('table:first td.caption-cell').toArray().map(el => $(el).text());
  }
};

describe('high-level integration tests', () => {
  it(`renders everything on the happy path for elementary school with
      no student registration dates`, () => {
    const {el} = testRender(testProps());

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade' ],
      [ 'STAR Reading', 'MCAS ELA Score', 'MCAS ELA SGP' ],
      [ 'STAR Math', 'MCAS Math Score', 'MCAS Math SGP' ],
      [ 'Discipline incidents', 'Absences', 'Tardies' ],
      [ 'Services', 'Summer', 'Notes', 'Program', 'Homeroom' ]
    ]);
  });

  it(`renders everything on the happy path for elementary school with
       student registration dates`, () => {

    const studentsWithRegistration = FixtureStudents.map((student) => {
      return _.merge(student, {registration_date: '2018-02-13T22:17:30.338Z'});
    });

    const {el} = testRender(testProps({
      students: studentsWithRegistration,
      allStudents: studentsWithRegistration
    }));

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade', 'Years enrolled' ],
      [ 'STAR Reading', 'MCAS ELA Score', 'MCAS ELA SGP' ],
      [ 'STAR Math', 'MCAS Math Score', 'MCAS Math SGP' ],
      [ 'Discipline incidents', 'Absences', 'Tardies' ],
      [ 'Services', 'Summer', 'Notes', 'Program', 'Homeroom' ]
    ]);
  });

  it('renders everything on the happy path for high school', () => {
    const {el} = testRender(testProps({
      school: {
        school_type: 'HS',
        local_id: 'SHS'
      }
    }));

    expect($(el).find('.SlicePanels').length).toEqual(1);
    expect($(el).find('.column').length).toEqual(6);
    expect(helpers.columnTitlesMatrix(el)).toEqual([
      [ 'Disability', 'Low Income', 'LEP', 'Race', 'Hispanic/Latino', 'Gender' ],
      [ 'Grade', 'House', 'Counselor', 'Risk level' ],
{'fraction_non_alphanumeric': 0.17565749235474007, 'fraction_numerical': 0.005626911314984709, 'mean_word_length': 3.4923076923076923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432941', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2535, 'n_words': 613}