Skip to content

Commit

Permalink
Merge pull request #179 from markjaquith/modernize-stopgap
Browse files Browse the repository at this point in the history
Modernize (stopgap)
  • Loading branch information
markjaquith authored Mar 26, 2024
2 parents 28bd334 + 2d675a6 commit 6a90698
Show file tree
Hide file tree
Showing 22 changed files with 5,748 additions and 7,139 deletions.
3 changes: 2 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ node_modules
/vendor
/composer.json
/composer.lock
/.vscode
/.vscode
/.pretterrc
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.16.3
lts/hydrogen
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"useTabs": true,
"trailingComma": "es5"
}
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function cleanUpReleaseFiles() {
'src/**',
];

return files.map(file => `release/svn/${file}`);
return files.map((file) => `release/svn/${file}`);
}

module.exports = grunt => {
module.exports = (grunt) => {
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand Down
2 changes: 1 addition & 1 deletion classes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CWS_PageLinksTo {
const DISMISSED_NOTICES = 'page_links_dismissed_options';
const MESSAGE_ID = 4;
const NEWSLETTER_URL = 'https://pages.convertkit.com/8eb23c1339/1ce4614706';
const CSS_JS_VERSION = '3.3.6';
const CSS_JS_VERSION = '3.3.7';

/**
* Whether to replace WP links with their specified URLs.
Expand Down
8 changes: 8 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
baseUrl: 'https://plugins.test',
testIsolation: false, // TODO: Remove this line when tests can run isolated.
},
})
3 changes: 0 additions & 3 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import faker from 'faker';
import { faker } from '@faker-js/faker';

const postTitle = () => {
const parts = [faker.lorem.word(), faker.lorem.word(), faker.random.number()];
const parts = [faker.lorem.word(), faker.lorem.word(), faker.number.int()];

return parts.join(' ');
};
Expand Down Expand Up @@ -30,7 +30,7 @@ const clickWordPress = () => {
};

const openPanel = () => {
cy.get('@panel').then($panel => {
cy.get('@panel').then(($panel) => {
if (!$panel.hasClass('is-opened')) {
cy.wrap($panel).click();
}
Expand All @@ -39,17 +39,11 @@ const openPanel = () => {

const assertWordPress = () => {
it('normal WordPress URL is selected', () => {
selectors
.chooseWordPress()
.should('be.visible')
.and('be.checked');
selectors.chooseWordPress().should('be.visible').and('be.checked');
});

it('custom URL is not selected', () => {
selectors
.chooseCustom()
.should('be.visible')
.and('not.be.checked');
selectors.chooseCustom().should('be.visible').and('not.be.checked');
});

it('custom URL UI is not visible', () => {
Expand All @@ -60,17 +54,11 @@ const assertWordPress = () => {

const assertCustom = () => {
it('custom URL is selected', () => {
selectors
.chooseCustom()
.should('be.visible')
.and('be.checked');
selectors.chooseCustom().should('be.visible').and('be.checked');
});

it('normal WordPress URL is not selected', () => {
selectors
.chooseWordPress()
.should('be.visible')
.and('not.be.checked');
selectors.chooseWordPress().should('be.visible').and('not.be.checked');
});

it('custom URL UI is visible', () => {
Expand All @@ -83,7 +71,6 @@ const save = () => {
selectors.saveButton().click();
selectors.savedNotice().should('be.visible');
cy.reload();
cy.get('button[aria-label="Close dialog"]').click({ force: true });
openPanel();
};

Expand All @@ -94,9 +81,6 @@ describe('Block Editor', () => {

before(() => {
cy.login();
Cypress.Cookies.defaults({
preserve: () => true,
});
cy.deactivatePlugin('classic-editor');
cy.visit('/wp-admin/post-new.php?post_type=page');
cy.url().should('contain', '/wp-admin/post-new.php?post_type=page');
Expand Down Expand Up @@ -151,10 +135,7 @@ describe('Block Editor', () => {
context('url', () => {
it('persists through changing link type', () => {
clickCustom();
selectors
.url()
.clear()
.type(linkedUrl);
selectors.url().clear().type(linkedUrl);
clickWordPress();
clickCustom();
selectors.url().should('have.value', linkedUrl);
Expand Down Expand Up @@ -190,7 +171,7 @@ describe('Block Editor', () => {
url: `/${draftSlug}/`,
followRedirect: false,
failOnStatusCode: false,
}).then(resp => {
}).then((resp) => {
expect(resp.status).to.eq(301);
expect(resp.redirectedToUrl).to.eq(linkedUrl);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import faker from 'faker';
import { faker } from '@faker-js/faker';

const postTitle = () => {
const parts = [faker.lorem.word(), faker.lorem.word(), faker.random.number()];
const parts = [faker.lorem.word(), faker.lorem.word(), faker.number.int()];

return parts.join(' ');
};
Expand All @@ -14,7 +14,6 @@ describe('Classic Editor', () => {

before(() => {
cy.login();
cy.keepAllCookies();
cy.enablePrettyPermalinks();
cy.activatePlugin('classic-editor');
cy.visit('/wp-admin/post-new.php?post_type=page');
Expand Down Expand Up @@ -65,59 +64,44 @@ describe('Classic Editor', () => {

it('shows hidden fields when custom link option enabled', () => {
cy.scrollTo('bottom');
cy.get('@chooseCustom')
.click()
.should('be.checked');
cy.get('@chooseCustom').click().should('be.checked');
cy.get('@chooseWp').should('not.be.checked');
cy.get('@url').should('be.visible');
cy.focused().should('have.attr', 'id', 'cws-links-to');
cy.get('@newTab').should('not.be.checked');
});

it('hides fields when custom link option is disabled', () => {
cy.get('@chooseWp')
.click()
.should('be.checked');
cy.get('@chooseWp').click().should('be.checked');
cy.get('@chooseCustom').should('not.be.checked');
cy.get('@url').should('not.be.visible');
});

it('persists a custom URL', () => {
cy.scrollTo('bottom');
cy.get('@chooseCustom')
.click()
.should('be.checked');
cy.get('@chooseCustom').click().should('be.checked');
cy.get('@url').type(linkedUrl);
cy.get('@saveButton').click();
cy.get('body').contains('Page draft updated');
cy.scrollTo('bottom');
cy.get('@chooseCustom').should('be.checked');
cy.get('@url')
.should('be.visible')
.and('have.value', linkedUrl);
cy.get('@url').should('be.visible').and('have.value', linkedUrl);
cy.get('@newTab').should('not.be.checked');
});

it('persists the new tab checkbox', () => {
cy.get('@newTab')
.click()
.should('be.checked');
cy.get('@newTab').click().should('be.checked');
cy.get('@saveButton').click();
cy.get('body').contains('Page draft updated');
cy.get('@url')
.should('be.visible')
.and('have.value', linkedUrl)
.clear()
.type(linkedUrl2);
cy.get('@newTab')
.should('be.checked')
.click()
.should('not.be.checked');
cy.get('@newTab').should('be.checked').click().should('not.be.checked');
cy.get('@saveButton').click();
cy.get('body').contains('Page draft updated');
cy.get('@url')
.should('be.visible')
.and('have.value', linkedUrl2);
cy.get('@url').should('be.visible').and('have.value', linkedUrl2);
cy.get('@newTab').should('not.be.checked');
});
});
Expand All @@ -129,7 +113,7 @@ describe('Classic Editor', () => {
url: `/${draftSlug}/`,
followRedirect: false,
failOnStatusCode: false,
}).then(resp => {
}).then((resp) => {
expect(resp.status).to.eq(301);
expect(resp.redirectedToUrl).to.eq(linkedUrl2);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import faker from 'faker';
import { faker } from '@faker-js/faker';

const postSlug = () => {
const parts = [faker.lorem.slug(), faker.lorem.slug(), faker.random.number()];
const parts = [faker.lorem.slug(), faker.lorem.slug(), faker.number.int()];

return parts.join('-');
};

const postTitle = () => {
const parts = [faker.lorem.word(), faker.lorem.word(), faker.random.number()];
const parts = [faker.lorem.word(), faker.lorem.word(), faker.number.int()];

return parts.join(' ');
};
Expand All @@ -22,7 +22,6 @@ describe('Quick Links', () => {

before(() => {
cy.login();
cy.keepAllCookies();
cy.enablePrettyPermalinks();
cy.visit('/wp-admin/');
cy.location('pathname').should('eq', '/wp-admin/');
Expand Down Expand Up @@ -154,9 +153,7 @@ describe('Quick Links', () => {

context('modal', () => {
it('shows a warning for long slugs', () => {
cy.get('@title')
.clear()
.type(longTitle);
cy.get('@title').clear().type(longTitle);
cy.get('@lengthWarning').should('be.visible');
});

Expand All @@ -172,7 +169,7 @@ describe('Quick Links', () => {
cy.request({
url: `/${publishSlug}/`,
followRedirect: false,
}).then(resp => {
}).then((resp) => {
expect(resp.status).to.eq(301);
expect(resp.redirectedToUrl).to.eq(linkedUrl);
});
Expand All @@ -184,9 +181,7 @@ describe('Quick Links', () => {
cy.get('@title').type(draftTitle);
cy.get('@slug').type(draftSlug);
cy.get('@url').type(linkedUrl);
cy.get('@save')
.should('not.be.disabled')
.click();
cy.get('@save').should('not.be.disabled').click();
cy.get('@modal').contains('Page link draft saved!');
});
});
Expand Down
31 changes: 12 additions & 19 deletions cypress/support/commands.js → cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
Cypress.Commands.add('login', () => {
cy.request({
url: '/wp-login.php',
method: 'POST',
form: true,
body: {
log: Cypress.env('wp_username'),
pwd: Cypress.env('wp_password'),
rememberme: 'forever',
testcookie: 1,
},
});
});

Cypress.Commands.add('keepAllCookies', () => {
Cypress.Cookies.defaults({
preserve: () => true,
cy.session('login', () => {
cy.request({
url: '/wp-login.php',
method: 'POST',
form: true,
body: {
log: Cypress.env('wp_username'),
pwd: Cypress.env('wp_password'),
rememberme: 'forever',
testcookie: 1,
},
});
});
cy.getCookies().then(cookies =>
cookies.forEach(cookie => Cypress.Cookies.preserveOnce(cookie.name))
);
});

Cypress.Commands.add(
Expand Down
20 changes: 0 additions & 20 deletions cypress/support/index.js

This file was deleted.

Loading

0 comments on commit 6a90698

Please sign in to comment.