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

Superadmin Partners View (4682) & Category Dropdown Error (4674) #4703

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bdeanhardt
Copy link

@bdeanhardt bdeanhardt commented Oct 3, 2024

Resolves #4682 and #4674

Description

The super admin partners view is now in alphabetical order.
If you have an error on new item, the category list for selection will not disappear anymore.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I reopened the super admin page after implementing my changes and the partners are now in alphabetical order.
I tried to reproduce the bug after implement my bug fix and I was unable to do so (categories will show up now despite an error).
Everything else still works as expected.

Screenshots

Screenshot 2024-10-03 at 10 18 25 AM

@bdeanhardt bdeanhardt changed the title 4682 - Superadmin Partners View Superadmin Partners View (4682) & Category Dropdown Error (4674) Oct 3, 2024
@cielf
Copy link
Collaborator

cielf commented Oct 3, 2024

Hey @bdeanhardt -- Thank you! -- we'll take a look. One thing for future -- we usually put a PR for each issue we work on -- it's easier for the testers.

@cielf
Copy link
Collaborator

cielf commented Oct 4, 2024

Also for future -- it's a better practice to make a branch, rather than making the changes in your main.

@cielf
Copy link
Collaborator

cielf commented Oct 4, 2024

@bdeanhardt Could you make the order "human alphabetical" -- i.e. case insensitive, aka lower case alphabetical?, rather than "computer alphabetical", which orders all the lowercase after all the upper case, please?

(We're in the process of making the order of all the other alphabetical lists case-insensitive)

Thanks,

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hi @bdeanhardt
Welcome aboard! Thanks for your work on this!

The item fix works very well!

For the partner page, I'm afraid we had a slight misunderstanding on what we mean by alphabetical -- we want alphabetical the way English-speaking humans do it -- i.e. both 'A' and 'a' are treated the same.

We'll also need automated tests for both of these. That's what we mean when we need tests.

Please see the other procedural comments I've made, above, for future pull requests.

@cielf
Copy link
Collaborator

cielf commented Oct 9, 2024

@bdeanhardt Functionally, this looks great! -- just waiting for those automated tests, then I'll pass it over to our tech lead for a final technical review.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Can you add or modify an existing test to validate these fixes?

@bdeanhardt
Copy link
Author

Can you add or modify an existing test to validate these fixes?

tests are in! Thank you for your patience on this.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

One comment on the newly added test. Shouldn't there be one more added test since there are two issues being fixed here?

post :create, params: bad_params

expect(response).to render_template(:new)
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This statement is just restating the code itself. You need to create item categories with specific names and validate that the printed categories match those names in alphabetical order.

Copy link
Author

Choose a reason for hiding this comment

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

Should I check for the alphabetical order of the categories in both tests? Or is this OK as is now that the first test is pushed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I got confused - this test doesn't actually test the bug, which is that the categories were empty after an error. You should do this in a request test which validates the output HTML.

Copy link
Author

Choose a reason for hiding this comment

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

Ok! I uploaded a new test.

@bdeanhardt
Copy link
Author

One comment on the newly added test. Shouldn't there be one more added test since there are two issues being fixed here?

I forgot to push the other test! I'm so sorry totally my bad.


it "assigns partners ordered by name (case-insensitive)" do
get :index
expect(assigns(:partners)).to eq([partner1, partner2, partner3].sort_by { |p| p.name.downcase })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:

expect(assigns(:partners).map(&:name)).to eq(%w(alpha Bravo Zeus))

But if you really want to test this, you should swap the names of partners 1 and 2. This way the default order would not be alphabetical and you'd actually be testing that the sort works. 😄

post :create, params: bad_params

expect(response).to render_template(:new)
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I got confused - this test doesn't actually test the bug, which is that the categories were empty after an error. You should do this in a request test which validates the output HTML.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Almost there!

expect(response).to render_template(:new)

# Ensure the item categories are assigned in the controller
expect(assigns(:item_categories)).to eq(organization.item_categories.order('name ASC'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I much prefer giving the categories explicit values and testing against those values rather than pulling them from the DB. You end up basically just copying the code you're testing into the test.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I'm having trouble understanding exactly what you mean here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean doing something like

let(:categories) do 
  [
    FactoryBot.create(:item_category, name: 'Apples'),  # include whatever other IDs need to be passed in
    FactoryBot.create(:item_category, name: 'Bananas')
  ] 
end
# ...
expect(assigns(:item_categories)).to eq(categories))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @bdeanhardt -- do you need further guidance on this?

Copy link
Author

Choose a reason for hiding this comment

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

Hey @cielf! Past 2 weeks have been chaos, but I'm back! I'm taking a look today :)

@dorner
Copy link
Collaborator

dorner commented Oct 27, 2024

Lint also needs to be fixed.

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.

Superadmin partners view -- partners should be in alphabetical order (for ease of finding)
3 participants