Skip to content

Commit

Permalink
Merge pull request #173 from wp-graphql/feat/issue-55-prep-for-wporg
Browse files Browse the repository at this point in the history
feat: Add link to settings page
  • Loading branch information
josephfusco authored Jun 10, 2024
2 parents b36cdf4 + 43479e0 commit 1ece2db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-comics-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wpgraphql-ide": patch
---

- Add settings link to the IDE Settings tab from the WordPress settings page.
28 changes: 28 additions & 0 deletions tests/e2e/specs/plugin-settings-link.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { loginToWordPressAdmin, visitPluginsPage, wpAdminUrl } from '../utils.js';
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

export const selectors = {
pluginsMenuItem: '#menu-plugins a',
pluginSettingsLink: 'a[href*="graphql-settings#graphql_ide_settings"]',
ideSettingsTab: '#graphql_ide_settings-tab',
};

// Login to WordPress before each test
test.beforeEach( async ( { page } ) => {
await loginToWordPressAdmin( page );
} );

test( 'should navigate to plugin settings and display IDE Settings tab', async ( { page } ) => {
// Go to Plugins page
await visitPluginsPage( page );

// Click on the plugin settings link
await page.click( selectors.pluginSettingsLink );

// Correct the expected URL string
const expectedUrl = `${wpAdminUrl}/admin.php?page=graphql-settings#graphql_ide_settings`;
await expect( page ).toHaveURL( expectedUrl );

// Check that the IDE Settings tab is visible
await expect( page.locator( selectors.ideSettingsTab ) ).toBeVisible();
} );
17 changes: 17 additions & 0 deletions wpgraphql-ide.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ function sanitize_custom_graphql_ide_link_behavior( $value ) {
return 'drawer';
}

/**
* Add settings link to the plugin actions
*
* @param array<string> $links The existing action links.
* @return array<string> The modified action links.
*/
function add_settings_link( array $links ): array {
$settings_link = sprintf(
'<a href="%s">%s</a>',
esc_url( admin_url( 'admin.php?page=graphql-settings#graphql_ide_settings' ) ),
esc_html__( 'Settings', 'wpgraphql-ide' )
);
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\\add_settings_link' );

/**
* Rename and reorder the submenu items under 'GraphQL'.
*/
Expand Down

0 comments on commit 1ece2db

Please sign in to comment.