-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/autocomplete choice value removal #1
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
base: 2.3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,10 +48,10 @@ public function attachImage(string $path, ?string $type = null, ?ProductVariantI | |
| } | ||
|
|
||
| if (null !== $productVariant) { | ||
| $this->autocompleteHelper->selectByValue( | ||
| $this->autocompleteHelper->selectByName( | ||
| $this->getDriver(), | ||
| $imageSubform->find('css', '[data-test-product-variant]')->getXpath(), | ||
| $productVariant->getCode(), | ||
| $productVariant->getName(), | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -106,12 +106,30 @@ public function hasImageWithType(string $type): bool | |
| } | ||
|
|
||
| public function hasImageWithVariant(ProductVariantInterface $productVariant): bool | ||
| { | ||
| $selectedVariantName = $this->getFirstImageSelectedVariantName(); | ||
|
|
||
| if (null === $selectedVariantName) { | ||
| return false; | ||
| } | ||
|
|
||
| return str_contains($selectedVariantName, $productVariant->getName()); | ||
|
Comment on lines
+110
to
+116
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. The Suggested fix public function hasImageWithVariant(ProductVariantInterface $productVariant): bool
{
$this->changeTab();
$images = $this->getElement('images');
$imageSubforms = $images->findAll('css', '[data-test-image-subform]');
foreach ($imageSubforms as $imageSubform) {
$variantField = $imageSubform->find('css', '[data-test-product-variant]');
if (null === $variantField) {
continue;
}
$selectedOption = $variantField->find('css', 'option[selected]');
if (null === $selectedOption) {
continue;
}
if ($selectedOption->getText() === $productVariant->getName()) {
return true;
}
}
return false;
}Prompt for AI assistanceCopy the prompt below and paste it into ChatGPT, Claude, or any LLM: |
||
| } | ||
|
Comment on lines
108
to
+117
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. The Suggested fix public function hasImageWithVariant(ProductVariantInterface $productVariant): bool
{
$this->changeTab();
$images = $this->getElement('images');
$variantElements = $images->findAll('css', '[data-test-product-variant*="' . $productVariant->getName() . '"]');
return count($variantElements) > 0;
}Prompt for AI assistanceCopy the prompt below and paste it into ChatGPT, Claude, or any LLM: |
||
|
|
||
| public function getFirstImageSelectedVariantName(): ?string | ||
| { | ||
| $this->changeTab(); | ||
|
|
||
| $images = $this->getElement('images'); | ||
| $imageSubform = $this->getFirstImageSubform(); | ||
| $variantField = $imageSubform->find('css', '[data-test-product-variant]'); | ||
|
|
||
| $selectedOption = $variantField->find('css', 'option[selected]'); | ||
|
|
||
| if (null === $selectedOption) { | ||
| return null; | ||
| } | ||
|
|
||
| return $images->has('css', sprintf('[data-test-product-variant*="%s"]', $productVariant->getCode())); | ||
| return $selectedOption->getText(); | ||
| } | ||
|
|
||
| public function countImages(): int | ||
|
|
@@ -189,10 +207,10 @@ public function selectVariantForFirstImage(ProductVariantInterface $productVaria | |
| $this->changeTab(); | ||
|
|
||
| $imageSubform = $this->getFirstImageSubform(); | ||
| $this->autocompleteHelper->selectByValue( | ||
| $this->autocompleteHelper->selectByName( | ||
| $this->getDriver(), | ||
| $imageSubform->find('css', '[data-test-product-variant]')->getXpath(), | ||
| $productVariant->getCode(), | ||
| $productVariant->getName(), | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void | |
| $resolver->setDefaults([ | ||
| 'class' => $this->productAttributeClass, | ||
| 'choice_name' => 'name', | ||
|
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. The Suggested fix $resolver->setDefaults([
'class' => $this->productAttributeClass,
'choice_name' => 'name',
'choice_value' => 'code',
]);Prompt for AI assistanceCopy the prompt below and paste it into ChatGPT, Claude, or any LLM: |
||
| 'choice_value' => 'code', | ||
| ]); | ||
| } | ||
|
|
||
|
|
||
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.
The
hasImageWithVariantmethod usesstr_contains()to check if a product variant name matches the selected variant, but this performs a substring match rather than an exact match. This causes false positives where checking for variant "Small" incorrectly returns true when "Extra Small" is selected, since "Small" is a substring of "Extra Small". This leads to unreliable test assertions in image-variant validation.Prompt for AI assistance
Copy the prompt below and paste it into ChatGPT, Claude, or any LLM: