const expect = chai.expect
import {describe, it} from 'mocha'
import reducer from 'ember-frost-bunsen/reducer'
import {CHANGE_VALUE, VALIDATION_RESOLVED} from 'ember-frost-bunsen/actions'

describe('initial state', function () {
  it('should be what we want', function () {
    const initialState = reducer({}, {type: '@@redux/INIT'})

    expect(initialState.errors).to.eql({})
    expect(initialState.validationResult).to.eql({warnings: [], errors: []})
    expect(initialState.value).to.eql(null)
  })
})

describe('value manipulation', function () {
  it('can change a value', function () {
    const initialState = {
      errors: {},
      validationResult: {warnings: [], errors: []},
      value: {
        foo: 12,
        bar: {
          qux: 'cheese'
        }
      },
      baseModel: {}
    }
    const changedState = reducer(initialState, {type: CHANGE_VALUE, value: 'wine', bunsenId: 'bar.qux'})
    expect(changedState.value.bar.qux).to.eql('wine')
    expect(changedState.value.foo).to.eql(12)
      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 1})
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', false)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expectOnValidationState({props}, {count: 0})
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', true)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expectOnValidationState({props}, {count: 0})
          })
        })
      })
      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {
            count: 1,
            errors: [
              {
                code: 'OBJECT_MISSING_REQUIRED_PROPERTY',
                params: ['foo'],
                message: 'Field is required.',
                path: '#/foo',
                isRequiredError: true
              }
            ]
          })
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: false
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: true
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              error: true,
              text: ''
            })

            expectBunsenInputToHaveError('foo', 'Field is required.', 'my-form')

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })
      })
describe('#Client-Containers-Users-Dialogs-PasswordResetDialog', () => {

  const renderComponent = (options, languageDictionary) => {
    options = options || {};
    const initialState = {
      passwordReset: fromJS({
        user: { name: options.username, email: '*****@*****.**' },
        error: null,
        requesting: true,
        loading: false,
        connection: 'connA'
      }),
      languageDictionary: fromJS({
        record: languageDictionary || {}
      }),
      settings: fromJS(options.settings || {}),
      connections: fromJS({
        records: options.connections || [ { name: 'connA' }, { name: 'connB' } ]
      }),
      user: fromJS({
        connection: {
          name: 'connA',
          enabled_clients: [ 1, 2 ]
        }
      }),
      applications: fromJS({
        records: [
          {
            name: 'app1',
            client_id: 1
          }, {
            name: 'app2',
            client_id: 2
          }]
      })
    };
    return wrapperMount(
      <Provider store={fakeStore(initialState)}>
        <PasswordResetDialog
          cancelPasswordReset={() => null}
          resetPassword={() => null}
        />
      </Provider>
    );
  };

  beforeEach(() => {
    wrapper = undefined;
    document.body.innerHTML = '';
  });

  afterEach(() => {
    if (wrapper && wrapper.unmount) wrapper.unmount();
  });

  const checkText = (component, preText, username, postText) => {
    expect(document.querySelector('p')
      .textContent).to.equal(`${preText}${username}${postText}`);
  };

  const checkConnectionLabel = (component, connectionLabel) => {
    if (connectionLabel) {
      const label = document.querySelector('label[for=connection]');
      expect(label).to.not.be.null;
      expect(label.textContent).to.equal(connectionLabel);
    } else {
      expect(document.querySelector('label[for=connection]')).to.be.null;
    }
  };

  const checkEmailLabel = (component, emailLabel) => {
    expect(document.querySelector('label[for=email]')
      .textContent).to.equal(emailLabel);
  };

  const checkClientLabel = (component, passwordLabel) => {
    expect(document.querySelector('label[for=client]')
      .textContent).to.equal(passwordLabel);
  };

  const checkConfirm = (component, title) => {
    const confirm = component.find(Confirm);
    expect(confirm.length).to.equal(1);
    expect(confirm.prop('title')).to.deep.equal(title);
  };

  it('should render', () => {
    const component = renderComponent({ username: '******' });

    checkText(component, 'Do you really want to reset the password for ', 'bill', '? This will send an email to the' +
      ' user allowing them to choose a new password.');
    checkConnectionLabel(component, 'Connection');
    checkEmailLabel(component, 'Email');
    checkClientLabel(component, 'Client (required)');
    checkConfirm(component, 'Reset Password?');
  });

  it('should render without connection field', () => {
    const component = renderComponent({ username: '******', connections: [ { name: 'connA' } ] });

    checkText(component, 'Do you really want to reset the password for ', 'bill', '? This will send an email to the' +
      ' user allowing them to choose a new password.');
    checkConnectionLabel(component);
    checkEmailLabel(component, 'Email');
    checkClientLabel(component, 'Client (required)');
    checkConfirm(component, 'Reset Password?');
  });

  it('should render not applicable language dictionary', () => {
    const languageDictionary = { someKey: 'someValue' };
    const component = renderComponent({ username: '******' }, languageDictionary);

    checkText(component, 'Do you really want to reset the password for ', 'bill', '? This will send an email to the' +
      ' user allowing them to choose a new password.');
    checkConnectionLabel(component, 'Connection');
    checkEmailLabel(component, 'Email');
    checkClientLabel(component, 'Client (required)');
    checkConfirm(component, 'Reset Password?');
  });

  it('should render applicable language dictionary', () => {
    const languageDictionary = {
      resetPasswordMessage: 'Some pre message {username} ignore second {username}',
      resetPasswordTitle: 'Reset Password Title'
    };
    const component = renderComponent({ username: '******' }, languageDictionary);

    checkText(component, 'Some pre message ', 'bob', ' ignore second {username}');
    checkConfirm(component, 'Reset Password Title');
  });

  it('should render applicable language dictionary spaces in username', () => {
    const languageDictionary = {
      resetPasswordMessage: 'Some other message {   username    }something else'
    };
    const component = renderComponent({ username: '******' }, languageDictionary);

    checkText(component, 'Some other message ', 'sally', 'something else');
  });

  it('should render applicable language dictionary no username', () => {
    const languageDictionary = {
      resetPasswordMessage: 'no username included: '
    };
    const component = renderComponent({ username: '******' }, languageDictionary);

    checkText(component, 'no username included: ', 'john', '');
  });

  it('should use userFields for whether connection appears', () => {
    const settings = {
      record: {
        settings: {
          userFields: [
            {
              property: 'connection',
              label: 'ConnectionLabel',
              edit: false
            }
          ]
        }
      }
    };
    const component = renderComponent({ username: '******', settings });
    checkConnectionLabel(component);
  });

  it('should use userFields for label names', () => {
    const settings = {
      record: {
        settings: {
          userFields: [
            {
              property: 'email',
              label: 'EmailLabel',
              edit: {}
            },
            {
              property: 'client',
              label: 'ClientLabel',
              edit: {}
            },
            {
              property: 'connection',
              label: 'ConnectionLabel',
              edit: {}
            }
          ]
        }
      }
    };
    const component = renderComponent({ username: '******', settings });
    checkConnectionLabel(component, 'ConnectionLabel');
    checkEmailLabel(component, 'EmailLabel');
    checkClientLabel(component, 'ClientLabel');
  });

  it('should handle null label name in user fields', () => {
    const settings = {
      record: {
        settings: {
          userFields: [
            {
              property: 'client',
              edit: {}
            },
            {
              property: 'email',
              edit: {}
            },
            {
              property: 'connection',
              edit: {}
            }
          ]
        }
      }
    };
    const component = renderComponent({ username: '******', settings });
    checkConnectionLabel(component, 'Connection');
    checkEmailLabel(component, 'Email');
    checkClientLabel(component, 'Client');
  });
});
describe('Acceptance: MultipleSelect', function() {
  let application;

  beforeEach(function() {
    application = startApp();
  });

  afterEach(function() {
    destroyApp(application);
  });

  beforeEach(function() {
    return visit('/');
  });

  it("has entries for each select", function() {
    expect($('.spec-multiple-select-Horse').length).to.equal(1);
    expect($('.spec-multiple-select-Cow').length).to.equal(1);
    expect($('.spec-multiple-select-Lizard').length).to.equal(1);
  });

  it("honors the initial selection", function() {
    expect($('.spec-multiple-select-Horse').prop('checked')).to.equal(true);
    expect($('.spec-multiple-select-Cow').prop('checked')).to.equal(false);
    expect($('.spec-multiple-select-Lizard').prop('checked')).to.equal(false);
  });
  describe("clicking on the lizard input", function() {
    beforeEach(function() {
      click('.spec-multiple-select-Lizard');
    });
    it("selects the lizard checkbox", function() {
      expect($('.spec-multiple-select-Lizard').prop('checked')).to.equal(true);
    });
    it("keeps the horse checkbox checked", function() {
      expect($('.spec-multiple-select-Horse').prop('checked')).to.equal(true);
    });
  });
});
Example #6
0
import {describe, it} from 'mocha';
import {run} from '@ember/runloop';
import {setupModelTest} from 'ember-mocha';

describe('Unit: Model: role', function () {
    setupModelTest('role', {
        needs: ['service:ajax']
    });

    it('provides a lowercase version of the name', function () {
        let model = this.subject({
            name: 'Author'
        });

        expect(model.get('name')).to.equal('Author');
        expect(model.get('lowerCaseName')).to.equal('author');

        run(function () {
            model.set('name', 'Editor');

            expect(model.get('name')).to.equal('Editor');
            expect(model.get('lowerCaseName')).to.equal('editor');
        });
    });
});
import { expect } from 'chai';
import { it, describe } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('Unit | Controller | wallets/accounts/history', () => {
  setupTest('controller:wallets/accounts/history', {
    // Specify the other units that are required for this test.
    // needs: ['controller:foo']
  });

  // Replace this with your real tests.
  it('exists', function () {
    const controller = this.subject();
    expect(controller).to.be.ok;
  });
});
Example #8
0
describe('Acceptance: AboutRoute', function() {
  let application;
  let server;

  beforeEach(function() {
    application = startApp();
  });

  afterEach(function() {
    Ember.tryInvoke(server, 'shutdown');
    destroyApp(application);
  });

  describe('the index route', () => {
    it('can be visited when the session is not authenticated', () => {
      invalidateSession(application);
      visit('/about-me');

      return andThen(() => {
        expect(currentPath()).to.eq('about');
      });
    });

    it('can be visited when the session is authenticated', () => {
      authenticateSession(application, { account_id: 1});

      visit('/about-me');

      return andThen(() => {
        expect(currentPath()).to.eq('about');
        let session = currentSession(application);
        expect(session.get('data.authenticated.account_id')).to.eql(1);
      });
    });
  });
});
/* jshint expr:true */
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= classifiedModuleName %>Validator', function() {
  setupTest('validator:<%= dasherizedModuleName %>', {
    // Specify the other units that are required for this test.
    needs: ['validator:messages']
  });

  // Replace this with your real tests.
  it('exists', function() {
    const validator = this.subject();
    expect(validator).to.be.ok;
  });
});
describe('Integration: Component / frost-bunsen-detail / array of strings', function () {
  describe('without initial value', function () {
    setupDetailComponentTest({
      bunsenModel: {
        properties: {
          foo: {
            items: {
              type: 'string'
            },
            type: 'array'
          }
        },
        type: 'object'
      }
    })

    it('renders as expected', function () {
      expectCollapsibleHandles(0, 'bunsenDetail')

      expect(
        this.$(selectors.bunsen.renderer.text),
        'does not render any bunsen text inputs'
      )
        .to.have.length(0)

      expect(
        findTextInputs(),
        'does not render any text inputs'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.bunsen.array.sort.handle),
        'does not render any sort handles'
      )
        .to.have.length(0)

      const $button = this.$(selectors.frost.button.input.enabled)

      expect(
        $button,
        'does not have any buttons'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.error),
        'does not have any validation errors'
      )
        .to.have.length(0)

      const $emptyMsg = this.$(selectors.bunsen.array.emptyMsg)

      expect(
        $emptyMsg,
        'has empty array message'
      )
        .to.have.length(1)

      expect(
        $emptyMsg.text().trim(),
        'has empty array message'
      )
        .to.equal('List is currently empty.')
    })

    describe('when autoAdd enabled', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              arrayOptions: {
                autoAdd: true
              },
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'bunsenDetail')

        expect(
          this.$(selectors.bunsen.renderer.text),
          'does not render any bunsen text inputs'
        )
          .to.have.length(0)

        expect(
          findTextInputs(),
          'does not render any text inputs'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.array.sort.handle),
          'does not render any sort handles'
        )
          .to.have.length(0)

        const $button = this.$(selectors.frost.button.input.enabled)

        expect(
          $button,
          'does not have any buttons'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        const $emptyMsg = this.$(selectors.bunsen.array.emptyMsg)

        expect(
          $emptyMsg,
          'has empty array message'
        )
          .to.have.length(1)

        expect(
          $emptyMsg.text().trim(),
          'has empty array message'
        )
          .to.equal('List is currently empty.')
      })
    })
  })

  describe('with initial value', function () {
    setupDetailComponentTest({
      bunsenModel: {
        properties: {
          foo: {
            items: {
              type: 'string'
            },
            type: 'array'
          }
        },
        type: 'object'
      },
      value: {
        foo: ['bar', 'baz']
      }
    })

    it('renders as expected', function () {
      expectCollapsibleHandles(0, 'bunsenDetail')

      const $static = this.$(selectors.bunsen.renderer.static)
      const value = this.get('value')

      expect(
        $static,
        'renders a bunsen static input for each array item'
      )
        .to.have.length(2)

      $static.each((index, el) => {
        expect(
          el.textContent.includes(value.foo[index]),
          'has the correct values'
        )
          .to.equal(true)
      })

      expect(
        $static,
        'renders a bunsen static input for each array item'
      )
        .to.have.length(2)

      expect(
        this.$(selectors.bunsen.array.sort.handle),
        'does not render sort handle for array items'
      )
        .to.have.length(0)

      const $button = this.$(selectors.frost.button.input.enabled)

      expect(
        $button,
        'does not render any buttons'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.error),
        'does not have any validation errors'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.bunsen.array.emptyMsg),
        'does not have empty array message'
      )
        .to.have.length(0)
    })

    describe('when sortable enabled', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              arrayOptions: {
                sortable: true
              },
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'bunsenDetail')

        const $static = this.$(selectors.bunsen.renderer.static)
        const value = this.get('value')

        expect(
          $static,
          'renders a bunsen static input for each array item'
        )
          .to.have.length(2)

        $static.each((index, el) => {
          expect(
            el.textContent.includes(value.foo[index]),
            'has the correct values'
          )
            .to.equal(true)
        })

        expect(
          this.$(selectors.bunsen.array.sort.handle),
          'does not render sort handle for array items'
        )
          .to.have.length(0)

        const $button = this.$(selectors.frost.button.input.enabled)

        expect(
          $button,
          'does not render any buttons'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.array.emptyMsg),
          'does not have empty array message'
        )
          .to.have.length(0)
      })
    })

    describe('when autoAdd enabled', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              arrayOptions: {
                autoAdd: true
              },
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'bunsenDetail')

        const $static = this.$(selectors.bunsen.renderer.static)
        const value = this.get('value')

        expect(
          $static,
          'renders a bunsen static input for each array item'
        )
          .to.have.length(2)

        $static.each((index, el) => {
          expect(
            el.textContent.includes(value.foo[index]),
            'has the correct values'
          )
            .to.equal(true)
        })

        expect(
          this.$(selectors.bunsen.array.sort.handle),
          'does not render sort handle for array items'
        )
          .to.have.length(0)

        const $button = this.$(selectors.frost.button.input.enabled)

        expect(
          $button,
          'does not render any buttons'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.array.emptyMsg),
          'does not have empty array message'
        )
          .to.have.length(0)
      })
    })
  })
})
Example #11
0
const port = process.env.PORT || 3000;

mocha.describe('API v2', () => {
  mocha.describe('GET /api/v2', () => {
    let app;

    mocha.before((done) => {
      app = server.listen(port);
      done();
    });

    mocha.it('returns status code 200', (done) => {
      request(app)
        .get('/api/v2/')
        .expect('Content-Type', /json/)
        .expect(200)
        .end((err, res) => {
          if (err) throw err;
          assert.isTrue(res.body.success);
          assert.equal(res.body.api, 'v2');
          done();
        });
    });

    mocha.after((done) => {
      app.close();
      done();
    });
  });
});
  describe('without initial value', function () {
    setupDetailComponentTest({
      bunsenModel: {
        properties: {
          foo: {
            items: {
              type: 'string'
            },
            type: 'array'
          }
        },
        type: 'object'
      }
    })

    it('renders as expected', function () {
      expectCollapsibleHandles(0, 'bunsenDetail')

      expect(
        this.$(selectors.bunsen.renderer.text),
        'does not render any bunsen text inputs'
      )
        .to.have.length(0)

      expect(
        findTextInputs(),
        'does not render any text inputs'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.bunsen.array.sort.handle),
        'does not render any sort handles'
      )
        .to.have.length(0)

      const $button = this.$(selectors.frost.button.input.enabled)

      expect(
        $button,
        'does not have any buttons'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.error),
        'does not have any validation errors'
      )
        .to.have.length(0)

      const $emptyMsg = this.$(selectors.bunsen.array.emptyMsg)

      expect(
        $emptyMsg,
        'has empty array message'
      )
        .to.have.length(1)

      expect(
        $emptyMsg.text().trim(),
        'has empty array message'
      )
        .to.equal('List is currently empty.')
    })

    describe('when autoAdd enabled', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              arrayOptions: {
                autoAdd: true
              },
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'bunsenDetail')

        expect(
          this.$(selectors.bunsen.renderer.text),
          'does not render any bunsen text inputs'
        )
          .to.have.length(0)

        expect(
          findTextInputs(),
          'does not render any text inputs'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.array.sort.handle),
          'does not render any sort handles'
        )
          .to.have.length(0)

        const $button = this.$(selectors.frost.button.input.enabled)

        expect(
          $button,
          'does not have any buttons'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        const $emptyMsg = this.$(selectors.bunsen.array.emptyMsg)

        expect(
          $emptyMsg,
          'has empty array message'
        )
          .to.have.length(1)

        expect(
          $emptyMsg.text().trim(),
          'has empty array message'
        )
          .to.equal('List is currently empty.')
      })
    })
  })
Example #13
0
describe('Acceptance: Settings - Navigation', function () {
    let application;

    beforeEach(function () {
        application = startApp();
    });

    afterEach(function () {
        destroyApp(application);
    });

    it('redirects to signin when not authenticated', function () {
        invalidateSession(application);
        visit('/settings/navigation');

        andThen(function () {
            expect(currentURL(), 'currentURL').to.equal('/signin');
        });
    });

    it('redirects to team page when authenticated as author', function () {
        let role = server.create('role', {name: 'Author'});
        let user = server.create('user', {roles: [role], slug: 'test-user'});

        authenticateSession(application);
        visit('/settings/navigation');

        andThen(function () {
            expect(currentURL(), 'currentURL').to.equal('/team/test-user');
        });
    });

    describe('when logged in', function () {
        beforeEach(function () {
            let role = server.create('role', {name: 'Administrator'});
            let user = server.create('user', {roles: [role]});

            // load the settings fixtures
            // TODO: this should always be run for acceptance tests
            server.loadFixtures();

            authenticateSession(application);
        });

        it('can visit /settings/navigation', function () {
            visit('/settings/navigation');

            andThen(function () {
                expect(currentPath()).to.equal('settings.navigation');
                // test has expected number of rows
                expect($('.gh-blognav-item').length, 'navigation items count').to.equal(3);
            });
        });

        it('saves settings', function () {
            visit('/settings/navigation');
            fillIn('.gh-blognav-label:first input', 'Test');
            fillIn('.gh-blognav-url:first input', '/test');
            triggerEvent('.gh-blognav-url:first input', 'blur');

            click('.btn-blue');

            andThen(function () {
                // TODO: Test for successful save here once we have a visual
                // indication. For now we know the save happened because
                // Pretender doesn't complain about an unknown URL

                // don't test against .error directly as it will pick up failed
                // tests "pre.error" elements
                expect($('span.error').length, 'error fields count').to.equal(0);
                expect($('.gh-alert').length, 'alerts count').to.equal(0);
            });
        });

        it('clears unsaved settings when navigating away', function () {
            visit('/settings/navigation');
            fillIn('.gh-blognav-label:first input', 'Test');
            triggerEvent('.gh-blognav-label:first input', 'blur');

            andThen(function () {
                expect($('.gh-blognav-label:first input').val()).to.equal('Test');
            });

            visit('/settings/code-injection');
            visit('/settings/navigation');

            andThen(function () {
                expect($('.gh-blognav-label:first input').val()).to.equal('Home');
            });
        });
    });
});
Example #14
0
describe('create', () => {
    it('should return object as is if it`s a BemEntityName', () => {
        const entityName = new BemEntityName({ block: 'block' });

        expect(BemEntityName.create(entityName)).to.equal(entityName);
    });

    it('should create block from object', () => {
        const entityName = BemEntityName.create({ block: 'block' });

        expect(entityName instanceof BemEntityName, 'Should be an instance of BemEntityName').to.be.true;
        expect(entityName.valueOf(), 'Should contain a name for same entity').to.deep.equal({ block: 'block' });
    });

    it('should create block by a string', () => {
        const entityName = BemEntityName.create('block');

        expect(entityName.valueOf()).to.deep.equal({ block: 'block' });
    });

    it('should create element from object', () => {
        const entityName = BemEntityName.create({ block: 'block', elem: 'elem' });

        expect(entityName.valueOf()).to.deep.equal({ block: 'block', elem: 'elem' });
    });

    it('should create simple modifier of block from object', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: 'mod' });

        expect(entityName.valueOf()).to.deep.equal({ block: 'block', mod: { name: 'mod', val: true } });
    });

    it('should create modifier of block from object', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: 'mod', val: 'val' });

        expect(entityName.valueOf()).to.deep.equal({ block: 'block', mod: { name: 'mod', val: 'val' } });
    });

    it('should normalize boolean modifier', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'mod' } });

        expect(entityName.mod.val).to.be.true;
    });

    it('should save normalized boolean modifier', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'mod' } });

        expect(entityName.mod.val).to.be.true;
    });

    it('should support `modName` and `modVal` fields', () => {
        const entityName = BemEntityName.create({ block: 'block', modName: 'mod', modVal: 'val' });

        expect(entityName.mod).to.deep.equal({ name: 'mod', val: 'val' });
    });

    it('should support `modName` field only', () => {
        const entityName = BemEntityName.create({ block: 'block', modName: 'mod' });

        expect(entityName.mod).to.deep.equal({ name: 'mod', val: true });
    });

    it('should use `mod.name` field instead of `modName`', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'mod1' }, modName: 'mod2' });

        expect(entityName.mod.name).to.be.equal('mod1');
    });

    it('should use `mod.val` field instead of `modVal`', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'm', val: 'v1' }, modVal: 'v2' });

        expect(entityName.mod.val).to.be.equal('v1');
    });

    it('should use `mod.name` and `mod.val` instead of `val`', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'm', val: 'v1' }, val: 'v3'});

        expect(entityName.mod.val).to.be.equal('v1');
    });

    it('should use `mod.name` and `mod.val` instead of `modVal` and `val`', () => {
        const entityName = BemEntityName.create({ block: 'block', mod: { name: 'm', val: 'v1' }, modVal: 'v2', val: 'v3'});

        expect(entityName.mod.val).to.be.equal('v1');
    });
});
describe(test.label, function () {
  test.setup()

  it('block format', function () {
    const label = 'b'
    const value = 'a'

    this.set('label', label)
    this.set('value', value)

    this.render(hbs`
      {{#frost-radio-group hook='myRadioGroup' as |controls|}}
        {{controls.button value=value label=label}}
      {{/frost-radio-group}}
    `)

    expect(
      this.$('.frost-radio-button-input').first().prop('value'),
      'value is set'
    ).to.eql(value)

    expect(
      this.$('.frost-radio-button').first().text().trim(),
      'label is set'
    ).to.eql(label)
  })

  it('inline format', function () {
    const inputs = [
      {value: 'a', label: 'b'}
    ]

    this.set('inputs', inputs)

    this.render(hbs`
      {{frost-radio-group hook='myRadioGroup' inputs=inputs}}
    `)

    expect(
      this.$('.frost-radio-button-input').first().prop('value'),
      'value is set'
    ).to.eql(inputs[0].value)

    expect(
      this.$('.frost-radio-button').first().text().trim(),
      'label is set'
    ).to.eql(inputs[0].label)
  })

  it('set hook property', function () {
    const hook = 'my-hook'

    this.set('hook', hook)

    this.render(hbs`
      {{frost-radio-group hook=hook}}
    `)

    expect(
      $hook(`${hook}`).hasClass('frost-radio-group'),
      'radio button group is set'
    ).to.equal(true)
  })

  it('renders using spread', function () {
    const value = 'b'
    const label = `Label for ${value}`

    this.set('value', value)
    this.set('label', label)

    this.render(hbs`
      {{#frost-radio-group
        options=(hash
          hook='myRadioGroup'
          id='radioGroup7'
          selectedValue=value
        )
        as |controls|
      }}
          {{#controls.button
            options=(hash
              size='medium'
            )
            value=value
          }}
            {{label}}
          {{/controls.button}}
      {{/frost-radio-group}}
    `)

    expect(
      this.$('.frost-radio-button-input').first().prop('value'),
      'value is set'
    ).to.eql(value)

    expect(
      this.$('.frost-radio-button').first().text().trim(),
      'label is set'
    ).to.eql(label)
  })
})
describe('Schema Validation: TypeField / ConnectionEdgeTypeIsNotNode: ', () => {
  it('Rule throws if appropriate context is not passed',() => {
    expect(rule.bind(null, { })).to.throw(Error, /context not passed to rule/);
  });

  it('Throw if NodeConnection defineds an edge that is a Node', () => {
    const test = `
      type TestCase implements Node {
        id: ID!
        conn: NodeConnection(RelatedType, testCase, MyEdgeType)
      }

      type RelatedType implements Node {
        id: ID!
        testCase: NodeConnection(TestCase, conn, MyEdgeType)
      }

      type MyEdgeType implements Node {
        id: ID!
        numberOfFoos: Int
      }
      `;
    const result = runTest(test);
    const { errors } = separateResults(result);
    expect(errors).to.deep.match(/Edge types cannot implement Node/);
  });

  it('Throw if ObjectConnection defineds an edge that is a Node', () => {
    const test = `
      type TestCase implements Node {
        id: ID!
        objConn: ObjectConnection(Foo, MyEdgeType)
      }

      type Foo { foo: String }

      type MyEdgeType implements Node {
        id: ID!
        numberOfFoos: Int
      }
      `;
    const result = runTest(test);
    const { errors } = separateResults(result);
    expect(errors).to.deep.match(/Edge types cannot implement Node/);
  });

  it('Throw if ScalarConnection defineds an edge that is a Node', () => {
    const test = `
      type TestCase implements Node {
        id: ID!
        scalarConn: ScalarConnection(Int, MyEdgeType)
      }
      type MyEdgeType implements Node {
        id: ID!
        numberOfFoos: Int
      }
      `;
    const result = runTest(test);
    const { errors } = separateResults(result);
    expect(errors).to.deep.match(/Edge types cannot implement Node/);
  });
});
Example #17
0
import { describe, it } from 'mocha';
import expect from 'expect';

describe('Testing App component', () => {
  it('should work', () => {
    expect(true).toBe(true);
  })
})
Example #18
0
describe('Number', () => {
    it('should read/write roundtrip small integers', () => {
        should(lang.writeNumber(lang.readNumber('123')))
            .equal('123');
    });

    it('should read/write roundtrip large integers (2^128)', () => {
        should(lang.writeNumber(lang.readNumber('340282366920938463463374607431768211456')))
            .equal('340282366920938463463374607431768211456');
    });

    it('should read/write roundtrip small decimals', () => {
        should(lang.writeNumber(lang.readNumber('0.123')))
            .equal('0.123');
    });

    it('should read/write roundtrip large decimals', () => {
        should(lang.writeNumber(lang.readNumber('0.123456789123456789123456789')))
            .equal('0.123456789123456789123456789');
    });

    it('should read/write roundtrip small repeating decimals', () => {
        should(lang.writeNumber(lang.readNumber('0.(123)')))
            .equal('0.(123)');
    });

    it('should read/write roundtrip large repeating decimals (1/97)', () => {
        should(lang.writeNumber(lang.readNumber('0.(010309278350515463917525773195876288659793814432989690721649484536082474226804123711340206185567)')))
            .equal('0.(010309278350515463917525773195876288659793814432989690721649484536082474226804123711340206185567)');
    });

    it('should keep decimal precision on add', () => {
        let n = lang.add(lang.readNumber('0.1'), lang.readNumber('0.2'));
        should(lang.writeNumber(n))
            .equal('0.3');
    });

    it('should compare equal a repeating decimal and a fraction', () => {
        let x = lang.readNumber('0.(032258064516129)');
        let y = lang.divide(lang.readNumber('1'), lang.readNumber('31'));
        should(lang.isNumberEqual(x, y)).ok();
    });

    it('should compare equal a decimal and a fraction', () => {
        let x = lang.readNumber('0.5');
        let y = lang.divide(lang.readNumber('1'), lang.readNumber('2'));
        should(lang.isNumberEqual(x, y)).ok();
    });
});
Example #19
0
'use strict'

const { describe, it } = require('mocha')
const assert = require('assert')
const bitcoin = require('../../')

describe('bitcoinjs-lib (blocks)', function () {
  it('can extract a height from a CoinBase transaction', function () {
    // from 00000000000000000097669cdca131f24d40c4cc7d80eaa65967a2d09acf6ce6
    const txHex = '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98fd16761d220400000000000000aa340000d49f0000ffffffff02b07fc366000000001976a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12bf1e400120000000000000000000000000000000000000000000000000000000000000000000000000'
    const tx = bitcoin.Transaction.fromHex(txHex)

    assert.strictEqual(tx.ins.length, 1)
    const script = tx.ins[0].script
    // bitcoin.script.decompile(script) // returns [] :(

    assert.strictEqual(script[0], 0x03)
    const heightBuffer = script.slice(1, 4)
    const height = bitcoin.script.number.decode(heightBuffer)
    assert.strictEqual(height, 498303)
  })
})
Example #20
0
  function () {
    let props, sandbox

    beforeEach(function () {
      sandbox = sinon.sandbox.create()

      props = {
        bunsenModel: {
          properties: {
            foo: {
              type: 'string'
            }
          },
          type: 'object'
        },
        bunsenView: undefined,
        disabled: undefined,
        onChange: sandbox.spy(),
        onValidation: sandbox.spy(),
        showAllErrors: undefined
      }

      this.setProperties(props)

      this.render(hbs`{{frost-bunsen-form
        bunsenModel=bunsenModel
        bunsenView=bunsenView
        disabled=disabled
        onChange=onChange
        onValidation=onValidation
        showAllErrors=showAllErrors
      }}`)
    })

    afterEach(function () {
      sandbox.restore()
    })

    it('renders as expected', function () {
      expect(
        this.$(selectors.bunsen.collapsible.handle),
        'does not render collapsible handle'
      )
        .to.have.length(0)

      expect(
        this.$(selectors.bunsen.renderer.text),
        'renders a bunsen text input'
      )
        .to.have.length(1)

      expect(
        findTextInputs(),
        'renders one text input'
      )
        .to.have.length(1)

      expectTextInputWithState('bunsenForm-foo-input', {
        placeholder: ''
      })

      expect(
        this.$(selectors.bunsen.label).text().trim(),
        'renders expected label text'
      )
        .to.equal('Foo')

      expect(
        this.$(selectors.error),
        'does not have any validation errors'
      )
        .to.have.length(0)

      expect(
        props.onValidation.callCount,
        'informs consumer of validation results'
      )
        .to.equal(1)

      const validationResult = props.onValidation.lastCall.args[0]

      expect(
        validationResult.errors.length,
        'informs consumer there are no errors'
      )
        .to.equal(0)

      expect(
        validationResult.warnings.length,
        'informs consumer there are no warnings'
      )
        .to.equal(0)
    })

    describe('when label defined in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              label: 'FooBar Baz',
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.collapsible.handle),
          'does not render collapsible handle'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          placeholder: ''
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('FooBar Baz')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })
    })

    describe('when collapsible is set to true in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              collapsible: true,
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.collapsible.handle),
          'renders collapsible handle'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          placeholder: ''
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })
    })

    describe('when collapsible is set to false in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              collapsible: false,
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.collapsible.handle),
          'does not render collapsible handle'
        )
          .to.have.length(0)

        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          placeholder: ''
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })
    })

    describe('when placeholder defined in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              model: 'foo',
              placeholder: 'Foo bar'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          placeholder: 'Foo bar'
        })

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })
    })

    describe('when type defined in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              model: 'foo',
              renderer: {
                name: 'string',
                type: 'date'
              }
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        const $input = this.$(selectors.frost.text.type.date.input.enabled)

        // TODO: figure out why hook doesn't work when type isn't text
        expectTextInputWithState($input, {
          placeholder: ''
          // type: 'date' // TODO: figure out why this fails
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })
    })

    describe('when form explicitly enabled', function () {
      beforeEach(function () {
        this.set('disabled', false)
      })

      it('renders as expected', function () {
        expect(
          findTextInputs(),
          'renders an enabled text input'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)
      })
    })

    describe('when form disabled', function () {
      beforeEach(function () {
        this.set('disabled', true)
      })

      it('renders as expected', function () {
        expect(
          findTextInputs(),
          'renders a disabled text input'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)
      })
    })

    describe('when property explicitly enabled in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              disabled: false,
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          findTextInputs(),
          'renders an enabled text input'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)
      })
    })

    describe('when property disabled in view', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              disabled: true,
              model: 'foo'
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      it('renders as expected', function () {
        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          disabled: true
        })

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)
      })
    })

    describe('when user inputs value', function () {
      const input = 'bar'

      beforeEach(function () {
        props.onValidation = sandbox.spy()
        this.set('onValidation', props.onValidation)
        fillIn('bunsenForm-foo-input', input)
      })

      it('functions as expected', function () {
        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders one text input'
        )
          .to.have.length(1)

        expectTextInputWithState('bunsenForm-foo-input', {
          placeholder: '',
          value: `${input}`
        })

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onChange.lastCall.args[0],
          'informs consumer of change'
        )
          .to.eql({
            foo: input
          })

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors,
          'has no validation errors'
        )
          .to.eql([])

        expect(
          validationResult.warnings,
          'has no validation warnings'
        )
          .to.eql([])
      })
    })

    describe('when field is required', function () {
      beforeEach(function () {
        props.onValidation = sandbox.spy()

        this.setProperties({
          bunsenModel: {
            properties: {
              foo: {
                type: 'string'
              }
            },
            required: ['foo'],
            type: 'object'
          },
          onValidation: props.onValidation
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders an enabled text input'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there is one error'
        )
          .to.equal(1)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })

      describe('when showAllErrors is false', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()

          this.setProperties({
            onValidation: props.onValidation,
            showAllErrors: false
          })
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders an enabled text input'
          )
            .to.have.length(1)

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'does not inform consumer of validation results'
          )
            .to.equal(0)
        })
      })

      describe('when showAllErrors is true', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()

          this.setProperties({
            onValidation: props.onValidation,
            showAllErrors: true
          })
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders an enabled text input'
          )
            .to.have.length(1)

          expectBunsenInputToHaveError('foo', 'Field is required.')

          expect(
            props.onValidation.callCount,
            'does not inform consumer of validation results'
          )
            .to.equal(0)
        })
      })
    })

    describe('transforms', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              model: 'foo',
              transforms: {
                read: [
                  {
                    from: '^Chris$',
                    regex: true,
                    to: 'Christopher'
                  },
                  {
                    from: 'Matt',
                    to: 'Matthew'
                  }
                ],
                write: [
                  {
                    from: '^Alexander$',
                    regex: true,
                    to: 'Alex'
                  },
                  {
                    from: 'Johnathan',
                    to: 'John'
                  }
                ]
              }
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      describe('applies literal string read transform', function () {
        const input = 'Matt'

        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', input)
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Matthew'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: input
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies regex string read transform', function () {
        const input = 'Chris'

        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', input)
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Christopher'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: input
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies literal string write transform', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', 'Johnathan')
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'John'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: 'John'
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies regex string write transform', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', 'Alexander')
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Alex'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: 'Alex'
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })
    })
  }
const { describe } = require('mocha');
const { runExercises } = require('../test-utils');

describe('Exercises Chapter 10', () => {
  runExercises('ch10');
});

Example #22
0
    describe('when field is required', function () {
      beforeEach(function () {
        props.onValidation = sandbox.spy()

        this.setProperties({
          bunsenModel: {
            properties: {
              foo: {
                type: 'string'
              }
            },
            required: ['foo'],
            type: 'object'
          },
          onValidation: props.onValidation
        })
      })

      it('renders as expected', function () {
        expect(
          this.$(selectors.bunsen.renderer.text),
          'renders a bunsen text input'
        )
          .to.have.length(1)

        expect(
          findTextInputs(),
          'renders an enabled text input'
        )
          .to.have.length(1)

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .to.equal(1)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there is one error'
        )
          .to.equal(1)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })

      describe('when showAllErrors is false', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()

          this.setProperties({
            onValidation: props.onValidation,
            showAllErrors: false
          })
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders an enabled text input'
          )
            .to.have.length(1)

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'does not inform consumer of validation results'
          )
            .to.equal(0)
        })
      })

      describe('when showAllErrors is true', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()

          this.setProperties({
            onValidation: props.onValidation,
            showAllErrors: true
          })
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders an enabled text input'
          )
            .to.have.length(1)

          expectBunsenInputToHaveError('foo', 'Field is required.')

          expect(
            props.onValidation.callCount,
            'does not inform consumer of validation results'
          )
            .to.equal(0)
        })
      })
    })
Example #23
0
import { expect } from 'chai';
import { describe, it } from 'mocha';
import {
  runTest,
  separateResults,
  tokenTypeDef
} from '../../../__tests__/setup';

import { NoArguments as rule } from '../NoArguments';

describe('Schema Validation: MutationField / NoArguments: ', () => {
  it('Rule throws if appropriate context is not passed',() => {
    expect(rule.bind(null, { })).to.throw(Error, /context not passed to rule/);
  });

  it('Mutation fields cannot define arguments', () => {
    const test = ` mutation failFast(id: ID) {
      id: ID!, foo(param: Int): String } ${tokenTypeDef} `;

    const result = runTest(test);
    const { errors } = separateResults(result);
    expect(errors).to.deep.match(
      /Field "foo" of mutation "failFast" cannot have arguments/);
  });
});
Example #24
0
    describe('transforms', function () {
      beforeEach(function () {
        this.set('bunsenView', {
          cells: [
            {
              model: 'foo',
              transforms: {
                read: [
                  {
                    from: '^Chris$',
                    regex: true,
                    to: 'Christopher'
                  },
                  {
                    from: 'Matt',
                    to: 'Matthew'
                  }
                ],
                write: [
                  {
                    from: '^Alexander$',
                    regex: true,
                    to: 'Alex'
                  },
                  {
                    from: 'Johnathan',
                    to: 'John'
                  }
                ]
              }
            }
          ],
          type: 'form',
          version: '2.0'
        })
      })

      describe('applies literal string read transform', function () {
        const input = 'Matt'

        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', input)
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Matthew'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: input
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies regex string read transform', function () {
        const input = 'Chris'

        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', input)
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Christopher'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: input
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies literal string write transform', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', 'Johnathan')
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'John'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: 'John'
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })

      describe('applies regex string write transform', function () {
        beforeEach(function () {
          props.onValidation = sandbox.spy()
          this.set('onValidation', props.onValidation)
          fillIn('bunsenForm-foo-input', 'Alexander')
        })

        it('functions as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.text),
            'renders a bunsen text input'
          )
            .to.have.length(1)

          expect(
            findTextInputs(),
            'renders one text input'
          )
            .to.have.length(1)

          expectTextInputWithState('bunsenForm-foo-input', {
            placeholder: '',
            value: 'Alex'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onChange.lastCall.args[0],
            'informs consumer of change'
          )
            .to.eql({
              foo: 'Alex'
            })

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors,
            'has no validation errors'
          )
            .to.eql([])

          expect(
            validationResult.warnings,
            'has no validation warnings'
          )
            .to.eql([])
        })
      })
    })
    describe('when no initial value', function () {
      beforeEach(function () {
        run(() => {
          resolver.resolve([
            Ember.Object.create({
              label: 'bar',
              value: 'bar'
            }),
            Ember.Object.create({
              label: 'baz',
              value: 'baz'
            })
          ])
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'my-form')

        expect(
          this.$(selectors.bunsen.renderer.select.input),
          'renders a bunsen select input'
        )
          .to.have.length(1)

        expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
          text: ''
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .not.to.equal(0)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })

      describe('when expanded/opened', function () {
        beforeEach(function () {
          $hook('my-form-foo').find('.frost-select').click()
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            items: ['bar', 'baz'],
            opened: true,
            text: ''
          })
        })
      })

      describe('when label defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                label: 'FooBar Baz',
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('FooBar Baz')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when collapsible is set to true in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(1, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when collapsible is set to false in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when placeholder defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    placeholder: 'Foo bar',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'Foo bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when form explicitly enabled', function () {
        beforeEach(function () {
          this.set('disabled', false)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when form disabled', function () {
        beforeEach(function () {
          this.set('disabled', true)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when property explicitly enabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when property disabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {
            count: 1,
            errors: [
              {
                code: 'OBJECT_MISSING_REQUIRED_PROPERTY',
                params: ['foo'],
                message: 'Field is required.',
                path: '#/foo',
                isRequiredError: true
              }
            ]
          })
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: false
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: true
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              error: true,
              text: ''
            })

            expectBunsenInputToHaveError('foo', 'Field is required.', 'my-form')

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })
      })
    })
describe('Integration: Component / frost-bunsen-form / errors / view / version unknown', function () {
  setupFormComponentTest({
    bunsenModel: {
      properties: {
        foo: {
          type: 'boolean'
        }
      },
      type: 'object'
    },
    bunsenView: {
      cells: [
        {
          model: 'foo'
        }
      ],
      type: 'form',
      version: '2.1'
    }
  })

  it('renders as expected', function () {
    const $heading = this.$(selectors.bunsen.validationErrors.heading)
    const $error = this.$(selectors.bunsen.validationErrors.error)

    expect(
      $heading,
      'has validation errors heading'
    )
      .to.have.length(1)

    expect(
      $heading.text().trim(),
      'validation errors heading has expected text'
    )
      .to.equal('There seems to be something wrong with your view schema')

    expect(
      $error,
      'has one validation error'
    )
      .to.have.length(1)

    expect(
      $error.text().trim().replace(/\s+/g, ' '),
      'validation error has correct text'
    )
      .to.equal('ERROR: #/version No enum match for: 2.1')
  })
})
describe('Integration: Component / frost-bunsen-form / renderer / multi-select Ember Data view query /', function () {
  setupComponentTest('frost-bunsen-form', {
    integration: true
  })

  let props, sandbox, resolver, store

  beforeEach(function () {
    sandbox = sinon.sandbox.create()
    initialize()
    resolver = {}

    store = {
      query () {
        return new RSVP.Promise((resolve, reject) => {
          resolver.resolve = resolve
          resolver.reject = reject
        })
      }
    }
    sandbox.spy(store, 'query')
    this.register('service:store', Service.extend(store))

    props = {
      bunsenModel: {
        properties: {
          foo: {
            type: 'array',
            items: {
              type: 'string'
            }
          }
        },
        type: 'object'
      },
      bunsenView: {
        cells: [
          {
            model: 'foo',
            renderer: {
              name: 'multi-select',
              options: {
                labelAttribute: 'label',
                modelType: 'node',
                query: {
                  baz: 'alpha',
                  filter: '[fizz]=$filter'
                },
                valueAttribute: 'value'
              }
            }
          }
        ],
        type: 'form',
        version: '2.0'
      },
      disabled: undefined,
      hook: 'my-form',
      onChange: sandbox.spy(),
      onError: sandbox.spy(),
      onValidation: sandbox.spy(),
      showAllErrors: undefined
    }

    this.setProperties(props)

    this.render(hbs`
      {{frost-select-outlet hook='selectOutlet'}}
      {{frost-bunsen-form
        bunsenModel=bunsenModel
        bunsenView=bunsenView
        disabled=disabled
        hook=hook
        onChange=onChange
        onError=onError
        onValidation=onValidation
        showAllErrors=showAllErrors
        value=value
      }}
    `)

    return wait()
  })

  afterEach(function () {
    sandbox.restore()
    props = null
    resolver = null
    sandbox = null
  })

  it('should perform initial query', function () {
    expect(store.query).to.have.been.calledWith('node', {baz: 'alpha', filter: '[fizz]='})
  })

  describe('when query succeeds', function () {
    describe('when no initial value', function () {
      beforeEach(function () {
        run(() => {
          resolver.resolve([
            Ember.Object.create({
              label: 'bar',
              value: 'bar'
            }),
            Ember.Object.create({
              label: 'baz',
              value: 'baz'
            })
          ])
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'my-form')

        expect(
          this.$(selectors.bunsen.renderer.select.input),
          'renders a bunsen select input'
        )
          .to.have.length(1)

        expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
          text: ''
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expect(
          props.onValidation.callCount,
          'informs consumer of validation results'
        )
          .not.to.equal(0)

        const validationResult = props.onValidation.lastCall.args[0]

        expect(
          validationResult.errors.length,
          'informs consumer there are no errors'
        )
          .to.equal(0)

        expect(
          validationResult.warnings.length,
          'informs consumer there are no warnings'
        )
          .to.equal(0)
      })

      describe('when expanded/opened', function () {
        beforeEach(function () {
          $hook('my-form-foo').find('.frost-select').click()
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            items: ['bar', 'baz'],
            opened: true,
            text: ''
          })
        })
      })

      describe('when label defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                label: 'FooBar Baz',
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('FooBar Baz')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when collapsible is set to true in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(1, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when collapsible is set to false in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when placeholder defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    placeholder: 'Foo bar',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'Foo bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expect(
            props.onValidation.callCount,
            'informs consumer of validation results'
          )
            .to.equal(1)

          const validationResult = props.onValidation.lastCall.args[0]

          expect(
            validationResult.errors.length,
            'informs consumer there are no errors'
          )
            .to.equal(0)

          expect(
            validationResult.warnings.length,
            'informs consumer there are no warnings'
          )
            .to.equal(0)
        })
      })

      describe('when form explicitly enabled', function () {
        beforeEach(function () {
          this.set('disabled', false)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when form disabled', function () {
        beforeEach(function () {
          this.set('disabled', true)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when property explicitly enabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when property disabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)
        })
      })

      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {
            count: 1,
            errors: [
              {
                code: 'OBJECT_MISSING_REQUIRED_PROPERTY',
                params: ['foo'],
                message: 'Field is required.',
                path: '#/foo',
                isRequiredError: true
              }
            ]
          })
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: false
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onValidation = sandbox.spy()

            this.setProperties({
              onValidation: props.onValidation,
              showAllErrors: true
            })

            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              error: true,
              text: ''
            })

            expectBunsenInputToHaveError('foo', 'Field is required.', 'my-form')

            expect(
              props.onValidation.callCount,
              'does inform consumer of validation results'
            )
              .to.equal(1)
          })
        })
      })
    })

    describe('when initial value', function () {
      beforeEach(function () {
        this.set('value', {foo: ['bar']})

        run(() => {
          resolver.resolve([
            Ember.Object.create({
              label: 'bar',
              value: 'bar'
            }),
            Ember.Object.create({
              label: 'baz',
              value: 'baz'
            })
          ])
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'my-form')

        expect(
          this.$(selectors.bunsen.renderer.select.input),
          'renders a bunsen select input'
        )
          .to.have.length(1)

        expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
          text: 'bar'
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expectOnValidationState({props}, {count: 2})
      })

      describe('when expanded/opened', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          $hook('my-form-foo').find('.frost-select').click()
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            items: ['bar', 'baz'],
            opened: true,
            text: 'bar'
          })
        })
      })

      describe('when label defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                label: 'FooBar Baz',
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('FooBar Baz')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when collapsible is set to true in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(1, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when collapsible is set to false in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when placeholder defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                },
                placeholder: 'Foo bar'
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'Foo bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when form explicitly enabled', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          this.set('disabled', false)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when form disabled', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          this.set('disabled', true)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: 'bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when property explicitly enabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when property disabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 1})
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', false)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expectOnValidationState({props}, {count: 0})
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', true)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expectOnValidationState({props}, {count: 0})
          })
        })
      })
    })

    describe('when user types', function () {
      beforeEach(function () {
        $hook('my-form-foo').find('.frost-select').click()
        return wait().then(() => {
          $hook('my-form-foo-list-input-input').val('42').trigger('input')
          return wait()
        })
      })

      it('should make another query with the filter text', function () {
        expect(store.query).to.have.been.calledWith('node', {baz: 'alpha', filter: '[fizz]=42'})
      })
    })

    describe('when user types with selected item', function () {
      beforeEach(function () {
        run(() => {
          resolver.resolve([
            Ember.Object.create({
              label: 'bar',
              value: 'bar'
            }),
            Ember.Object.create({
              label: 'baz',
              value: 'baz'
            })
          ])
        })

        $hook('my-form-foo').find('.frost-select').click()
        $hook('my-form-foo-item', {index: 0}).trigger('mousedown')
        return wait().then(() => {
          $hook('my-form-foo-list-input-input').val('42').trigger('input')
          return wait()
        })
      })

      it('should make another query with the filter text', function () {
        expect(store.query).to.have.been.calledWith('node', {baz: 'alpha', filter: '[fizz]=42'})
      })
    })
  })

  describe('when query fails', function () {
    beforeEach(function () {
      run(() => {
        resolver.reject({
          responseJSON: {
            errors: [{
              detail: 'It done broke, son.'
            }]
          }
        })
      })

      return wait()
    })

    it('should call onError', function () {
      expect(this.get('onError').lastCall.args).to.eql(['foo', [{
        path: 'foo',
        message: 'It done broke, son.'
      }]])
    })
  })
})
Example #28
0
'use strict';

const describe = require('mocha').describe;
const it = require('mocha').it;

const expect = require('chai').expect;
const path = require('path');

const walk = require('../../../lib/index');

describe('schemes/flat/error', () => {
    it('should throw error if level is not found', done => {
        const levelpath = path.resolve('./not-existing-level');
        const options = {
            defaults: { scheme: 'flat' }
        };

        walk([levelpath], options)
            .resume()
            .on('error', err => {
                expect(err.code).to.equal('ENOENT', 'err code is wrong');
                expect(err.path).to.equal(levelpath, 'level path is wrong');
                done();
            });
    });
});
    describe('when initial value', function () {
      beforeEach(function () {
        this.set('value', {foo: ['bar']})

        run(() => {
          resolver.resolve([
            Ember.Object.create({
              label: 'bar',
              value: 'bar'
            }),
            Ember.Object.create({
              label: 'baz',
              value: 'baz'
            })
          ])
        })

        return wait()
      })

      it('renders as expected', function () {
        expectCollapsibleHandles(0, 'my-form')

        expect(
          this.$(selectors.bunsen.renderer.select.input),
          'renders a bunsen select input'
        )
          .to.have.length(1)

        expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
          text: 'bar'
        })

        expect(
          this.$(selectors.bunsen.label).text().trim(),
          'renders expected label text'
        )
          .to.equal('Foo')

        expect(
          this.$(selectors.error),
          'does not have any validation errors'
        )
          .to.have.length(0)

        expectOnValidationState({props}, {count: 2})
      })

      describe('when expanded/opened', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          $hook('my-form-foo').find('.frost-select').click()
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            items: ['bar', 'baz'],
            opened: true,
            text: 'bar'
          })
        })
      })

      describe('when label defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                label: 'FooBar Baz',
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('FooBar Baz')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when collapsible is set to true in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(1, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when collapsible is set to false in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                collapsible: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectCollapsibleHandles(0, 'my-form')

          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.bunsen.label).text().trim(),
            'renders expected label text'
          )
            .to.equal('Foo')

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when placeholder defined in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                },
                placeholder: 'Foo bar'
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'Foo bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when form explicitly enabled', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          this.set('disabled', false)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: 'bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when form disabled', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()
          this.set('disabled', true)
          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: 'bar'
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when property explicitly enabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: false,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when property disabled in view', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenView', {
            cells: [
              {
                disabled: true,
                model: 'foo',
                renderer: {
                  name: 'multi-select',
                  options: {
                    labelAttribute: 'label',
                    modelType: 'node',
                    query: {
                      baz: 'alpha'
                    },
                    valueAttribute: 'value'
                  }
                }
              }
            ],
            type: 'form',
            version: '2.0'
          })

          return wait()
        })

        it('renders as expected', function () {
          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            disabled: true,
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 0})
        })
      })

      describe('when field is required', function () {
        beforeEach(function () {
          props.onChange.reset()
          props.onValidation.reset()

          this.set('bunsenModel', {
            properties: {
              foo: {
                type: 'array',
                items: {
                  type: 'string'
                }
              }
            },
            required: ['foo'],
            type: 'object'
          })

          return wait()
        })

        it('renders as expected', function () {
          expect(
            this.$(selectors.bunsen.renderer.select.input),
            'renders a bunsen select input'
          )
            .to.have.length(1)

          expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
            text: ''
          })

          expect(
            this.$(selectors.error),
            'does not have any validation errors'
          )
            .to.have.length(0)

          expectOnValidationState({props}, {count: 1})
        })

        describe('when showAllErrors is false', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', false)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expect(
              this.$(selectors.error),
              'does not have any validation errors'
            )
              .to.have.length(0)

            expectOnValidationState({props}, {count: 0})
          })
        })

        describe('when showAllErrors is true', function () {
          beforeEach(function () {
            props.onChange.reset()
            props.onValidation.reset()
            this.set('showAllErrors', true)
            return wait()
          })

          it('renders as expected', function () {
            expect(
              this.$(selectors.bunsen.renderer.select.input),
              'renders a bunsen select input'
            )
              .to.have.length(1)

            expectSelectWithState($hook('my-form-foo').find('.frost-select'), {
              text: ''
            })

            expectOnValidationState({props}, {count: 0})
          })
        })
      })
    })
describe('DeviseAuthorizer', () => {
  let authorizer;
  let block;
  let data;

  beforeEach(function() {
    authorizer = Devise.create();
    block = sinon.spy();
  });

  describe('#authorize', function() {
    function itDoesNotAuthorizeTheRequest() {
      it('does not call the block', function() {
        authorizer.authorize(data, block);

        expect(block).to.not.have.been.called;
      });
    }

    describe('when the session data contains a non empty token and email', function() {
      beforeEach(function() {
        data = {
          token: 'secret token!',
          email: '*****@*****.**'
        };
      });

      it('calls the block with a header containing "token" and "email"', function() {
        authorizer.authorize(data, block);

        expect(block).to.have.been.calledWith('Authorization', 'Token token="secret token!", email="*****@*****.**"');
      });
    });

    describe('when custom identification and token attribute names are configured', function() {
      beforeEach(function() {
        authorizer = Devise.extend({ tokenAttributeName: 'employee_token', identificationAttributeName: 'employee_email' }).create();
      });

      describe('when the session data contains a non empty employee_token and employee_email', function() {
        beforeEach(function() {
          data = {
            'employee_token': 'secret token!',
            'employee_email': '*****@*****.**'
          };
        });

        it('calls the block with a header containing "employee_token" and "employee_email"', function() {
          authorizer.authorize(data, block);

          expect(block).to.have.been.calledWith('Authorization', 'Token employee_token="secret token!", employee_email="*****@*****.**"');
        });
      });
    });

    describe('when the session data does not contain a token', function() {
      beforeEach(function() {
        data = {
          email: '*****@*****.**'
        };
      });

      itDoesNotAuthorizeTheRequest();
    });

    describe('when the session data does not contain an email', function() {
      beforeEach(function() {
        data = {
          token: 'secret token!'
        };
      });

      itDoesNotAuthorizeTheRequest();
    });
  });
});