Ghost/ghost/admin/tests/integration/components/gh-navitem-test.js

113 lines
4.2 KiB
JavaScript
Raw Normal View History

/* jshint expr:true */
import {expect} from 'chai';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {setupComponentTest} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import NavItem from 'ghost-admin/models/navigation-item';
import wait from 'ember-test-helpers/wait';
2016-11-24 01:50:57 +03:00
describe('Integration: Component: gh-navitem', function () {
setupComponentTest('gh-navitem', {
integration: true
2016-11-24 01:50:57 +03:00
});
2016-11-24 01:50:57 +03:00
beforeEach(function () {
this.set('baseUrl', 'http://localhost:2368');
});
2016-11-24 01:50:57 +03:00
it('renders', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl}}`);
let $item = this.$('.gh-blognav-item');
2016-11-24 01:50:57 +03:00
expect($item.find('.gh-blognav-grab').length).to.equal(1);
expect($item.find('.gh-blognav-label').length).to.equal(1);
expect($item.find('.gh-blognav-url').length).to.equal(1);
expect($item.find('.gh-blognav-delete').length).to.equal(1);
2016-11-24 01:50:57 +03:00
// doesn't show any errors
expect($item.hasClass('gh-blognav-item--error')).to.be.false;
expect($item.find('.error').length).to.equal(0);
expect($item.find('.response:visible').length).to.equal(0);
});
2016-11-24 01:50:57 +03:00
it('doesn\'t show drag handle for new items', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl}}`);
let $item = this.$('.gh-blognav-item');
2016-11-24 01:50:57 +03:00
expect($item.find('.gh-blognav-grab').length).to.equal(0);
});
2016-11-24 01:50:57 +03:00
it('shows add button for new items', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl}}`);
let $item = this.$('.gh-blognav-item');
2016-11-24 01:50:57 +03:00
expect($item.find('.gh-blognav-add').length).to.equal(1);
expect($item.find('.gh-blognav-delete').length).to.equal(0);
});
2016-11-24 01:50:57 +03:00
it('triggers delete action', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
2016-11-24 01:50:57 +03:00
let deleteActionCallCount = 0;
this.on('deleteItem', (navItem) => {
expect(navItem).to.equal(this.get('navItem'));
deleteActionCallCount++;
});
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl deleteItem="deleteItem"}}`);
this.$('.gh-blognav-delete').trigger('click');
2016-11-24 01:50:57 +03:00
expect(deleteActionCallCount).to.equal(1);
});
2016-11-24 01:50:57 +03:00
it('triggers add action', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
2016-11-24 01:50:57 +03:00
let addActionCallCount = 0;
this.on('add', () => {
addActionCallCount++;
});
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl addItem="add"}}`);
this.$('.gh-blognav-add').trigger('click');
2016-11-24 01:50:57 +03:00
expect(addActionCallCount).to.equal(1);
});
2016-11-24 01:50:57 +03:00
it('triggers update action', function () {
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
2016-11-24 01:50:57 +03:00
let updateActionCallCount = 0;
this.on('update', () => {
updateActionCallCount++;
});
2016-11-24 01:50:57 +03:00
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl updateUrl="update"}}`);
this.$('.gh-blognav-url input').trigger('blur');
2016-11-24 01:50:57 +03:00
expect(updateActionCallCount).to.equal(1);
});
2016-11-24 01:50:57 +03:00
it('displays inline errors', function () {
this.set('navItem', NavItem.create({label: '', url: ''}));
this.get('navItem').validate();
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl}}`);
let $item = this.$('.gh-blognav-item');
return wait().then(() => {
expect($item.hasClass('gh-blognav-item--error')).to.be.true;
expect($item.find('.gh-blognav-label').hasClass('error')).to.be.true;
expect($item.find('.gh-blognav-label .response').text().trim()).to.equal('You must specify a label');
expect($item.find('.gh-blognav-url').hasClass('error')).to.be.true;
expect($item.find('.gh-blognav-url .response').text().trim()).to.equal('You must specify a URL or relative path');
});
2016-11-24 01:50:57 +03:00
});
});