Fix code quality issues and improve test framework

This commit is contained in:
2025-04-21 21:23:23 +01:00
parent ed160ed51b
commit 051bc763f8
11 changed files with 155 additions and 75 deletions

View File

@@ -2,42 +2,46 @@ describe('WordPress Multisite Tests', () => {
it('Can access the main site', () => {
cy.visit('/');
cy.get('body').should('exist');
cy.get('h1').should('exist');
cy.title().should('include', 'WordPress');
});
it('Can access the test subsite', () => {
cy.visit('/testsite');
cy.get('body').should('exist');
cy.get('h1').should('exist');
cy.title().should('include', 'Test Site');
});
it('Can login to the admin area', () => {
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.get('body.wp-admin').should('exist');
cy.loginAsAdmin();
cy.get('#wpadminbar').should('exist');
cy.get('#dashboard-widgets').should('exist');
});
it('Can access network admin', () => {
// Login first
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.loginAsAdmin();
// Go to network admin
cy.visit('/wp-admin/network/');
cy.get('body.network-admin').should('exist');
});
it('Plugin is network activated', () => {
// Login first
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.loginAsAdmin();
// Check plugins page
cy.visit('/wp-admin/network/plugins.php');
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Network Active');
});
it('Network settings page loads correctly', () => {
cy.loginAsAdmin();
// Navigate to the network settings page (if it exists)
cy.visit('/wp-admin/network/settings.php');
// This is a basic check for the network settings page
cy.get('h1').should('contain', 'Network Settings');
});
});

View File

@@ -5,22 +5,26 @@ describe('WordPress Single Site Tests', () => {
});
it('Can login to the admin area', () => {
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.get('body.wp-admin').should('exist');
cy.loginAsAdmin();
cy.get('#wpadminbar').should('exist');
cy.get('#dashboard-widgets').should('exist');
});
it('Plugin is activated', () => {
// Login first
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.loginAsAdmin();
// Check plugins page
cy.visit('/wp-admin/plugins.php');
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Deactivate');
});
it('Plugin settings page loads correctly', () => {
cy.loginAsAdmin();
// Navigate to the plugin settings page (if it exists)
cy.visit('/wp-admin/options-general.php?page=wp-plugin-starter-template');
// This is a basic check - adjust based on your actual plugin's settings page
cy.get('h1').should('contain', 'WP Plugin Starter Template');
});
});

View File

@@ -0,0 +1,20 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
/**
* Custom command to login as admin
*/
Cypress.Commands.add('loginAsAdmin', () => {
cy.visit('/wp-admin');
cy.get('#user_login').type('admin');
cy.get('#user_pass').type('password');
cy.get('#wp-submit').click();
cy.get('body.wp-admin').should('exist');
});

17
cypress/support/e2e.js Normal file
View File

@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';