Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new team editor - button and modal only #3495

Merged
merged 13 commits into from
Aug 12, 2024

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Aug 5, 2024

What is the feature?
Add user in editor: https://trello.com/c/piMcGsJa/2973-add-user-in-editor

What does this PR add?
These changes are UI only!

  • adds a button onto the members table that opens a modal.
  • The modal does nothing at the moment - both buttons just close the modal.
  • The button is hidden behind a feature flag: 'ADD_NEW_EDITOR'

Screenshots:

Button:
Screenshot 2024-08-07 at 11 43 24

Modal:
Screenshot 2024-08-07 at 11 43 40

Copy link

github-actions bot commented Aug 5, 2024

Removed vultr server and associated DNS entries

@jamdelion jamdelion changed the title feat: Add new team editor - button only feat: Add new team editor - button and modal only Aug 6, 2024
package.json Outdated Show resolved Hide resolved
@jamdelion jamdelion marked this pull request as ready for review August 7, 2024 10:59
@jamdelion jamdelion requested a review from a team August 7, 2024 10:59
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Looks good! A couple minor questions, no blockers to merging.

Thanks for clear to-do's and tests, exciting to see this feature taking shape 🙌

editor.planx.uk/src/lib/featureFlags.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

Fantastic PR - super clear and easy to follow, great level of explanation in the PR description and nice small atomic changes - love it 👍

One very small comment on tests to take a look at please!

package.json Outdated Show resolved Hide resolved
@@ -0,0 +1,33 @@
/* eslint-disable jest/expect-expect */
import { fireEvent, screen, within } from "@testing-library/react";
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Daf, I am using the setup API but extracted into a helper for reusability - see helpers/setupTeamMembersScreen.tsx.

Or I have I misunderstood your comment? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry - that wasn't a very clear comment in hindsight.

What we would be aiming for is for setupTeamMembersScreen() to return the user generated by setup() so that we can call user.click() as opposed to fireEvent.click() in our tests here 👍

setup() returns Record<"user", UserEvent> & RenderResult so we can access all the values from there, e.g. getByTestId, findByLabelText instead of importing screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, thanks for explaining!

I've updated to be able to get user from setup (and thus got rid of fireEvent but is there a particular reason why we prefer use getBy... functions from here rather than from screen?

I had a go at getting everything from setup but in my opinion it made the tests a lot more unwieldy due to having to initialise the variables globally (rendered) and not being able to destructure them so nicely.

I also think it made it make less sense to have a helper called setupTeamMembersScreen obscuring some of the methods that were exposed. I ended up with this which I don't think is as nice:

describe("when a user with the ADD_NEW_EDITOR feature flag enabled presses 'add a new editor'", () => {
  let rendered: Record<"user", UserEvent> & RenderResult

  beforeEach(async () => {
    rendered = setup(
      <DndProvider backend={HTML5Backend}>
        <TeamMembers teamMembersByRole={exampleTeamMembersData} />
      </DndProvider>
    );
    await rendered.findByText("Team editors"); 
    const teamEditorsTable = rendered.getByTestId("team-editors");
    const addEditorButton = await within(teamEditorsTable).findByText(
      "Add a new editor"
    );
    rendered.user.click(addEditorButton);
  });
  it("opens the modal and displays the input fields", async () => {
    expect(await rendered.findByTestId("modal-create-user-button")).toBeVisible();
    expect(await rendered.findByLabelText("First name")).toBeVisible();
  });
});

In the example you linked, screen is used as well as user so hopefully the way it is left now is acceptable 😅 Super interested in talking through the thought processes behind the current code conventions though so let me know if you'd like a chat!

@jamdelion jamdelion requested a review from DafyddLlyr August 8, 2024 15:32
@jessicamcinchak
Copy link
Member

✅ Tests are passing here & I don't want syntax/setup chat to block other dependent PRs, so I've "dismissed the requested changes" from Daf here just so you aren't blocked from merging this one for a couple days until he's back !

Let's pick back up the testing conversation later this week and can always come back for a light refactor for consistency if we decide 👌

@jessicamcinchak jessicamcinchak dismissed DafyddLlyr’s stale review August 12, 2024 07:09

Let's revisit test setup syntax when you're back later this week!

@jamdelion jamdelion merged commit 51031bf into main Aug 12, 2024
12 checks passed
@jamdelion jamdelion deleted the jh/add-team-editor-button branch October 28, 2024 16:44
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.

3 participants