-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Run the E2E tests as a user with the author role #11359
Conversation
@@ -94,7 +94,7 @@ describe( 'Change detection', () => { | |||
// Toggle post as sticky (not persisted for autosave). | |||
await ensureSidebarOpened(); | |||
|
|||
const postStickyToggleButton = ( await page.$x( "//label[contains(text(), 'Stick to the Front Page')]" ) )[ 0 ]; | |||
const postStickyToggleButton = ( await page.$x( "//label[contains(text(), 'Pending Review')]" ) )[ 0 ]; |
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.
Authors can mark things needing review, they can't stick things to the front page. The effect in the test is the same.
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.
If I'm reading correctly, the E2E tests can still be run by a non-author, in which case the label would not have the changed effect here. Should this be made more generic? Lookup element by its class? A helper utility which returns the button accounting for role?
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.
As far as I can see, no matter what your user role, clicking "Pending Review" marks the post as dirty, and that's what's getting tested here.
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.
Oh, I think I misunderstood the reason for the change. It’s just changing it to an option which is visible for both admins and authors.
@@ -60,12 +62,12 @@ describe( 'templates', () => { | |||
const STANDARD_FORMAT_VALUE = '0'; | |||
|
|||
async function setPostFormat( format ) { | |||
await switchToAdminUser(); |
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.
Switching user will not actually do anything if we're running as the admin user. We'll only switch if we're running as a different user, because the author role cannot manage plugins.
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.
That's good to know; could you leave a comment explaining that in the code? 😄
@@ -116,6 +116,12 @@ function observeConsoleLogging() { | |||
return; | |||
} | |||
|
|||
// Viewing posts on the front end can result in this error, which | |||
// has nothing to do with Gutenberg. | |||
if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) { |
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 seems to be a jQuery thing that happens on the front end, and we sometimes would get hit by it, but sometimes the test assertions would complete quickly enough for it not to make the test fail.
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.
Is there an issue anywhere that tracks that? I don't quite follow.
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.
I'm not sure what causes it yet, it seems to be unrelated to Gutenberg, and happens when you view the published post on the front end. I'll investigate further after this merge.
@@ -94,7 +94,7 @@ describe( 'Change detection', () => { | |||
// Toggle post as sticky (not persisted for autosave). | |||
await ensureSidebarOpened(); | |||
|
|||
const postStickyToggleButton = ( await page.$x( "//label[contains(text(), 'Stick to the Front Page')]" ) )[ 0 ]; | |||
const postStickyToggleButton = ( await page.$x( "//label[contains(text(), 'Pending Review')]" ) )[ 0 ]; |
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.
If I'm reading correctly, the E2E tests can still be run by a non-author, in which case the label would not have the changed effect here. Should this be made more generic? Lookup element by its class? A helper utility which returns the button accounting for role?
@@ -94,8 +94,8 @@ describe( 'Change detection', () => { | |||
// Toggle post as sticky (not persisted for autosave). |
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.
We're no longer toggling as sticky.
Not sure what's going on here, I've merged master but the test still fails for authors when it passes on my local branch. |
66cd0f1
to
bd386ab
Compare
So this is all working correctly now, and is catching an actual bug. To recreate: Set up a brand new WP install. Seems that the Latest Posts block is doing something with category information, and requesting |
@notnownikki This is probably a similar bug to the one fixed in #11395, we should use |
@aduth I think I addressed your points here, and this would be good to get in because it caught a real bug. @youknowriad Change to the Latest Posts block is included here now. |
this.toggleDisplayPostDate = this.toggleDisplayPostDate.bind( this ); | ||
} | ||
|
||
componentWillMount() { | ||
apiFetch( { | ||
path: addQueryArgs( `/wp/v2/categories`, CATEGORIES_LIST_QUERY ), |
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.
Doesn't this need to iterate the entire list? What if I have 102 categories?
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 just how it was in the original code, I was just fixing it so that it didn't break for authors
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.
Ok. I'll mention on #10873 and we can resolve with that.
path: addQueryArgs( `/wp/v2/categories`, CATEGORIES_LIST_QUERY ), | ||
} ).then( | ||
( categoriesList ) => { | ||
this.setState( { categoriesList } ); |
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.
What if the block is removed at this point, we should guard against it
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.
Added an abort call when the component unmounts, same as the hierarchical term selector.
@@ -56,6 +56,10 @@ class LatestPostsEdit extends Component { | |||
); | |||
} | |||
|
|||
componentWillUnmount() { | |||
invoke( this.fetchRequest, [ 'abort' ] ); |
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.
Do we support "abort" in apiFetch requests?
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.
if we don't, then the hierarchical term selector is wrong too.
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.
I don't think we do :). I think we did at some point in apiRequest because we were relying on jQuery but it's not the case anymore AFAIK.
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.
Yup, no abort! Ok, I'll do the this.isStillMounted
thing instead. Can we fix the term selector in another PR? I'm keen to get this in with as few changes as possible so authors get tested asap
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 looks good to me and is a solid improvement.
I left a few comments and I'm not sure if other comments are resolved (they aren't marked as such automatically by GitHub, so I've flagged @aduth for another review). Never mind, I think maybe I had this tab left open and missed the feedback being addressed.
I think this is a solid improvement though, cheers!
@@ -67,5 +67,9 @@ jobs: | |||
- stage: test | |||
env: WP_VERSION=latest | |||
script: | |||
- npm install || exit 1 |
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.
I presume this is run by Travis and thus not needed?
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.
It's run as part of the e2e tests. It didn't used to be, but now it is.
@@ -7,5 +7,8 @@ cd "$(dirname "$0")/../" | |||
# Setup local environement | |||
( ./bin/setup-local-env.sh ) | |||
|
|||
# Run the tests | |||
npm run test-e2e | |||
if [ "$E2E_ROLE" = "author" ]; then |
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.
Seems like the role we want to use could be passed to the script rather than hardcoding an "author-or-admin" choice, but if you want to do that as a follow-up it's fine with me 😄
(It would also let you avoid the if/else here, and instead just pass the role we want, with "admin" being the default. 🤷♂️)
this.isStillMounted = true; | ||
this.fetchRequest = apiFetch( { | ||
path: addQueryArgs( `/wp/v2/categories`, CATEGORIES_LIST_QUERY ), | ||
} ).then( |
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.
What happens if this request fails? We don't use catch
here...
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.
Added a catch
which sets the list to an empty list.
@@ -60,12 +62,12 @@ describe( 'templates', () => { | |||
const STANDARD_FORMAT_VALUE = '0'; | |||
|
|||
async function setPostFormat( format ) { | |||
await switchToAdminUser(); |
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.
That's good to know; could you leave a comment explaining that in the code? 😄
test/e2e/specs/templates.test.js
Outdated
@@ -93,9 +97,13 @@ describe( 'templates', () => { | |||
} ); | |||
|
|||
it( 'should not populate new page with default block for format', async () => { | |||
// This test always needs to run as the admin user. |
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.
Could you explain why it needs to run as the admin user?
@@ -116,6 +116,12 @@ function observeConsoleLogging() { | |||
return; | |||
} | |||
|
|||
// Viewing posts on the front end can result in this error, which | |||
// has nothing to do with Gutenberg. | |||
if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) { |
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.
Is there an issue anywhere that tracks that? I don't quite follow.
Description
Adds support for
E2E_ROLE
env var which allows the e2e tests to run as a user with theauthor
role.It adds a dummy
favicon.ico
so that we don't (sometimes) error on the 404 when looking at front end posts, and ignoresnet::ERR_UNKNOWN_URL_SCHEME
console message which we also (sometimes) get when viewing a front end post.The code that deals with plugins switches to the admin user, and back to the test user after the plugin operations are done.
How has this been tested?
Both e2e tests should pass.
At the moment, they require #11395 because the fail is catching that bug.
Types of changes
Checklist: