wpengine / atlas-content-modeler

Content modeling plugin for WordPress
https://developers.wpengine.com/docs/atlas-content-modeler
GNU General Public License v2.0
165 stars 13 forks source link

Do not show list of entries when browser loses and regains focus unless necessary #683

Closed mindctrl closed 8 months ago

mindctrl commented 8 months ago

Description

Fixes an issue where a list of entries was shown on relationship fields when the browser tab lost and regained focus.

Fixes #627

Also adds the changelog to readme.txt from 0.26.0, as it was accidentally omitted in that release.

Checklist

I have:

Testing

See testing instructions in #627. Reproduce the issue in the main branch before checking out this branch.

Note: when checking out this repo/branch, you'll need to run npm ci and npm run start. Edit: related to conversation below, you can delete Parcel's cache with rm -rf .parcel-cache/

Automated tests should continue to work as expected.

Note: The e2e tests are flaky in Circle. You can run them locally with Docker and make test-e2e. If you want to limit the e2e tests to specific tests instead of running the whole suite, you can do this:

TEST=PublishModelCest:I_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type make test-e2e

See development docs for more info on running tests locally https://github.com/wpengine/atlas-content-modeler/blob/main/docs/DEVELOPMENT.md#running-a-single-end-to-end-acceptance-test

mindctrl commented 8 months ago

The one-off test failures are unrelated.

First failure was:

1) CreateRelationshipFieldEntryCest: I_cannot_choose_an_entry_on_the_reverse_side_that_is_linked_to_another_entry
 Test  tests/acceptance/CreateRelationshipFieldEntryCest.php:i_cannot_choose_an_entry_on_the_reverse_side_that_is_linked_to_another_entry
 Step  Click "(descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()]"
 Fail  Link or Button or CSS or XPath element with (descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()] was not found.

Second failure was a different one:

1) PublishModelCest: I_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type
 Test  tests/acceptance/PublishModelCest.php:i_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type
 Step  Click "(descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()]"
 Fail  Link or Button or CSS or XPath element with (descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()] was not found.

These pass locally.

First one:

CreateRelationshipFieldEntryCest: I_cannot_choose_an_entry_on_the_reverse_side_that_is_linked_to_another_entry
Signature: CreateRelationshipFieldEntryCest:i_cannot_choose_an_entry_on_the_reverse_side_that_is_linked_to_another_entry
Test: tests/acceptance/CreateRelationshipFieldEntryCest.php:i_cannot_choose_an_entry_on_the_reverse_side_that_is_linked_to_another_entry
Scenario --
  Dump file URL [localhost:8080] replaced with [localhost]
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["admin_email_lifespan",2533080438,"yes"]
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["_transient_doing_cron",1705506270,"yes"]
 I maximize window 
 I login as admin 
  Trying to login, attempt 0/5...
  [GET] http://localhost:8080/wp-login.php
  Cookies matching pattern /^wordpress_[a-z0-9]{32}$/ : {"wordpress_37d007a56d816107ce5b52c10342db37": "admin%7C1705678531%7CZ47G1yoSGCiKUZLBf8PHCswtgKBJY1ExL1qbNhB8M0m%7Cad21318782b7a89fd4cca1f6355996a5756b7923ba003204d402c8435db56d27"}
  Cookies matching pattern /^wordpress_logged_in_[a-z0-9]{32}$/ : {"wordpress_logged_in_37d007a56d816107ce5b52c10342db37": "admin%7C1705678531%7CZ47G1yoSGCiKUZLBf8PHCswtgKBJY1ExL1qbNhB8M0m%7Ce961f87e3a69edcc42f71baaeba0acf60eb200326d4c7b0100b9bb2fa2689f29"}
 I have content model "Right","Rights"
   I grab option from database "atlas_content_modeler_post_types"
  [Query] SELECT option_value FROM `wp_options` WHERE `option_name` = ? 
  [Parameters] ["atlas_content_modeler_post_types"]
   I have option in database "atlas_content_modeler_post_types",{"right":{"show_in_rest":true,"show_in_graphql":true,"slug":"right","api_visibility":"private",...}
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["atlas_content_modeler_post_types","a:1:{s:5:"right";a:9:{s:12:"show_in_rest";b:1;s:15:"show_in_graphql";b:1;s:4:"slug";s:5:"right";s:14:"api_visibility";s:7:"private";s:10:"model_icon";s:20:"dashicons-admin-post";s:11:"description";s:0:"";s:6:"fields";a:0:{}s:8:"singular";s:5:"Right";s:6:"plural";s:6:"Rights";}}","yes"]
 I have content model "Left","Lefts"
   I grab option from database "atlas_content_modeler_post_types"
  [Query] SELECT option_value FROM `wp_options` WHERE `option_name` = ? 
  [Parameters] ["atlas_content_modeler_post_types"]
   I have option in database "atlas_content_modeler_post_types",{"right":{"show_in_rest":true,"show_in_graphql":true,"slug":"right","api_visibility":"private",...}
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["atlas_content_modeler_post_types","a:2:{s:5:"right";a:9:{s:12:"show_in_rest";b:1;s:15:"show_in_graphql";b:1;s:4:"slug";s:5:"right";s:14:"api_visibility";s:7:"private";s:10:"model_icon";s:20:"dashicons-admin-post";s:11:"description";s:0:"";s:6:"fields";a:0:{}s:8:"singular";s:5:"Right";s:6:"plural";s:6:"Rights";}s:4:"left";a:9:{s:12:"show_in_rest";b:1;s:15:"show_in_graphql";b:1;s:4:"slug";s:4:"left";s:14:"api_visibility";s:7:"private";s:10:"model_icon";s:20:"dashicons-admin-post";s:11:"description";s:0:"";s:6:"fields";a:0:{}s:8:"singular";s:4:"Left";s:6:"plural";s:5:"Lefts";}}","yes"]
 I am on wp engine edit content model page "left"
   I am on page "/wp-admin/admin.php?page=atlas-content-modeler&view=edit-model&id=left"
  [GET] http://localhost:8080/wp-admin/admin.php?page=atlas-content-modeler&view=edit-model&id=left
 I wait for element ".field-buttons"
 I click "Relationship",".field-buttons"
 I wait 1
 I fill field {"name":"name"},"Rights One To One"
 I select option "#reference","Rights"
 I click "input#one-to-one"
 I click "#enable-reverse"
 I wait 1
 I see "Reverse Display Name"
 I fill field {"name":"reverseName"},"Lefts One To One"
 I click "button[data-testid="edit-model-update-create-button"]"
 I wait 1
 I click "(descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()]"
 I click "Relationship",".field-buttons"
 I wait 1
 I fill field {"name":"name"},"Rights Many To One"
 I select option "#reference","Rights"
 I click "input#many-to-one"
 I click "#enable-reverse"
 I wait 1
 I see "Reverse Display Name"
 I fill field {"name":"reverseName"},"Lefts One To Many"
 I click "button[data-testid="edit-model-update-create-button"]"
 I wait 1
 I am on page "/wp-admin/post-new.php?post_type=right"
  [GET] http://localhost:8080/wp-admin/post-new.php?post_type=right
 I click "Publish","#publishing-action"
 I wait 2
 I am on page "/wp-admin/post-new.php?post_type=left"
  [GET] http://localhost:8080/wp-admin/post-new.php?post_type=left
 I click "Publish","#publishing-action"
 I wait 2
 I am on page "/wp-admin/post-new.php?post_type=left"
  [GET] http://localhost:8080/wp-admin/post-new.php?post_type=left
 I click "Publish","#publishing-action"
 I wait 2
 I am on page "/wp-admin/post-new.php?post_type=right"
  [GET] http://localhost:8080/wp-admin/post-new.php?post_type=right
 I click "#atlas-content-modeler[right][rightsOneToOne]"
 I wait for element visible "td.checkbox input"
 I click "(descendant-or-self::td[@class and contains(concat(' ', normalize-space(@class), ' '), ' checkbox ')]/descendant-or-self::*/input)[position()=1]"
 I click "button[data-testid="relationship-modal-save-button"]"
 I wait 1
 I click "#atlas-content-modeler[right][rightsManyToOne]"
 I wait for element visible "td.checkbox input"
 I click "(descendant-or-self::td[@class and contains(concat(' ', normalize-space(@class), ' '), ' checkbox ')]/descendant-or-self::*/input)[position()=1]"
 I click "(descendant-or-self::td[@class and contains(concat(' ', normalize-space(@class), ' '), ' checkbox ')]/descendant-or-self::*/input)[position()=2]"
 I click "button[data-testid="relationship-modal-save-button"]"
 I wait 1
 I click "Publish","#publishing-action"
 I wait 2
 I am on page "/wp-admin/post-new.php?post_type=right"
  [GET] http://localhost:8080/wp-admin/post-new.php?post_type=right
 I click "#atlas-content-modeler[right][rightsOneToOne]"
 I wait for element visible ".unselectable button"
 I move mouse over ".unselectable button"
 I wait for element visible ".tooltip-text"
 I see "is already linked",".tooltip-text"
 I see number of elements ".unselectable button",1
 I click "button[data-testid="relationship-modal-cancel-button"]"
 I click "#atlas-content-modeler[right][rightsManyToOne]"
 I wait for element visible ".unselectable button"
 I move mouse over ".unselectable button"
 I wait for element visible ".tooltip-text"
 I see "is already linked",".tooltip-text"
 I see number of elements ".unselectable button",2
 PASSED 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [RunProcess] Stopping chromedriver --url-base=/wd/hub --whitelisted-ips=

Time: 26.53 seconds, Memory: 14.00 MB

OK (1 test, 6 assertions)

Second one:

PublishModelCest: I_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type
Signature: PublishModelCest:i_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type
Test: tests/acceptance/PublishModelCest.php:i_see_submission_errors_in_number_fields_when_input_is_more_than_max_for_the_number_type
Scenario --
  Dump file URL [localhost:8080] replaced with [localhost]
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["admin_email_lifespan",2533080438,"yes"]
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["_transient_doing_cron",1705506480,"yes"]
 I resize window 1024,1024
 I maximize window 
 I login as admin 
  Trying to login, attempt 0/5...
  [GET] http://localhost:8080/wp-login.php
  Cookies matching pattern /^wordpress_[a-z0-9]{32}$/ : {"wordpress_37d007a56d816107ce5b52c10342db37": "admin%7C1705678741%7CB08ZMCTa0sy4KyKScDWPb3kdvo9xRJ47eTVzvD1i43f%7C4c58185ee32fe243f4652a28d4e4d78ddff4e1a0e08bc999cd9e01fd2dc25d86"}
  Cookies matching pattern /^wordpress_logged_in_[a-z0-9]{32}$/ : {"wordpress_logged_in_37d007a56d816107ce5b52c10342db37": "admin%7C1705678741%7CB08ZMCTa0sy4KyKScDWPb3kdvo9xRJ47eTVzvD1i43f%7C18dc57c49477d8116206515c9a4ac485bd85a92928be80289c44e0c92f605913"}
 I have content model "goose","geese",{"description":"Geese go honk"}
   I grab option from database "atlas_content_modeler_post_types"
  [Query] SELECT option_value FROM `wp_options` WHERE `option_name` = ? 
  [Parameters] ["atlas_content_modeler_post_types"]
   I have option in database "atlas_content_modeler_post_types",{"goose":{"show_in_rest":true,"show_in_graphql":true,"slug":"goose","api_visibility":"private",...}
  [Query] INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES (?, ?, ?)
  [Parameters] ["atlas_content_modeler_post_types","a:1:{s:5:"goose";a:9:{s:12:"show_in_rest";b:1;s:15:"show_in_graphql";b:1;s:4:"slug";s:5:"goose";s:14:"api_visibility";s:7:"private";s:10:"model_icon";s:20:"dashicons-admin-post";s:11:"description";s:13:"Geese go honk";s:6:"fields";a:0:{}s:8:"singular";s:5:"goose";s:6:"plural";s:5:"geese";}}","yes"]
 I am on wp engine edit content model page "goose"
   I am on page "/wp-admin/admin.php?page=atlas-content-modeler&view=edit-model&id=goose"
  [GET] http://localhost:8080/wp-admin/admin.php?page=atlas-content-modeler&view=edit-model&id=goose
 I click "Number",".field-buttons"
 I fill field {"name":"name"},"Integer"
 I click "button[data-testid="edit-model-update-create-settings-button"]"
 I fill field {"name":"minValue"},"0"
 I fill field {"name":"maxValue"},"10"
 I fill field {"name":"step"},"1"
 I click "button[data-testid="model-advanced-settings-done-button"]"
 I wait 1
 I click "button[data-testid="edit-model-update-create-button"]"
 I wait 1
 I click "(descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' add-item ')])[position()=last()]"
 I click "Number",".field-buttons"
 I fill field {"name":"name"},"Decimal"
 I click "input#decimal"
 I click "button[data-testid="edit-model-update-create-settings-button"]"
 I fill field {"name":"minValue"},"0"
 I fill field {"name":"maxValue"},"2.5"
 I fill field {"name":"step"},"1.1"
 I click "button[data-testid="model-advanced-settings-done-button"]"
 I click "button[data-testid="edit-model-update-create-button"]"
 I wait 1
 I am on page "/wp-admin/edit.php?post_type=goose"
  [GET] http://localhost:8080/wp-admin/edit.php?post_type=goose
 I click "Add New",".wrap"
 I wait 1
 I fill field {"name":"atlas-content-modeler[goose][integer]"},"20"
 I fill field {"name":"atlas-content-modeler[goose][decimal]"},"20"
 I scroll to "#submitdiv"
 I click "Publish","#publishing-action"
 I wait 2
 I see "Maximum value is","#field-integer"
 I see "Maximum value is","#field-decimal"
 I wait 1
 I see in field "atlas-content-modeler[goose][integer]","20"
 I see in field "atlas-content-modeler[goose][decimal]","20"
 PASSED 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [RunProcess] Stopping chromedriver --url-base=/wd/hub --whitelisted-ips=

Time: 14.49 seconds, Memory: 14.00 MB

OK (1 test, 4 assertions)
blakewilson commented 8 months ago

If I understand the testing steps correctly, it looks like this is still occurring for me:

https://github.com/wpengine/atlas-content-modeler/assets/5946219/a5a374a8-eb74-4517-883e-c9317077887e

Here is a screen recording using the latest of this PR. I am still seeing no entries on a fresh load, and then refocusing the window populates the proper relationship items.

EDIT: Cleared parcel-cache and now it's working as expected 🎉