Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Oct 6, 2023
1 parent 7c716b0 commit 180612c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 7 additions & 5 deletions test/display-name-slug-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@ describe('<DisplayNameSlugEditor />', function() {
});

describe('component lifecycle', function() {
const getResourceUrlSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'getResourceUrl');
let getResourceUrlSpy;

const origin = 'https://www.test.com';

before(function() {
getResourceUrlSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'getResourceUrl');
wrapper = mount(<DisplayNameSlugEditor origin={origin} resource={resource} resourceType="project" />);
});

describe('componentDidMount', function() {
after(function() {
getResourceUrlSpy.reset();
getResourceUrlSpy.resetHistory();
});

it('should call getResourceUrl', function() {
Expand Down Expand Up @@ -117,9 +118,10 @@ describe('<DisplayNameSlugEditor />', function() {
let button;
const onChangeSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'handleInputChange');
const undoNameChangeSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'undoNameChange');
const warnURLChangeSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'warnURLChange');
let warnURLChangeSpy;

before(function() {
warnURLChangeSpy = sinon.spy(DisplayNameSlugEditor.prototype, 'warnURLChange');
wrapper = mount(<DisplayNameSlugEditor resource={resource} resourceType="project" />);
input = wrapper.find('input[type="text"]');
value = 'Lorem ipsum';
Expand All @@ -136,7 +138,7 @@ describe('<DisplayNameSlugEditor />', function() {
expect(warnURLChangeSpy.calledOnce).to.be.true;
expect(warnURLChangeSpy.calledWith(resource, value)).to.be.true;
expect(warnURLChangeSpy.calledAfter(onChangeSpy)).to.be.true;
warnURLChangeSpy.reset();
warnURLChangeSpy.resetHistory();
});

it('warns the user about URL changes', function() {
Expand All @@ -159,7 +161,7 @@ describe('<DisplayNameSlugEditor />', function() {
input.simulate('change', { target: { value: 'a new name' }});
expect(warnURLChangeSpy.calledOnce).to.be.true;
expect(wrapper.state().warn).to.be.false;
warnURLChangeSpy.reset();
warnURLChangeSpy.resetHistory();
});

it('does not warn the user about URL changes if the slug includes "untitled-organization"', function() {
Expand Down
26 changes: 12 additions & 14 deletions test/paginator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,56 @@ describe('Paginator', function() {

describe('with props page, pageKey and router provided', function() {
let wrapper;
const router = { push() {} };
const spy = sinon.spy(router, 'push');
const router = {
push: sinon.spy()
};

beforeEach(function() {
wrapper = mount(<Paginator page={5} pageCount={10} pageKey={'testPage'} router={router} />);
});

afterEach(function() {
spy.reset();
router.push.resetHistory();
});

it('should start on page', function() {
expect(wrapper.prop('page')).to.equal(5);
});
it('should add pageKey to param onChange', function() {
wrapper.find('#next').simulate('click');
expect(Object.keys(spy.args[0][0].query)).to.include('testPage');
expect(Object.keys(router.push.args[0][0].query)).to.include('testPage');
});
it('should go to the next page', function() {
wrapper.find('#next').simulate('click');
expect(spy.args[0][0].query.testPage).to.equal(6);
expect(router.push.args[0][0].query.testPage).to.equal(6);
});
it('should go to the last page', function() {
wrapper.find('#last').simulate('click');
expect(spy.args[0][0].query.testPage).to.equal(10);
expect(router.push.args[0][0].query.testPage).to.equal(10);
});
it('should go to the previous page', function() {
wrapper.find('#previous').simulate('click');
expect(spy.args[0][0].query.testPage).to.equal(4);
expect(router.push.args[0][0].query.testPage).to.equal(4);
});
it('should go to the first page', function() {
wrapper.find('#first').simulate('click');
expect(spy.args[0][0].query.testPage).to.equal(1);
expect(router.push.args[0][0].query.testPage).to.equal(1);
});
it('should go to a page selected', function() {
wrapper.find('select').simulate('change', { target: { value: 3 }});
expect(spy.args[0][0].query.testPage).to.equal(3);
expect(router.push.args[0][0].query.testPage).to.equal(3);
});
});

describe('with onPageChange prop provided', function() {
let wrapper;
const onPageChange = sinon.spy();
let onPageChange

beforeEach(function() {
onPageChange = sinon.spy();
wrapper = mount(<Paginator page={5} pageCount={10} onPageChange={onPageChange} />);
});

afterEach(function() {
onPageChange.reset();
});

it('should go to the next page', function() {
wrapper.find('#next').simulate('click');
expect(onPageChange.withArgs(6).calledOnce).to.equal(true);
Expand Down

0 comments on commit 180612c

Please sign in to comment.