Skip to content

Commit

Permalink
Update post save button texts
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#8536, closes TryGhost/Ghost#8500

- Post save button will now display publish/un-publish/schedule/un-schedule/re-schedule/update
- On successful save button will display published/un-published/scheduled/un-scheduled/re-scheduled/updated
  • Loading branch information
cobbspur committed Jun 15, 2017
1 parent 25bfa20 commit cf93bcb
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 7 deletions.
43 changes: 40 additions & 3 deletions app/components/gh-publishmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,48 @@ export default Component.extend({
}
}),

buttonText: computed('postState', function () {
let state = this.get('postState');
buttonText: computed('postState', 'saveType', function() {
let postState = this.get('postState');
let saveType = this.get('saveType');
let buttonText;

if (postState === 'draft') {
buttonText = saveType === 'publish' ? 'Publish' : 'Schedule';
}

if (postState === 'published') {
buttonText = saveType === 'publish' ? 'Update' : 'Un-publish';
}

return state === 'draft' ? 'Publish' : 'Update';
if (postState === 'scheduled') {
buttonText = saveType === 'schedule' ? 'Re-schedule' : 'Un-schedule';
}

return buttonText || 'Publish';
}),

successText: computed('_previousStatus', 'postState', function() {
let postState = this.get('postState');
let previousStatus = this.get('_previousStatus');
let buttonText;

if (previousStatus === 'draft') {
buttonText = postState === 'published' ? 'Published' : 'Scheduled';
}

if (previousStatus === 'published') {
buttonText = postState === 'draft' ? 'Un-published' : 'Updated';
}

if (previousStatus === 'scheduled') {
buttonText = postState === 'draft' ? 'Un-scheduled' : 'Re-scheduled';
}

return buttonText;
}),

save: task(function* () {
this.set('_previousStatus', this.get('post.status'));
this.get('setSaveType')(this.get('saveType'));

try {
Expand All @@ -66,6 +101,8 @@ export default Component.extend({
}
}),

_previousStatus: null,

_cachePublishedAtBlogTZ() {
this._publishedAtBlogTZ = this.get('post.publishedAtBlogTZ');
},
Expand Down
1 change: 1 addition & 0 deletions app/templates/components/gh-publishmenu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</button>
{{gh-task-button buttonText
task=save
successText=successText
class="gh-btn gh-btn-blue gh-publishmenu-button gh-btn-icon"
data-test-publishmenu-save=true}}
</footer>
Expand Down
109 changes: 105 additions & 4 deletions tests/acceptance/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,28 @@ describe('Acceptance: Editor', function() {
'draft publish menu is shown'
).to.exist;

await click(testSelector('publishmenu-scheduled-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'draft post schedule button text'
).to.equal('Schedule');

await click(testSelector('publishmenu-published-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'draft post publish button text'
).to.equal('Publish');

// Publish the post
await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after draft is published'
).to.equal('Published');

expect(
find(testSelector('publishmenu-published')),
'publish menu is shown after draft published'
Expand All @@ -162,6 +181,15 @@ describe('Acceptance: Editor', function() {
'post status updated after draft published'
).to.equal('Published');

await click(testSelector('publishmenu-cancel'));
await click(testSelector('publishmenu-trigger'));
await click(testSelector('publishmenu-unpublished-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'published post unpublish button text'
).to.equal('Un-publish');

// post id 2 is a published post, checking for published post behaviour now
await visit('/editor/2');

Expand All @@ -175,8 +203,19 @@ describe('Acceptance: Editor', function() {
await triggerEvent(testSelector('date-time-picker-time-input'), 'blur');
// saving
await click(testSelector('publishmenu-trigger'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'published button text'
).to.equal('Update');

await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after published post is updated'
).to.equal('Updated');

// go to settings to change the timezone
await visit('/settings/general');
await click(testSelector('toggle-timezone'));
Expand Down Expand Up @@ -215,8 +254,19 @@ describe('Acceptance: Editor', function() {
// unpublish
await click(testSelector('publishmenu-trigger'));
await click(testSelector('publishmenu-unpublished-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'published post unpublish button text'
).to.equal('Un-publish');

await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after published post is unpublished'
).to.equal('Un-published');

expect(
find(testSelector('publishmenu-draft')),
'draft menu is shown after unpublished'
Expand All @@ -233,33 +283,84 @@ describe('Acceptance: Editor', function() {

let newFutureTime = moment.tz('Pacific/Kwajalein').add(10, 'minutes');
await click(testSelector('publishmenu-scheduled-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'draft post, schedule button text'
).to.equal('Schedule');

await datepickerSelect(`${testSelector('publishmenu-draft')} ${testSelector('date-time-picker-datepicker')}`, newFutureTime);
await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after draft is scheduled'
).to.equal('Scheduled');

await click(testSelector('publishmenu-cancel'));

expect(
find(testSelector('publishmenu-scheduled')),
'publish menu is not shown after closed'
).to.not.exist;

// expect countdown to show warning, that post will be published in x minutes
expect(find(testSelector('schedule-countdown')).text().trim(), 'notification countdown')
.to.contain('Post will be published in');

expect(
find(testSelector('publishmenu-trigger')).text().trim(),
'scheduled publish button text'
).to.equal('Scheduled');

expect(
find(testSelector('editor-post-status')).text().trim(),
'scheduled status text'
'scheduled post status'
).to.equal('Scheduled');

// expect countdown to show warning, that post will be published in x minutes
expect(find(testSelector('schedule-countdown')).text().trim(), 'notification countdown')
.to.contain('Post will be published in');
// Re-schedule
await click(testSelector('publishmenu-trigger'));
await click(testSelector('publishmenu-scheduled-option'));
expect(
find(testSelector('publishmenu-save')).text().trim(),
'scheduled post button reschedule text'
).to.equal('Re-schedule');

await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button text for a rescheduled post'
).to.equal('Re-scheduled');

await click(testSelector('publishmenu-cancel'));

expect(
find(testSelector('publishmenu-scheduled')),
'publish menu is not shown after closed'
).to.not.exist;

expect(
find(testSelector('editor-post-status')).text().trim(),
'scheduled status text'
).to.equal('Scheduled');

// unschedule
await click(testSelector('publishmenu-trigger'));
await click(testSelector('publishmenu-draft-option'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after scheduled post is unscheduled'
).to.equal('Un-schedule');

await click(testSelector('publishmenu-save'));

expect(
find(testSelector('publishmenu-save')).text().trim(),
'publish menu save button updated after scheduled post is unscheduled'
).to.equal('Un-scheduled');

await click(testSelector('publishmenu-cancel'));

expect(
Expand Down

0 comments on commit cf93bcb

Please sign in to comment.