Skip to content

Implement onClick for the add/remove model buttons in the model editor#2982

Merged
robertbrignull merged 4 commits intomainfrom
robertbrignull/add-remove-models
Oct 17, 2023
Merged

Implement onClick for the add/remove model buttons in the model editor#2982
robertbrignull merged 4 commits intomainfrom
robertbrignull/add-remove-models

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

Hooks up the actual onClick handler for the add/remove model buttons.

Also adds tests. I couldn't think of any more edge cases to test, but if there are some please let me know and I'll add tests for those.

(While testing, I did spot one bug where the method modeling panel didn't update perfectly. I'll open a separate PR for this.)

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

Copy link
Copy Markdown
Member

@koesie10 koesie10 left a comment

Choose a reason for hiding this comment

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

I think the tests will need to be changed since re-rendering won't happen automatically, but the code itself looks good.

Comment on lines +131 to +137
modeledMethods
.slice(0, modeledMethods.length - 1)
.map((_, index) => () => {
const newModeledMethods = [...modeledMethods];
newModeledMethods.splice(index, 1);
onChange(method.signature, newModeledMethods);
}),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we make this slightly easier to read by removing the modeledMethods.slice(0, modeledMethods.length - 1) call? It doesn't seem like it would make a huge difference since we wouldn't be using that handler anyway, but I think it would be easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's fine. Technically we don't need that final handler, but I agree the code is a little cleaner if we just create it anyway. I'm fine with that.


await userEvent.click(screen.getByLabelText("Add new model"));

const kindInputs = screen.getAllByRole("combobox", { name: "Model type" });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't work because the view won't get re-rendered after calling onChange. I think a more useful test here would be to check that onChange gets called with the correct values. Then, you can use the onChange values to re-render and check that there are 2 kind inputs. See for example this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I also came to the same conclusion. I've just got all the tests working using the onChange handler.

@robertbrignull robertbrignull merged commit 8d5574e into main Oct 17, 2023
@robertbrignull robertbrignull deleted the robertbrignull/add-remove-models branch October 17, 2023 09:29
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.

2 participants