<commit_before>/* eslint-env mocha */
import Vue from 'vue-test'; // eslint-disable-line
import Vuex from 'vuex';
import assert from 'assert';
import sinon from 'sinon';
import ChannelListPage from '../../src/views/reports/channel-list-page';
import { ViewBy } from '../../src/constants/reportConstants';
import { mount } from '@vue/test-utils';

const initialState = () => ({
  classId: '',
  pageName: '',
  core: {
    channels: {
      list: [
        { id: 'recent_channel', title: 'Recent Channel' },
        { id: 'not_recent_channel', title: 'Not Recent Channel' },
        { id: 'null_channel', title: 'Null Channel' },
      ],
    },
  },
  pageState: {
    showRecentOnly: false,
    tableData: [
      {
        title: 'recent_channel',
        lastActive: new Date('2017-04-20T21:17:58.810Z'),
        id: 'test1',
      },
      {
        title: 'not_recent_channel',
        lastActive: new Date('2017-03-20T21:17:58.810Z'),
        id: 'test2',
      },
      {
        title: 'null_channel',
        lastActive: null,
        id: 'test3',
      },
    ],
    viewBy: ViewBy.CHANNEL,
    sortColumn: '',
    sortOrder: '',
  },
});

function makeWrapper(options = {}, state) {
  const store = new Vuex.Store({
    state: state || initialState(),
  });
  return mount(ChannelListPage, {
    ...options,
    stubs: ['report-subheading', 'name-cell'],
    store,
  });
}

function getElements(wrapper) {
  return {
    channelRows: () => wrapper.findAll('tbody > tr'),
    headerText: () => wrapper.findAll('h1').at(0),
  };
}

describe('channel list page component', () => {
  let state;
  let clock;

  beforeEach(() => {
    state = initialState();
    // sets clock to 4/19/2017
    clock = sinon.useFakeTimers(Number(new Date(2017, 3, 19)));
  });

  afterEach(() => {
    clock.restore();
  });

  describe('in "show everything" mode', () => {
    it('shows the correct header', () => {
      const wrapper = makeWrapper({}, state);
      const { headerText } = getElements(wrapper);
      assert.equal(headerText().text(), 'Content');
    });

    it('shows all channels, regardless of activity', () => {
      const wrapper = makeWrapper({}, state);
      const { channelRows } = getElements(wrapper);
      // only checks the number of rows, not whether they are correct
      assert.equal(channelRows().length, 3);
    });
  });

  describe('in "show recent only" mode', () => {
    beforeEach(() => {
      state.pageState.showRecentOnly = true;
    });

    it('shows the "recent activity" header', () => {
      const wrapper = makeWrapper({}, state);
      const { headerText } = getElements(wrapper);
      assert.equal(headerText().text(), 'Recent activity');
    });

    it('hides channels that have null or not-recent activity', () => {
      const wrapper = makeWrapper({}, state);
      const { channelRows } = getElements(wrapper);
      assert.equal(channelRows().length, 1);
    });
  });
});
<commit_msg>Fix test<commit_after>/* eslint-env mocha */
import Vue from 'vue-test'; // eslint-disable-line
import Vuex from 'vuex';
import assert from 'assert';
import sinon from 'sinon';
import ChannelListPage from '../../src/views/reports/channel-list-page';
import { ViewBy } from '../../src/constants/reportConstants';
import { mount } from '@vue/test-utils';

const initialState = () => ({
  classId: '',
  pageName: '',
  core: {
    channels: {
      list: [
        { id: 'recent_channel', title: 'Recent Channel' },
        { id: 'not_recent_channel', title: 'Not Recent Channel' },
        { id: 'null_channel', title: 'Null Channel' },
      ],
    },
  },
  pageState: {
    showRecentOnly: false,
    tableData: [
      {
        title: 'recent_channel',
        lastActive: new Date('2017-04-20T21:17:58.810Z'),
        id: 'test1',
      },
      {
        title: 'not_recent_channel',
        lastActive: new Date('2017-03-20T21:17:58.810Z'),
        id: 'test2',
      },
      {
        title: 'null_channel',
        lastActive: null,
        id: 'test3',
      },
    ],
    viewBy: ViewBy.CHANNEL,
    sortColumn: '',
    sortOrder: '',
  },
});

function makeWrapper(options = {}, state) {
  const store = new Vuex.Store({
    state: state || initialState(),
  });
  return mount(ChannelListPage, {
    ...options,
    stubs: ['report-subheading', 'name-cell', 'breadcrumbs'],
    store,
  });
}

function getElements(wrapper) {
  return {
    channelRows: () => wrapper.findAll('tbody > tr'),
    headerText: () => wrapper.findAll('h1').at(0),
  };
}

describe('channel list page component', () => {
  let state;
  let clock;

  beforeEach(() => {
    state = initialState();
    // sets clock to 4/19/2017
    clock = sinon.useFakeTimers(Number(new Date(2017, 3, 19)));
  });

  afterEach(() => {
    clock.restore();
  });

  describe('in "show everything" mode', () => {
    it('shows the correct header', () => {
      const wrapper = makeWrapper({}, state);
      const { headerText } = getElements(wrapper);
      assert.equal(headerText().text(), 'Content');
    });

    it('shows all channels, regardless of activity', () => {
      const wrapper = makeWrapper({}, state);
      const { channelRows } = getElements(wrapper);
      // only checks the number of rows, not whether they are correct
      assert.equal(channelRows().length, 3);
    });
  });

  describe('in "show recent only" mode', () => {
    beforeEach(() => {
      state.pageState.showRecentOnly = true;
    });

    it('shows the "recent activity" header', () => {
      const wrapper = makeWrapper({}, state);
      const { headerText } = getElements(wrapper);
      assert.equal(headerText().text(), 'Recent activity');
    });

    it('hides channels that have null or not-recent activity', () => {
      const wrapper = makeWrapper({}, state);
      const { channelRows } = getElements(wrapper);
      assert.equal(channelRows().length, 1);
    });
  });
});

{'fraction_non_alphanumeric': 0.17588195386702848, 'fraction_numerical': 0.018656716417910446, 'mean_word_length': 2.7488874761602036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '7487376', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1813, 'n_words': 428}