From 07f08e89da2a720fea54614435d9a41d9052bc71 Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 7 Aug 2024 09:25:52 -0400 Subject: [PATCH 1/4] The plugin file is always stream.php --- classes/class-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/class-plugin.php b/classes/class-plugin.php index dfa086d13..d51c7943e 100755 --- a/classes/class-plugin.php +++ b/classes/class-plugin.php @@ -258,7 +258,7 @@ private function locate_plugin() { $dir_url = trailingslashit( plugins_url( '', __DIR__ ) ); $dir_path = plugin_dir_path( __DIR__ ); $dir_basename = basename( $dir_path ); - $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php'; + $plugin_basename = trailingslashit( $dir_basename ) . 'stream.php'; return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' ); } From 24fe5fdbc964ad31ce133a855ff4168a00be862b Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 7 Aug 2024 11:39:44 -0400 Subject: [PATCH 2/4] Add Network activated / deactivated tests --- .gitignore | 1 + playwright.config.js | 8 +++-- tests/e2e/editor-new-post.spec.js | 5 +-- tests/e2e/network-activated.spec.js | 56 +++++++++++++++++++++++++++++ tests/e2e/setup/setup.js | 41 +++++++++++++++++++++ 5 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 tests/e2e/network-activated.spec.js create mode 100644 tests/e2e/setup/setup.js diff --git a/.gitignore b/.gitignore index 8a328671c..f57f65a72 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ tests/data/tmp/* /playwright-report/ /blob-report/ /playwright/.cache/ +/playwright/.auth/ diff --git a/playwright.config.js b/playwright.config.js index 50d2a193e..3fc5bc911 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -33,12 +33,16 @@ module.exports = defineConfig( { /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, - /* Configure projects for major browsers */ projects: [ + { name: 'setup', testMatch: /setup\.js/ }, { name: 'chromium', - use: { ...devices[ 'Desktop Chrome' ] }, + use: { + ...devices[ 'Desktop Chrome' ], + storageState: 'playwright/.auth/user.json', + }, + dependencies: [ 'setup' ], }, ], } ); diff --git a/tests/e2e/editor-new-post.spec.js b/tests/e2e/editor-new-post.spec.js index 4adc2bd4f..f643fd798 100644 --- a/tests/e2e/editor-new-post.spec.js +++ b/tests/e2e/editor-new-post.spec.js @@ -21,10 +21,7 @@ test.describe( 'Editor: saving a new post', () => { console.log( `New post ${ postTitle }` ); // Even though we're using WP's npm package, it's more straightforward to do it this way, at least for me in this environment. - await page.goto( 'http://stream.wpenv.net/wp-login.php?redirect_to=http://stream.wpenv.net/wp-admin/post-new.php%2F&reauth=1' ); - await page.getByLabel( 'Username or Email Address' ).fill( 'admin' ); - await page.getByLabel( 'Password', { exact: true } ).fill( 'password' ); - await page.getByRole( 'button', { name: 'Log In' } ).click(); + await page.goto( 'http://stream.wpenv.net/wp-admin/post-new.php' ); await page.getByLabel( 'Add title' ).click(); await page.getByLabel( 'Add title' ).fill( postTitle ); await page.getByLabel( 'Add title' ).press( 'Tab' ); diff --git a/tests/e2e/network-activated.spec.js b/tests/e2e/network-activated.spec.js new file mode 100644 index 000000000..18ae4af21 --- /dev/null +++ b/tests/e2e/network-activated.spec.js @@ -0,0 +1,56 @@ +/** + * WordPress dependencies + */ +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; + +let page; + +test.describe.configure( { mode: 'serial' } ); + +test.beforeAll( async ( { browser } ) => { + page = await browser.newPage(); +} ); + +test.afterAll( async () => { + await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' ); + const isActive = await page + .getByLabel( 'Network Deactivate Stream' ) + .isVisible(); + + if ( isActive ) { + // eslint-disable-next-line no-console + console.log( 'Deactivating Stream after Network tests.' ); + await page.getByLabel( 'Network Deactivate Stream' ).click(); + } +} ); + +test.describe( 'Network: shows network activated states', () => { + // Do we have a published row? + test( 'does not show stream in network admin when deactivated', async () => { + await page.goto( 'http://stream.wpenv.net/wp-admin/network/index.php' ); + // Expects Stream log to not have the Network Settings. + await expect( + page.locator( '[href*="admin.php?page=wp_stream"]' ), + ).not.toBeVisible(); + } ); + + // We should not have an updated row. This times out which makes it fail. + test( 'does not have updated row', async () => { + await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' ); + const isActive = await page + .getByLabel( 'Network Activate Stream' ) + .isVisible(); + + if ( isActive ) { + // eslint-disable-next-line no-console + console.log( 'Activating Stream for next tests.' ); + await page.getByLabel( 'Network Activate Stream' ).click(); + } + + await page.goto( 'http://stream.wpenv.net/wp-admin/network/index.php' ); + // Expects Stream log to not have the Network Settings. + await expect( + page.locator( '[href*="admin.php?page=wp_stream_network_settings"]' ), + ).toBeVisible(); + } ); +} ); diff --git a/tests/e2e/setup/setup.js b/tests/e2e/setup/setup.js new file mode 100644 index 000000000..6f1ff57ee --- /dev/null +++ b/tests/e2e/setup/setup.js @@ -0,0 +1,41 @@ +/** + * External dependencies + */ +import { test as setup } from '@playwright/test'; + +const authFile = 'playwright/.auth/user.json'; + +/** + * Log in before all the tests. + * @see https://playwright.dev/docs/auth + */ +setup( 'authenticate', async ( { page } ) => { + // Log in. + await page.goto( 'http://stream.wpenv.net/wp-login.php' ); + await page.getByLabel( 'Username or Email Address' ).fill( 'admin' ); + await page.getByLabel( 'Password', { exact: true } ).fill( 'password' ); + await page.getByRole( 'button', { name: 'Log In' } ).click(); + // Wait until the page receives the cookies. + + // Sometimes login flow sets cookies in the process of several redirects. + // Wait for the final URL to ensure that the cookies are actually set. + await page.waitForURL( 'http://stream.wpenv.net/wp-admin/' ); + + await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' ); + const isActive = await page.getByLabel( 'Network Deactivate Stream' ).isVisible(); + + // eslint-disable-next-line no-console + console.log( `Stream is currently active: ${ isActive }` ); + + if ( isActive ) { + // eslint-disable-next-line no-console + console.log( 'Deactivating Stream before tests.' ); + await page.getByLabel( 'Network Deactivate Stream' ).click(); + } + + // End of authentication steps. + await page.context().storageState( { path: authFile } ); + + // eslint-disable-next-line no-console + console.log( 'Done with network setup.' ); +} ); From 4f0dcc0e11571d773c45c1d446c47c4d08f92a30 Mon Sep 17 00:00:00 2001 From: "Mary (JJ) Jay" Date: Thu, 15 Aug 2024 10:33:04 -0400 Subject: [PATCH 3/4] Use correct variable name Co-authored-by: Piotr Delawski --- tests/e2e/network-activated.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/network-activated.spec.js b/tests/e2e/network-activated.spec.js index 18ae4af21..e963478ca 100644 --- a/tests/e2e/network-activated.spec.js +++ b/tests/e2e/network-activated.spec.js @@ -37,7 +37,7 @@ test.describe( 'Network: shows network activated states', () => { // We should not have an updated row. This times out which makes it fail. test( 'does not have updated row', async () => { await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' ); - const isActive = await page + const isInactive = await page .getByLabel( 'Network Activate Stream' ) .isVisible(); From 80a85f1ea8049adb4ad52e059dc26dfb5b65bc99 Mon Sep 17 00:00:00 2001 From: "Mary (JJ) Jay" Date: Thu, 15 Aug 2024 10:33:16 -0400 Subject: [PATCH 4/4] Use correct variable name Co-authored-by: Piotr Delawski --- tests/e2e/network-activated.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/network-activated.spec.js b/tests/e2e/network-activated.spec.js index e963478ca..c46097d62 100644 --- a/tests/e2e/network-activated.spec.js +++ b/tests/e2e/network-activated.spec.js @@ -41,7 +41,7 @@ test.describe( 'Network: shows network activated states', () => { .getByLabel( 'Network Activate Stream' ) .isVisible(); - if ( isActive ) { + if ( isInactive ) { // eslint-disable-next-line no-console console.log( 'Activating Stream for next tests.' ); await page.getByLabel( 'Network Activate Stream' ).click();