2015-09-16 20:02:06 +03:00
|
|
|
/* jshint expr:true */
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import { describeComponent, it } from 'ember-mocha';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import Ember from 'ember';
|
2016-04-26 12:45:59 +03:00
|
|
|
import NavItem from 'ghost/models/navigation-item';
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2015-10-12 19:54:15 +03:00
|
|
|
const {run} = Ember;
|
2015-09-16 20:02:06 +03:00
|
|
|
|
|
|
|
describeComponent(
|
|
|
|
'gh-navigation',
|
2015-10-06 19:31:03 +03:00
|
|
|
'Integration: Component: gh-navigation',
|
2015-09-16 20:02:06 +03:00
|
|
|
{
|
|
|
|
integration: true
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
it('renders', function () {
|
|
|
|
this.render(hbs`{{#gh-navigation}}<div class="js-gh-blognav"><div class="gh-blognav-item"></div></div>{{/gh-navigation}}`);
|
|
|
|
expect(this.$('section.gh-view')).to.have.length(1);
|
|
|
|
expect(this.$('.ui-sortable')).to.have.length(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers reorder action', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let navItems = [];
|
|
|
|
let expectedOldIndex = -1;
|
|
|
|
let expectedNewIndex = -1;
|
2015-09-16 20:02:06 +03:00
|
|
|
|
|
|
|
navItems.pushObject(NavItem.create({label: 'First', url: '/first'}));
|
|
|
|
navItems.pushObject(NavItem.create({label: 'Second', url: '/second'}));
|
|
|
|
navItems.pushObject(NavItem.create({label: 'Third', url: '/third'}));
|
|
|
|
navItems.pushObject(NavItem.create({label: '', url: '', last: true}));
|
|
|
|
this.set('navigationItems', navItems);
|
|
|
|
this.set('blogUrl', 'http://localhost:2368');
|
|
|
|
|
|
|
|
this.on('moveItem', (oldIndex, newIndex) => {
|
|
|
|
expect(oldIndex).to.equal(expectedOldIndex);
|
|
|
|
expect(newIndex).to.equal(expectedNewIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
run(() => {
|
|
|
|
this.render(hbs `
|
|
|
|
{{#gh-navigation moveItem="moveItem"}}
|
|
|
|
<form id="settings-navigation" class="gh-blognav js-gh-blognav" novalidate="novalidate">
|
|
|
|
{{#each navigationItems as |navItem|}}
|
|
|
|
{{gh-navitem navItem=navItem baseUrl=blogUrl addItem="addItem" deleteItem="deleteItem" updateUrl="updateUrl"}}
|
|
|
|
{{/each}}
|
|
|
|
</form>
|
|
|
|
{{/gh-navigation}}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
// check it renders the nav item rows
|
|
|
|
expect(this.$('.gh-blognav-item')).to.have.length(4);
|
|
|
|
|
|
|
|
// move second item up one
|
|
|
|
expectedOldIndex = 1;
|
|
|
|
expectedNewIndex = 0;
|
2015-10-05 09:07:44 +03:00
|
|
|
run(() => {
|
|
|
|
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
|
|
|
move: -1,
|
|
|
|
handle: '.gh-blognav-grab'
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// move second item down one
|
|
|
|
expectedOldIndex = 1;
|
|
|
|
expectedNewIndex = 2;
|
2015-10-05 09:07:44 +03:00
|
|
|
run(() => {
|
|
|
|
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
|
|
|
move: 1,
|
|
|
|
handle: '.gh-blognav-grab'
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|