<commit_before>import {Charity} from '../../src/dashboard-child-routes/charity';
import {App} from '../../src/app';
import {AuthStub, HttpMock, AppStateStub} from './commons';
import {Validator} from 'aurelia-validation';

class VCMock {
  createForCurrentScope(validator) {
    return {validateTrigger: null};
  }
}

class ValidatorMock extends Validator {
  constructor(a, b) {
    super();
    this.a = a;
    this.b = b;
  }
  validateObject(obj, rules) {
    console.log('obj');
    console.log(obj);
    if (obj.charityTypes.indexOf('True') > -1){
      return Promise.resolve([{rule: Object, object: Object, propertyName: 'charityPhoneNumber', valid: true, message: 'Charity Phone Number is correct'}]);
    }
    return Promise.resolve([{rule: Object, object: Object, propertyName: 'charityPhoneNumber', valid: false, message: 'Charity Phone Number is not correct'}]);
  }
  validateProperty(prop, val, rules) {
    return Promise.resolve({});
  }
}

describe('the Charity Module', () => {
  let charity;
  let app;
  let auth;
  let vc;
  let val;
  beforeEach(() => {
    vc = new VCMock();
    val = new ValidatorMock();
    auth = new AuthStub();
    auth.setToken({sub: '<PASSWORD>'});
    app = new App(auth, new HttpMock());
    app.activate();
    charity = new Charity(app, vc, val);
    charity.app.appState = new AppStateStub();
  });

  it('activates', (done) => {
    charity.activate();
    done();
  });

  it('checkboxes expanded', (done) => {
    document.body.innerHTML = '  <iron-dropdown id="types" horizontal-align="right" vertical-align="top" style="margin-top:25px;"></iron-dropdown>';
    charity.expanded = true;
    charity.showCheckboxes('types');
    expect(charity.expanded).toBe(false);
    done();
  });

  it('checkboxes closed', (done) => {
    document.body.innerHTML = '  <iron-dropdown id="types" horizontal-align="right" vertical-align="top" style="margin-top:25px;"></iron-dropdown>';
    charity.expanded = false;
    charity.showCheckboxes('types');
    expect(charity.expanded).toBe(true);
    done();
  });

  it('runs type picked when nothing is selected', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('runs type picked with valid types and other selected and can submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = true;
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('runs type picked with valid types and other selected and cannot submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('validates the charity form to allow submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validType = true;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('does not allow submit when type is not selected', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validType = false;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('does not allow submit when validationResults are false', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('allows submit when validationResults are true', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['True'];
    charity.validType = true;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });


  it('new charity created', (done) => {
    //charity.app.appState = new AppStateStub();
    charity.activate();
    charity.user = {'name': '<NAME>', '_id': '32'};
    charity.newCharity.charityState = 1;
    charity.createCharity();
    expect(charity.newCharity.charityManagers[0]).toBe('Test Name');
    expect(charity.newCharity.charityState).toBe('Alabama');
    done();
  });
});<commit_msg>100% coverage to charity<commit_after>import {Charity} from '../../src/dashboard-child-routes/charity';
import {App} from '../../src/app';
import {AuthStub, HttpMock, AppStateStub} from './commons';
import {Validator} from 'aurelia-validation';

class VCMock {
  createForCurrentScope(validator) {
    return {validateTrigger: null};
  }
}

class ValidatorMock extends Validator {
  constructor(a, b) {
    super();
    this.a = a;
    this.b = b;
  }
  validateObject(obj, rules) {
    console.log('obj');
    console.log(obj);
    if (obj.charityTypes.indexOf('True') > -1){
      return Promise.resolve([{rule: Object, object: Object, propertyName: 'charityPhoneNumber', valid: true, message: 'Charity Phone Number is correct'}]);
    }
    return Promise.resolve([{rule: Object, object: Object, propertyName: 'charityPhoneNumber', valid: false, message: 'Charity Phone Number is not correct'}]);
  }
  validateProperty(prop, val, rules) {
    return Promise.resolve({});
  }
}

class HttpMockChar extends HttpMock {
  fetch(url, obj) {
    this.headers.url = url;
    this.headers.method = obj ? obj.method : 'GET';
    if (obj && obj.method === 'put') {
      this.user = obj.body;
    }
    this.status = 200;
    return Promise.resolve({
      Headers: this.headers,
      json: () => Promise.resolve([{charityTypes: ['Home', 'Elderly']}, {charityTypes: ['Home', 'Elderly', 'other']}, {charityTypes: []}])
    });
  }
}

describe('the Charity Module', () => {
  let charity;
  let app;
  let auth;
  let vc;
  let val;
  beforeEach(() => {
    vc = new VCMock();
    val = new ValidatorMock();
    auth = new AuthStub();
    auth.setToken({sub: '<PASSWORD>'});
    app = new App(auth, new HttpMockChar());
    app.activate();
    charity = new Charity(app, vc, val);
    charity.app.appState = new AppStateStub();
  });

  it('activates', (done) => {
    charity.activate();
    done();
  });

  it('checkboxes expanded', (done) => {
    document.body.innerHTML = '  <iron-dropdown id="types" horizontal-align="right" vertical-align="top" style="margin-top:25px;"></iron-dropdown>';
    charity.expanded = true;
    charity.showCheckboxes('types');
    expect(charity.expanded).toBe(false);
    done();
  });

  it('checkboxes closed', (done) => {
    document.body.innerHTML = '  <iron-dropdown id="types" horizontal-align="right" vertical-align="top" style="margin-top:25px;"></iron-dropdown>';
    charity.expanded = false;
    charity.showCheckboxes('types');
    expect(charity.expanded).toBe(true);
    done();
  });

  it('runs type picked when nothing is selected', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('runs type picked with valid types and other selected and can submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = true;
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('runs type picked with valid types and other selected and cannot submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.typePicked();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('validates the charity form to allow submit', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validType = true;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('does not allow submit when type is not selected', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validType = false;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('does not allow submit when validationResults are false', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['Christian', 'other'];
    charity.canSubmit = false;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('allows submit when validationResults are true', (done) => {
    document.body.innerHTML = '<button id="newCharityButton">';
    charity.newCharity.charityTypes = ['True'];
    charity.validType = true;
    charity.validate();
    //expect(charity.newCharity.charityType.length).toBe(0);
    done();
  });

  it('new charity created', (done) => {
    //charity.app.appState = new AppStateStub();
    charity.activate();
    charity.user = {'name': '<NAME>', '_id': '32'};
    charity.newCharity.charityState = 1;
    charity.createCharity();
    expect(charity.newCharity.charityManagers[0]).toBe('<NAME>');
    expect(charity.newCharity.charityState).toBe('Alabama');
    done();
  });

  it('deletes charity', (done) => {
    charity.deleteCharity();
    done();
  });
});
{'fraction_non_alphanumeric': 0.17291811760023879, 'fraction_numerical': 0.003780718336483932, 'mean_word_length': 3.8049713193116634, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 60, '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': '949031', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3213, 'n_words': 666}