Ghost/ghost/admin/tests/acceptance/restore-post-test.js
Steve Larson c121149ca3
Added posts restore UI (#21096)
ref https://app.incident.io/ghost/incidents/107
ref cc88757e2a
- added new path in admin `/restore`
- added basic ui for restoring posts from local storage
- added limits for # of revisions for posts with an `id` (5 revisions)

This commit adds a simple UI for restoring posts in case of data loss.
This is a backstop for very rare situations in which it seems Ember gets
into a conflicted state. See ref'd commit for more info. Clicking
'Restore' will create a new post with the saved off content.
2024-09-24 15:01:17 +00:00

49 lines
2.2 KiB
JavaScript

import {authenticateSession} from 'ember-simple-auth/test-support';
import {beforeEach, describe, it} from 'mocha';
import {click} from '@ember/test-helpers';
import {expect} from 'chai';
import {find, visit} from '@ember/test-helpers';
import {setupApplicationTest} from 'ember-mocha';
import {setupMirage} from 'ember-cli-mirage/test-support';
describe('Acceptance: Restore', function () {
let hooks = setupApplicationTest();
setupMirage(hooks);
beforeEach(async function () {
// Create a user and authenticate the session
let role = this.server.create('role', {name: 'Owner'});
this.server.create('user', {roles: [role], slug: 'owner'});
await authenticateSession();
});
it('restores a post from a revision', async function () {
// Create a post revision in localStorage
const revisionData = {
id: 'test-id',
title: 'Test Post',
lexical: '{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Test content","type":"extended-text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}',
revisionTimestamp: Date.now()
};
const revisionKey = `post-revision-${revisionData.id}-${revisionData.revisionTimestamp}`;
localStorage.setItem(revisionKey, JSON.stringify(revisionData));
localStorage.setItem('ghost-revisions', JSON.stringify([revisionKey]));
// Visit the restore route
await visit(`/restore/`);
// Verify that the post title is displayed
const postTitle = find('[data-test-id="restore-post-title"]').textContent.trim();
expect(postTitle).to.equal('Test Post');
// Verify that the restore button is present
const restoreButton = find('[data-test-id="restore-post-button"]');
expect(restoreButton).to.exist;
// Click the restore button
await click(restoreButton);
// Verify that the post is restored (notification will show)
expect(find('.gh-notification-title').textContent.trim()).to.equal('Post restored successfully');
});
});