Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
✅ write test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
dok committed Jun 21, 2019
1 parent a04fc03 commit e26d64e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/api-explorer/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,49 @@ describe('auth', () => {
expect(explorer.state('auth')).toEqual({ api_key: '123456', petstore_auth: '' });
});

it('should disable lazy render first 5 projects', () => {
const explorer = shallow(<ApiExplorer {...props} />);

const { lazyHash } = explorer.instance();
expect(lazyHash[0]).toEqual(false);
expect(lazyHash[1]).toEqual(false);
expect(lazyHash[2]).toEqual(false);
expect(lazyHash[3]).toEqual(false);
expect(lazyHash[4]).toEqual(false);
});

it('should disable lazy render middle 5 projects', () => {
// somewhere in the middle of props.docs
window.history.pushState({}, '', '/#user-createWithArray');
const explorer = shallow(<ApiExplorer {...props} />);

const instance = explorer.instance();
const slugs = instance.props.docs.map(x => x.slug);
const centerIdx = slugs.indexOf('user-createWithArray');

expect(instance.lazyHash[centerIdx - 2]).toEqual(false);
expect(instance.lazyHash[centerIdx - 1]).toEqual(false);
expect(instance.lazyHash[centerIdx]).toEqual(false);
expect(instance.lazyHash[centerIdx + 1]).toEqual(false);
expect(instance.lazyHash[centerIdx + 2]).toEqual(false);
});

it('should disable lazy render for last 5 projects', () => {
// last doc in props.docs
window.history.pushState({}, '', '/#user-username');
const explorer = shallow(<ApiExplorer {...props} />);

const instance = explorer.instance();
const slugs = instance.props.docs.map(x => x.slug);
const centerIdx = slugs.indexOf('user-username');

expect(instance.lazyHash[centerIdx - 2]).toEqual(false);
expect(instance.lazyHash[centerIdx - 1]).toEqual(false);
expect(instance.lazyHash[centerIdx]).toEqual(false);
expect(instance.lazyHash[centerIdx + 1]).toEqual(false);
expect(instance.lazyHash[centerIdx + 2]).toEqual(false);
});

it('should default to empty string', () => {
const explorer = shallow(<ApiExplorer {...props} />);

Expand Down

0 comments on commit e26d64e

Please sign in to comment.