示例#1
0
  it('spreads user props', () => {
    // JSX does not render custom html attributes so we prefix them with data-*.
    // https://facebook.github.io/react/docs/jsx-gotchas.html#custom-html-attributes
    const props = {
      [`data-${_.kebabCase(faker.hacker.noun())}`]: faker.hacker.verb(),
    }

    shallow(<Component {...requiredProps} {...props} />)
      .should.have.descendants(props)
  })
示例#2
0
    it('updates text when value changed', () => {
      const initialValue = faker.hacker.noun()
      const nextValue = faker.hacker.noun()

      wrapperMount(<Search results={options} minCharacters={0} value={initialValue} />)
        .find('.prompt')
        .should.have.value(initialValue)

      wrapper
        .setProps({ value: nextValue })
        .find('.prompt')
        .should.have.value(nextValue)
    })
示例#3
0
  it('spreads user props', () => {
    // JSX does not render custom html attributes so we prefix them with data-*.
    // https://facebook.github.io/react/docs/jsx-gotchas.html#custom-html-attributes
    const props = {
      [`data-${_.kebabCase(faker.hacker.noun())}`]: faker.hacker.verb(),
    }

    // descendants() accepts an enzyme <selector>
    // props should be spread on some descendant
    // we find the descendant with spread props via a matching props object selector
    // we do not test Component for props, of course they exist as we are spreading them
    shallow(<Component {...requiredProps} {...props} />)
      .should.have.descendants(props)
  })
    it('does not set state for non autoControlledProps', () => {
      consoleUtil.disableOnce()

      TestClass = createTestClass({ autoControlledProps: [], state: {} })
      const wrapper = shallow(<TestClass />)

      wrapper
        .instance()
        .trySetState({ [faker.hacker.noun()]: faker.hacker.verb() })

      wrapper
        .state()
        .should.be.empty()
    })
示例#5
0
  describe('shorthand', () => {
    const baseProps = {
      content: faker.hacker.phrase(),
      description: faker.hacker.phrase(),
      header: faker.hacker.phrase(),
    }

    it('renders content without wrapping ListContent', () => {
      const wrapper = shallow(<ListContent {...baseProps} />)

      wrapper.find('ListHeader').should.have.prop('content', baseProps.header)
      wrapper.find('ListDescription').should.have.prop('content', baseProps.description)
      wrapper.should.contain.text(baseProps.content)
    })
  })
    it('adds HeaderSubheader as child when there is an image', () => {
      const text = faker.hacker.phrase()

      shallow(<Header image='foo.png' subheader={text} />)
        .find('HeaderSubheader')
        .should.have.prop('content', text)
    })
    it('is passed to Checkbox controls', () => {
      const text = faker.hacker.phrase()

      shallow(<FormField control={Checkbox} label={text} />)
        .find('Checkbox')
        .should.have.prop('label', text)
    })
    it('wraps html radio inputs', () => {
      const text = faker.hacker.phrase()
      const label = shallow(<FormField control='input' label={text} type='radio' />).find('label')

      label.childAt(0).should.have.tagName('input')
      label.should.contain.text(text)
    })
示例#9
0
    it('sets the display text', () => {
      const text = faker.hacker.phrase()

      wrapperRender(<Dropdown {...requiredProps} text={text} />)
        .find('.text')
        .should.contain.text(text)
    })
    it('called when click on center', () => {
      const spy = sandbox.spy()
      const wrapper = mount(<Dimmer onClickOutside={spy}>{faker.hacker.phrase()}</Dimmer>)

      wrapper.find('div.center').simulate('click')
      spy.should.have.been.calledOnce()
    })
    it('called when click on Dimmer', () => {
      const spy = sandbox.spy()

      mount(<Dimmer onClickOutside={spy}>{faker.hacker.phrase()}</Dimmer>)
        .simulate('click')
      spy.should.have.been.calledOnce()
    })
    it('omitted when click on children', () => {
      const spy = sandbox.spy()
      const wrapper = mount(<Dimmer onClickOutside={spy}><div>{faker.hacker.phrase()}</div></Dimmer>)

      wrapper.find('div.center').childAt(0).simulate('click')
      spy.should.have.been.callCount(0)
    })
示例#13
0
export const implementsIconProp = (Component, requiredProps = {}) => {
  const iconName = faker.hacker.noun()
  const assertValid = (element) => {
    const wrapper = shallow(element)
    wrapper
      .should.have.descendants('Icon')
    wrapper
      .find('Icon')
      .should.have.prop('name', iconName)
  }

  describe('icon (common)', () => {
    _noDefaultClassNameFromProp(Component, 'icon')

    it('has no i when not defined', () => {
      shallow(<Component />)
        .should.not.have.descendants('i')
    })

    it('accepts an Icon instance', () => {
      const icon = <Icon name={iconName} />
      assertValid(<Component icon={icon} />)
    })

    it('accepts an icon name string', () => {
      assertValid(<Component icon={iconName} />)
    })
  })
}
  describe('renders children', () => {
    const firstText = faker.hacker.phrase()
    const secondText = faker.hacker.phrase()

    it('with `items` prop', () => {
      const items = [
        { header: firstText },
        { header: secondText },
      ]

      const wrapper = mount(<CardGroup items={items} />).find('Card')

      wrapper.first().find('CardHeader').should.contain.text(firstText)
      wrapper.last().find('CardHeader').should.contain.text(secondText)
    })
  })
    it('is passed to Radio controls', () => {
      const text = faker.hacker.phrase()

      shallow(<FormField control={Radio} label={text} />)
        .find('Radio')
        .should.have.prop('label', text)
    })
示例#16
0
    _.times(randInt(100, 150), function (i) { // random requests
       models.Request.create({
         title: faker.hacker.phrase(),
         body: faker.lorem.paragraphs(randInt(1, 4)),
         offer: randRoundInt(100, 10000),
         createdAt: randDate()
       }).then(function (request) {
         myModels.requests.push(request);
         request.setUser(randFromObj(myModels.user)).then(function (model) {
           request.setTags(randTags(myModels.tags)).then(function (model) {
             request.setComments(randComments(myModels.comments)).then(function (model) {
               var proposals = randProposals(myModels.proposals);
               request.setProposals(proposals).then(function (model) {
                 // give each proposal a user
                 _.each(proposals, function (proposal) {
                   randFromObj(myModels.user).addProposal(proposal);
                 });
                 // 33% chance of accepting one proposal
                 if (proposals.length && randInt(0, 100) % 3 === 0) {
                   proposals[0].set('state', 1).save();
                 }
               });
             });
           });
         });

       });
     });
示例#17
0
文件: Comment.js 项目: tanglx61/db
exports.populate = function(opts, callback) {
	console.time('populateComments');

	var c = opts.count;
	var count = (c && Number(c))  || DEFAULT_COMMENT_COUNT;

	console.info('populating ' + count + ' Comments...');
	bar.init(count);

	var comments = [];


	for (var i=0; i<count; i++) {
		comments.push({
			content: faker.hacker.phrase(),
			uid: faker.random.number({min:1, max:config.users}),
			pid: faker.random.number({min:1, max:config.posts}),
			ts: String.format("(NOW() - '{0} seconds'::INTERVAL)", faker.random.number({min:0, max:864000}))
		});
	}


	async.eachSeries(comments, function(comment, next){
		bar.tick();
		create({db: opts.db, comment: comment}, next);
	}, function(err){
		console.timeEnd('populateComments');
		if (callback) callback(err);
	});
};	
    it('does not set state for props passed as null by the parent', () => {
      consoleUtil.disableOnce()

      const props = makeProps()
      const autoControlledProps = _.keys(props)

      const randomProp = _.sample(autoControlledProps)
      const randomValue = faker.hacker.phrase()

      props[randomProp] = null

      TestClass = createTestClass({ autoControlledProps, state: {} })
      const wrapper = shallow(<TestClass {...props } />)

      wrapper
        .instance()
        .trySetState({ [randomProp]: randomValue })

      // not updated
      wrapper
        .should.not.have.state(randomProp, randomValue)

      // is original value
      wrapper
        .should.have.state(randomProp, props[randomProp])
    })
示例#19
0
    it('passes prop to StepContent', () => {
      const title = faker.hacker.phrase()

      shallow(<Step title={title} />)
        .find('StepContent')
        .should.have.prop('title', title)
    })
示例#20
0
var interval = setInterval(function () {
  room.message(faker.hacker.phrase());
  if (++i > repeats) {
    clearInterval(interval);
    room.leave();
  }
}, 10000);
示例#21
0
    it('passes prop to StepContent', () => {
      const description = faker.hacker.phrase()

      shallow(<Step description={description} />)
        .find('StepContent')
        .should.have.prop('description', description)
    })
示例#22
0
    it('sets the display text', () => {
      const text = faker.hacker.phrase()

      wrapperRender(<Dropdown options={options} selection text={text} />)
        .find('.text')
        .should.contain.text(text)
    })
示例#23
0
const buildFolder = function buildFolder (foldersCollection, paentFolderId) {
  const doc = {
    name: faker.hacker.noun(),
    parent: paentFolderId,
    created: new Date().toString()
  }
  return foldersCollection.create(doc)
}
示例#24
0
module.exports.newStageComment = (stageId, userId, cb) => {
    StagesComments.create({
        stageId: mongoose.Types.ObjectId(stageId),
        text: faker.hacker.phrase(),
        userId: mongoose.Types.ObjectId(userId)
    })
        .then(() => cb());
};
示例#25
0
module.exports.newQuestComment = (questId, userId, cb) => {
    QuestsComments.create({
        questId: mongoose.Types.ObjectId(questId),
        text: faker.hacker.phrase(),
        userId: mongoose.Types.ObjectId(userId)
    })
        .then(() => cb());
};
    it('is sibling to text inputs', () => {
      const text = faker.hacker.phrase()
      const wrapper = shallow(<FormField control='input' label={text} type='text' />)

      wrapper.childAt(0).should.have.tagName('label')
      wrapper.childAt(0).should.contain.text(text)
      wrapper.childAt(1).should.have.tagName('input')
    })
示例#27
0
    it('does not add prop value to className', () => {
      // silence propType warnings
      consoleUtil.disableOnce()

      const value = faker.hacker.noun()
      shallow(createElement(Component, { ...requiredProps, [propKey]: value }))
        .should.not.have.className(value)
    })
 it('... and updates the custom fields requested in \'_updateCustomFields\'', (done) => {
     var customField = faker.hacker.noun();
     data.customField = customField;
     vm.updateFromData(data)
         .always(function() {
             assert.equal(vm.customField(), customField);
             done();
         });
 });
示例#29
0
const buildFile = function buildFile (parentFolderId, filesColleciton) {
  const doc = {
    name: faker.hacker.noun(),
    folder: parentFolderId,
    created: new Date().toString(),
    url: faker.image.imageUrl()
  }
  return filesColleciton.create(doc)
}
示例#30
0
    const categoryOptions = _.range(0, categoryLength).reduce((memo, index) => {
      const category = `${faker.hacker.noun()}-${index}`

      memo[category] = {
        name: category,
        results: getOptions(categoryResultsLength),
      }

      return memo
    }, {})