Skip to content

MERL-1004: fixed missing edit button in the Faust toolbar when previewing a post#1556

Merged
TeresaGobble merged 17 commits into
canaryfrom
MERL-1004-edit-button-in-toolbar-added-to-preview-node
Sep 1, 2023
Merged

MERL-1004: fixed missing edit button in the Faust toolbar when previewing a post#1556
TeresaGobble merged 17 commits into
canaryfrom
MERL-1004-edit-button-in-toolbar-added-to-preview-node

Conversation

@TeresaGobble

@TeresaGobble TeresaGobble commented Aug 29, 2023

Copy link
Copy Markdown
Contributor

Tasks

  • I have signed a Contributor License Agreement (CLA) with WP Engine.
  • If a code change, I have written testing instructions that the whole team & outside contributors can understand.
  • I have written and included a comprehensive changeset to properly document the changes I've made.

Description

This PR addresses the missing edit button in the Faust toolbar when previewing a post.
Ticket: https://wpengine.atlassian.net/jira/software/c/projects/MERL/boards/1007?modal=detail&selectedIssue=MERL-1004

Closes #1515

Testing

Before testing:
Enable the experimental toolbar in your test site- see Customizing the Toolbar - Faust.js™ for instructions.
Enable public route redirects in WordPress:
wp-admin → settings → faust → Enable public route redirects ✅

Testing:
Start your test site after switching to this branch.
go to wp-admin and create a new post. Add content, and then click on the laptop icon on the upper righthand side of the editor. Go to Preview in new tab.
image

Note the edit button present in the Faust toolbar.

image

Co-authored-by: Joe Fusco <josephfusco@users.noreply.github.com>
Co-authored-by: Blake Wilson <blake@blake.id>
@TeresaGobble TeresaGobble requested a review from a team as a code owner August 29, 2023 20:00
@changeset-bot

changeset-bot Bot commented Aug 29, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9ecee4e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@faustwp/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 29, 2023

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @faustwp/getting-started-example

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 242.63 KB (🟡 +36 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@TeresaGobble TeresaGobble changed the title Added preview typeName query to edit functionality MERL-1004: Added preview typeName query to edit functionality Aug 30, 2023
Comment thread packages/faustwp-core/src/components/Toolbar/nodes/Edit.tsx Outdated
@TeresaGobble TeresaGobble changed the title MERL-1004: Added preview typeName query to edit functionality MERL-1004: fixed missing edit button in the Faust toolbar when previewing a post Aug 30, 2023
Comment thread .changeset/funny-starfishes-melt.md Outdated
@mindctrl

Copy link
Copy Markdown
Contributor

This is working well for me in Chrome. Noted internally that it does not work in Safari, but seems to be related to existing auth/cookie issue in Safari, and not a blocker for merge here.

Would be nice to have some tests to confirm the Edit node appears as expected to avoid regressions.

Co-authored-by: John Parris <john.parris@wpengine.com>
@blakewilson

blakewilson commented Aug 31, 2023

Copy link
Copy Markdown
Contributor

For the tests that are failing, this seems due to our introduction of useRouter, we'll have to mock it. @TeresaGobble you could do something like this:

Do a wildcard import of next/router:

import * as nextRouter from 'next/router';

Then in the Toolbar tests that are failing, mock the useRouter call:

  const useRouterSpy = jest.spyOn(nextRouter, 'useRouter').mockReturnValue({
    query: {},
  } as any as nextRouter.NextRouter);

For example:

test('renders the toolbar if user preference is true', async () => {
  expect.assertions(1);
  mockIsAuthenticated = true;

  const mockUseQuery = {
    data: {
      viewer: {
        shouldShowFaustToolbar: true,
      },
    },
  } as any as QueryResult<unknown, unknown>;

  const useQuerySpy = jest
    .spyOn(apollo, 'useQuery')
    .mockReturnValue(mockUseQuery);

  const useRouterSpy = jest.spyOn(nextRouter, 'useRouter').mockReturnValue({
    query: {},
  } as any as nextRouter.NextRouter);

  const dom = render(<Toolbar />);

  const navElement = await waitFor(() =>
    queryByAttribute('id', dom.container, 'wpadminbar'),
  );

  expect(navElement).toBeInTheDocument();
});

+1 to @mindctrl's point about adding another test to avoid regressions. We could mock certain values from the useRouter to do that:

  const useRouterSpy = jest.spyOn(nextRouter, 'useRouter').mockReturnValue({
    query: {
      p: '123',
      typeName: 'Post'
    },
  } as any as nextRouter.NextRouter);

@TeresaGobble

Copy link
Copy Markdown
Contributor Author

This is working well for me in Chrome. Noted internally that it does not work in Safari, but seems to be related to existing auth/cookie issue in Safari, and not a blocker for merge here.

Would be nice to have some tests to confirm the Edit node appears as expected to avoid regressions.

Thank you John! Still working on getting the tests to pass here for the packages on Node.js 16 and 18- the logic has changed a bit with this implementation. 👍

@TeresaGobble

TeresaGobble commented Aug 31, 2023

Copy link
Copy Markdown
Contributor Author

Hi @blakewilson and @mindctrl ! Thank you so much for reviewing this for me!

My test packages for Node.js 16 and 18 failed upon adding our regression tests for the Edit Post Node in previews. I've confirmed that they're passing locally, but in our GitHub actions the test is receiving one assertion call instead of two, and expects 3 items but receives 4. I've dug around but can't seem to find an explanation for the discrepancy. Maybe something is unexpected about the way GitHub is handling expect.assertions(number) in this scenario? I've also rerun the failed checks, no change.

@theodesp

theodesp commented Sep 1, 2023

Copy link
Copy Markdown
Member

Hi @blakewilson and @mindctrl ! Thank you so much for reviewing this for me!

My test packages for Node.js 16 and 18 failed upon adding our regression tests for the Edit Post Node in previews. I've confirmed that they're passing locally, but in our GitHub actions the test is receiving one assertion call instead of two, and expects 3 items but receives 4. I've dug around but can't seem to find an explanation for the discrepancy. Maybe something is unexpected about the way GitHub is handling expect.assertions(number) in this scenario? I've also rerun the failed checks, no change.

It might be that the assertions fail because of the missing FAUST_SECRET_KEY:

https://github.com/wpengine/faustjs/actions/runs/6041182270/job/16393924705?pr=1556#step:6:513

@blakewilson blakewilson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @TeresaGobble! Thanks for adding regression tests as well.

@TeresaGobble TeresaGobble merged commit cf887d3 into canary Sep 1, 2023
@TeresaGobble TeresaGobble deleted the MERL-1004-edit-button-in-toolbar-added-to-preview-node branch September 1, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: "Edit Post" node in the toolbar not working when previewing posts

4 participants