2016-05-24 15:06:59 +03:00
|
|
|
import NavItem from 'ghost-admin/models/navigation-item';
|
2017-05-29 21:50:03 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2019-05-13 17:18:41 +03:00
|
|
|
import {click, find, render, triggerEvent} from '@ember/test-helpers';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupRenderingTest} from 'ember-mocha';
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
describe('Integration: Component: settings/navigation/nav-item', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
this.set('baseUrl', 'http://localhost:2368');
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} />`);
|
2019-05-13 17:18:41 +03:00
|
|
|
let item = find('.gh-blognav-item');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2022-12-08 20:04:20 +03:00
|
|
|
expect(item.querySelector('.gh-blognav-grab'), 'grab').to.exist;
|
|
|
|
expect(item.querySelector('.gh-blognav-label'), 'label').to.exist;
|
|
|
|
expect(item.querySelector('.gh-blognav-url'), 'url').to.exist;
|
|
|
|
expect(item.querySelector('.gh-blognav-delete'), 'delete').to.exist;
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
// doesn't show any errors
|
2019-05-13 17:18:41 +03:00
|
|
|
expect(find('.gh-blognav-item--error')).to.not.exist;
|
|
|
|
expect(find('.error')).to.not.exist;
|
|
|
|
expect(find('.response')).to.not.be.displayed;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('doesn\'t show drag handle for new items', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} />`);
|
2019-05-13 17:18:41 +03:00
|
|
|
let item = find('.gh-blognav-item');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-05-13 17:18:41 +03:00
|
|
|
expect(item.querySelector('.gh-blognav-grab')).to.not.exist;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('shows add button for new items', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} />`);
|
2019-05-13 17:18:41 +03:00
|
|
|
let item = find('.gh-blognav-item');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-05-13 17:18:41 +03:00
|
|
|
expect(item.querySelector('.gh-blognav-add')).to.exist;
|
|
|
|
expect(item.querySelector('.gh-blognav-delete')).to.not.exist;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers delete action', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let deleteActionCallCount = 0;
|
2019-01-02 12:58:55 +03:00
|
|
|
this.set('deleteItem', (navItem) => {
|
2022-01-21 22:25:47 +03:00
|
|
|
expect(navItem).to.equal(this.navItem);
|
2018-01-05 18:38:23 +03:00
|
|
|
deleteActionCallCount += 1;
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} @deleteItem={{this.deleteItem}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
await click('.gh-blognav-delete');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(deleteActionCallCount).to.equal(1);
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers add action', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url', isNew: true}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let addActionCallCount = 0;
|
2019-01-02 12:58:55 +03:00
|
|
|
this.set('add', () => {
|
2018-01-05 18:38:23 +03:00
|
|
|
addActionCallCount += 1;
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} @addItem={{this.add}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
await click('.gh-blognav-add');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(addActionCallCount).to.equal(1);
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers update url action', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let updateActionCallCount = 0;
|
2019-01-02 12:58:55 +03:00
|
|
|
this.set('update', (value) => {
|
2018-01-05 18:38:23 +03:00
|
|
|
updateActionCallCount += 1;
|
2019-01-02 12:58:55 +03:00
|
|
|
return value;
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} @updateUrl={{this.update}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
await triggerEvent('.gh-blognav-url input', 'blur');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(updateActionCallCount).to.equal(1);
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers update label action', async function () {
|
2017-10-31 18:27:25 +03:00
|
|
|
this.set('navItem', NavItem.create({label: 'Test', url: '/url'}));
|
|
|
|
|
|
|
|
let updateActionCallCount = 0;
|
2019-01-02 12:58:55 +03:00
|
|
|
this.set('update', (value) => {
|
2018-01-05 18:38:23 +03:00
|
|
|
updateActionCallCount += 1;
|
2019-01-02 12:58:55 +03:00
|
|
|
return value;
|
2017-10-31 18:27:25 +03:00
|
|
|
});
|
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} @updateLabel={{this.update}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
await triggerEvent('.gh-blognav-label input', 'blur');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2020-07-07 10:54:00 +03:00
|
|
|
expect(updateActionCallCount).to.equal(2);
|
2017-10-31 18:27:25 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('displays inline errors', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('navItem', NavItem.create({label: '', url: ''}));
|
2022-01-21 22:25:47 +03:00
|
|
|
this.navItem.validate();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2022-10-07 19:42:52 +03:00
|
|
|
await render(hbs`<Settings::Navigation::NavItem @navItem={{this.navItem}} @baseUrl={{this.baseUrl}} />`);
|
2019-05-13 17:18:41 +03:00
|
|
|
let item = find('.gh-blognav-item');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-05-13 17:18:41 +03:00
|
|
|
expect(item).to.have.class('gh-blognav-item--error');
|
|
|
|
expect(item.querySelector('.gh-blognav-label')).to.have.class('error');
|
|
|
|
expect(item.querySelector('.gh-blognav-label .response')).to.have.trimmed.text('You must specify a label');
|
|
|
|
expect(item.querySelector('.gh-blognav-url')).to.have.class('error');
|
|
|
|
expect(item.querySelector('.gh-blognav-url .response')).to.have.trimmed.text('You must specify a URL or relative path');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|