0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added extra post model state properties to debug logs

ref https://linear.app/tryghost/issue/ONC-323

- include post model state properties as well as the state name
This commit is contained in:
Kevin Ansfield 2024-09-20 09:09:01 +01:00
parent cc88757e2a
commit 64118c139e
2 changed files with 20 additions and 9 deletions

View file

@ -194,10 +194,17 @@ export default class LexicalEditorController extends Controller {
// eslint-disable-next-line ghost/ember/no-observers
@observes('post.currentState.stateName')
_pushPostState() {
const stateName = this.post?.currentState.stateName;
const post = this.post;
if (!post) {
return;
}
const {stateName, isDeleted, isDirty, isEmpty, isLoading, isLoaded, isNew, isSaving, isValid} = post.currentState;
if (stateName) {
console.log('post state changed:', stateName); // eslint-disable-line no-console
this._postStates.push(stateName);
const postState = [stateName, {isDeleted, isDirty, isEmpty, isLoading, isLoaded, isNew, isSaving, isValid}];
console.log('post state changed:', ...postState); // eslint-disable-line no-console
this._postStates.push(postState);
}
}

View file

@ -477,11 +477,15 @@ describe('Unit: Controller: lexical-editor', function () {
it('_getNotFoundErrorContext() includes all post states', async function () {
const newPost = store.createRecord('post');
controller.setPost(newPost);
controller.post = {currentState: {stateName: 'state.one'}};
controller.post = {currentState: {stateName: 'state.two'}};
expect(controller._getNotFoundErrorContext().allPostStates).to.deep.equal(
['root.loaded.created.uncommitted', 'state.one', 'state.two']
);
controller.post = {currentState: {stateName: 'state.one', isDirty: true}};
controller.post = {currentState: {stateName: 'state.two', isDirty: false}};
const allPostStates = controller._getNotFoundErrorContext().allPostStates;
const expectedStates = [
['root.loaded.created.uncommitted', {isDeleted: false, isDirty: true, isEmpty: false, isLoading: false, isLoaded: true, isNew: true, isSaving: false, isValid: true}],
['state.one', {isDeleted: undefined, isDirty: true, isEmpty: undefined, isLoading: undefined, isLoaded: undefined, isNew: undefined, isSaving: undefined, isValid: undefined}],
['state.two', {isDeleted: undefined, isDirty: false, isEmpty: undefined, isLoading: undefined, isLoaded: undefined, isNew: undefined, isSaving: undefined, isValid: undefined}]
];
expect(allPostStates).to.deep.equal(expectedStates);
});
});
});