-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from 10up/command/set-permalink-structure
Set Permalink Structure command
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Set Permalink Structure | ||
* | ||
* @param type - Permalink structure, should contain structure tags or be an empty string (which means "Plain" structure) | ||
* | ||
* @example | ||
* ``` | ||
* cy.setPermalinkStructure('/%year%/%postname%/') | ||
* ``` | ||
*/ | ||
export const setPermalinkStructure = (type: string): void => { | ||
cy.visit('/wp-admin/options-permalink.php'); | ||
cy.get('#permalink_structure').click().clear(); | ||
if ('' !== type) { | ||
cy.get('#permalink_structure').click().type(type); | ||
} | ||
cy.get('#submit').click(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
describe('Command: setPermalinkStructure', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
}); | ||
|
||
const structures = [ | ||
{ name: 'Plain', value: '' }, | ||
{ name: 'Day and name', value: '/%year%/%monthnum%/%day%/%postname%/' }, | ||
{ name: 'Month and name', value: '/%year%/%monthnum%/%postname%/' }, | ||
{ name: 'Numeric', value: '/archives/%post_id%' }, | ||
{ name: 'Post name', value: '/%postname%/' }, | ||
]; | ||
|
||
structures.forEach(structure => { | ||
it(`Should be able to set predefined ${structure.name} permalinks`, () => { | ||
cy.setPermalinkStructure(structure.value); | ||
cy.get('.notice-success').should( | ||
'contain', | ||
'Permalink structure updated.' | ||
); | ||
cy.get('.form-table.permalink-structure :checked').should( | ||
'have.value', | ||
structure.value | ||
); | ||
}); | ||
}); | ||
|
||
it('Should be able to set custom permalinks', () => { | ||
const structure = '/custom/%second%/'; | ||
cy.setPermalinkStructure(structure); | ||
cy.get('.notice-success').should('contain', 'Permalink structure updated.'); | ||
cy.get('.form-table.permalink-structure :checked').should( | ||
'have.value', | ||
'custom' | ||
); | ||
cy.get('#permalink_structure').should('have.value', structure); | ||
}); | ||
|
||
it('Should receive error if no tag added', ()=>{ | ||
cy.setPermalinkStructure('no-tag'); | ||
cy.get('.notice-error').should('contain', 'A structure tag is required when using custom permalinks.'); | ||
}); | ||
|
||
after(() => { | ||
// Set permalinks back to plain | ||
cy.setPermalinkStructure(''); | ||
}); | ||
}); |