-
-
Notifications
You must be signed in to change notification settings - Fork 585
#5568 Fix kit allocation/deallocation history display direction (fixes #5568) #5628
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
Open
rodrigovirgilio
wants to merge
3
commits into
rubyforgood:main
Choose a base branch
from
rodrigovirgilio:fix/kit-allocation-history-display
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
fa2dfcf
Fix kit allocation/deallocation history display direction (fixes #5568)
rodrigovirgilio 7a22bba
Fix whitespace in event row item/quantity text (fixes #5568)
rodrigovirgilio 6fe19ca
Derive kit event direction without depending on line item order (fixe…
rodrigovirgilio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,6 +263,112 @@ | |
| expect(response.body).not_to include("99<br>") | ||
| end | ||
| end | ||
|
|
||
| context "with kit allocation and deallocation events" do | ||
| let(:component_item) { create(:item, organization: organization, name: "Widget") } | ||
| let(:kit) do | ||
| create_kit(organization: organization, line_items_attributes: [ | ||
| {item_id: component_item.id, quantity: 5} | ||
| ]) | ||
| end | ||
|
|
||
| def row_for(event_type) | ||
| Nokogiri::HTML(response.body).css("tbody tr").find do |row| | ||
| row.css("td")[1]&.text&.strip == event_type | ||
| end | ||
| end | ||
|
|
||
| before do | ||
| TestInventory.create_inventory(organization, { | ||
| storage_location.id => {component_item.id => 100} | ||
| }) | ||
| KitAllocateEvent.publish(kit, storage_location.id, 3) | ||
| KitDeallocateEvent.publish(kit, storage_location.id, 1) | ||
| end | ||
|
|
||
| it "shows a positive kit quantity to the storage location and a negative item quantity for KitAllocate" do | ||
| subject | ||
| row = row_for("KitAllocate") | ||
| expect(row).not_to be_nil | ||
| cells = row.css("td") | ||
| expect(cells[4].text).not_to include(storage_location.name) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at indexed cells can be a bit flaky as well... can we do something CSV-like where we find the index of the cell whose header is "From" and check the values that way? |
||
| expect(cells[5].text).to include(storage_location.name) | ||
| expect(cells[6].text).to include("#{kit.name}: 3") | ||
| expect(cells[6].text).to include("Widget: -15") | ||
| end | ||
|
|
||
| it "shows a positive kit quantity from the storage location and a negative item quantity for KitDeallocate" do | ||
| subject | ||
| row = row_for("KitDeallocate") | ||
| expect(row).not_to be_nil | ||
| cells = row.css("td") | ||
| expect(cells[4].text).to include(storage_location.name) | ||
| expect(cells[5].text).not_to include(storage_location.name) | ||
| expect(cells[6].text).to include("#{kit.name}: 1") | ||
| expect(cells[6].text).to include("Widget: -5") | ||
| end | ||
| end | ||
|
|
||
| context "with kit events whose line items are not in the usual order" do | ||
| # KitAllocateEvent/KitDeallocateEvent normally append the kit's own line item | ||
| # last, but the view must not depend on that ordering to work out direction. | ||
| let(:component_item) { create(:item, organization: organization, name: "Widget") } | ||
| let(:kit) do | ||
| create_kit(organization: organization, line_items_attributes: [ | ||
| {item_id: component_item.id, quantity: 5} | ||
| ]) | ||
| end | ||
|
|
||
| def row_for(event_type) | ||
| Nokogiri::HTML(response.body).css("tbody tr").find do |row| | ||
| row.css("td")[1]&.text&.strip == event_type | ||
| end | ||
| end | ||
|
|
||
| before do | ||
| TestInventory.create_inventory(organization, { | ||
| storage_location.id => {component_item.id => 100, kit.kit_item.id => 100} | ||
| }) | ||
| end | ||
|
|
||
| it "shows the correct direction for KitAllocate with the kit's line item first" do | ||
| KitAllocateEvent.create!( | ||
| eventable: kit, | ||
| organization_id: organization.id, | ||
| event_time: Time.zone.now, | ||
| data: EventTypes::InventoryPayload.new( | ||
| items: KitAllocateEvent.event_line_items(kit, storage_location.id, 2).reverse | ||
| ) | ||
| ) | ||
| subject | ||
| row = row_for("KitAllocate") | ||
| expect(row).not_to be_nil | ||
| cells = row.css("td") | ||
| expect(cells[4].text).not_to include(storage_location.name) | ||
| expect(cells[5].text).to include(storage_location.name) | ||
| expect(cells[6].text).to include("#{kit.name}: 2") | ||
| expect(cells[6].text).to include("Widget: -10") | ||
| end | ||
|
|
||
| it "shows the correct direction for KitDeallocate with the kit's line item first" do | ||
| KitDeallocateEvent.create!( | ||
| eventable: kit, | ||
| organization_id: organization.id, | ||
| event_time: Time.zone.now, | ||
| data: EventTypes::InventoryPayload.new( | ||
| items: KitDeallocateEvent.event_line_items(kit, storage_location.id, 4).reverse | ||
| ) | ||
| ) | ||
| subject | ||
| row = row_for("KitDeallocate") | ||
| expect(row).not_to be_nil | ||
| cells = row.css("td") | ||
| expect(cells[4].text).to include(storage_location.name) | ||
| expect(cells[5].text).not_to include(storage_location.name) | ||
| expect(cells[6].text).to include("#{kit.name}: 4") | ||
| expect(cells[6].text).to include("Widget: -20") | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot to go into a view file... can we extract to a helper function?