Fixed editor tests

refs fb5e083ce9

- fixed linting errors
- fixed automatic clearing of invalid publish date when PSM is closed
  - previously the PSM was always rendered so it had a `showSettingsMenu` argument that told it whether it was being shown
  - automatic error clearing was tied to `showSettingsMenu` so it was switched to `willDestroyElement` because now the menu is re-rendered each time it's shown
- fixed tests
  - tests assumed the menu was always rendered so they were manipulating inputs even though they weren't visible on screen
This commit is contained in:
Kevin Ansfield 2021-07-02 19:57:58 +01:00
parent fb5e083ce9
commit 986e1174dd
5 changed files with 24 additions and 41 deletions

View File

@ -3,7 +3,6 @@ import {
IMAGE_EXTENSIONS,
IMAGE_MIME_TYPES
} from 'ghost-admin/components/gh-image-uploader';
import {debounce, run} from '@ember/runloop';
import {inject as service} from '@ember/service';
export default Component.extend({

View File

@ -55,7 +55,7 @@
@timeErrorProperty="publishedAtBlogTime"
@maxDate="now"
@disabled={{this.post.isScheduled}}
@isActive={{and this.showSettingsMenu (not this.isViewingSubview)}}
@isActive={{not this.isViewingSubview}}
/>
{{#unless (or this.post.isDraft this.post.isPublished this.post.pastScheduledTime)}}
<p>Use the publish menu to re-schedule</p>

View File

@ -22,8 +22,7 @@ export default Component.extend({
post: null,
showSettingsMenu: false,
_showSettingsMenu: false,
isViewingSubview: false,
canonicalUrlScratch: alias('post.canonicalUrlScratch'),
customExcerptScratch: alias('post.customExcerptScratch'),
@ -69,38 +68,16 @@ export default Component.extend({
return urlParts.join(' > ');
}),
isViewingSubview: computed('showSettingsMenu', {
get() {
return false;
},
set(key, value) {
// Not viewing a subview if we can't even see the PSM
if (!this.showSettingsMenu) {
return false;
}
return value;
}
}),
didReceiveAttrs() {
this._super(...arguments);
// fired when menu is closed
if (!this.showSettingsMenu && this._showSettingsMenu) {
let post = this.post;
let errors = post.get('errors');
// reset the publish date if it has an error
if (errors.has('publishedAtBlogDate') || errors.has('publishedAtBlogTime')) {
post.set('publishedAtBlogTZ', post.get('publishedAtUTC'));
post.validate({attribute: 'publishedAtBlog'});
}
}
this._showSettingsMenu = this.showSettingsMenu;
},
willDestroyElement() {
let post = this.post;
let errors = post.get('errors');
// reset the publish date if it has an error
if (errors.has('publishedAtBlogDate') || errors.has('publishedAtBlogTime')) {
post.set('publishedAtBlogTZ', post.get('publishedAtUTC'));
post.validate({attribute: 'publishedAtBlog'});
}
this.setSidebarWidthVariable(0);
},

View File

@ -101,7 +101,6 @@
{{#if this.showSettingsMenu}}
<GhPostSettingsMenu
@post={{this.post}}
@showSettingsMenu={{this.showSettingsMenu}}
@toggleEmailPreviewModal={{action "toggleEmailPreviewModal"}}
@deletePost={{action "toggleDeletePostModal"}}
@updateSlugTask={{this.updateSlugTask}}
@ -110,7 +109,7 @@
{{/if}}
</div>
<button type="button" class="settings-menu-toggle gh-btn gh-btn-editor gh-btn-icon only-has-icon gh-actions-cog" title="Settings" data-test-button="psm-toggle" {{on "click" this.toggleSettingsMenu}} data-test-psm-trigger>
<button type="button" class="settings-menu-toggle gh-btn gh-btn-editor gh-btn-icon only-has-icon gh-actions-cog" title="Settings" {{on "click" this.toggleSettingsMenu}} data-test-psm-trigger>
{{#if this.showSettingsMenu}}
<span class="settings-menu-open">{{svg-jar "sidemenu-open"}}</span>
{{else}}

View File

@ -148,7 +148,7 @@ describe('Acceptance: Editor', function () {
.to.equal('Must be in the past');
// closing the PSM will reset the invalid date/time
await click('[data-test-close-settings-menu]');
await click('[data-test-psm-trigger]');
await click('[data-test-psm-trigger]');
expect(
@ -173,7 +173,7 @@ describe('Acceptance: Editor', function () {
await datepickerSelect('[data-test-date-time-picker-datepicker]', validTime.toDate());
// hide psm
await click('[data-test-close-settings-menu]');
await click('[data-test-psm-trigger]');
// checking the flow of the saving button for a draft
expect(
@ -237,8 +237,9 @@ describe('Acceptance: Editor', function () {
// post id 2 is a published post, checking for published post behaviour now
await visit('/editor/post/2');
expect(currentURL(), 'currentURL').to.equal('/editor/post/2');
await click('[data-test-psm-trigger]');
expect(find('[data-test-date-time-picker-date-input]').value).to.equal('2015-12-19');
expect(find('[data-test-date-time-picker-time-input]').value).to.equal('16:25');
@ -246,6 +247,9 @@ describe('Acceptance: Editor', function () {
await datepickerSelect('[data-test-date-time-picker-datepicker]', moment('2016-05-10 10:00').toDate());
await fillIn('[data-test-date-time-picker-time-input]', '10:00');
await blur('[data-test-date-time-picker-time-input]');
await click('[data-test-psm-trigger]');
// saving
await click('[data-test-publishmenu-trigger]');
@ -286,6 +290,7 @@ describe('Acceptance: Editor', function () {
expect(currentURL(), 'currentURL in editor')
.to.equal('/editor/post/2');
await click('[data-test-psm-trigger]');
expect(
find('[data-test-date-time-picker-date-input]').value,
'date after timezone change'
@ -534,6 +539,9 @@ describe('Acceptance: Editor', function () {
expect(currentURL(), 'currentURL')
.to.equal('/editor/post/1');
await click('[data-test-psm-trigger]');
expect(find('[data-test-date-time-picker-date-input]').value, 'scheduled date')
.to.equal(compareDateString);
expect(find('[data-test-date-time-picker-time-input]').value, 'scheduled time')
@ -558,7 +566,7 @@ describe('Acceptance: Editor', function () {
expect(currentURL(), 'currentURL')
.to.equal('/editor/post/1');
await click('[data-test-button="psm-toggle"]');
await click('[data-test-psm-trigger]');
let tokens = findAll('[data-test-input="authors"] .ember-power-select-multiple-option');