Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom commands with @10up/cypress-wp-utils #162

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ jobs:

- name: Test
run: npm run cypress:run

- name: Upload artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-artifact
retention-days: 2
path: |
${{ github.workspace }}/cypress-test/tests/cypress/screenshots/
${{ github.workspace }}/cypress-test/tests/cypress/videos/
${{ github.workspace }}/cypress-test/tests/cypress/logs/
11 changes: 11 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ jobs:

- name: Test
run: npm run cypress:run

- name: Upload artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-artifact
retention-days: 2
path: |
${{ github.workspace }}/cypress-test/tests/cypress/screenshots/
${{ github.workspace }}/cypress-test/tests/cypress/videos/
${{ github.workspace }}/cypress-test/tests/cypress/logs/
28 changes: 25 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@
"./vendor/bin/phpcs --standard=10up-Default --extensions=php --warning-severity=8 -s --runtime-set testVersion 5.3"
],
"tests/**/*.js": [
"./node_modules/.bin/wp-scripts format",
"git add"
"./node_modules/.bin/wp-scripts format"
]
},
"devDependencies": {
"@10up/cypress-wp-utils": "git+https://github.com/10up/cypress-wp-utils.git#build",
"@wordpress/env": "^4.3.1",
"@wordpress/prettier-config": "^1.1.3",
"@wordpress/scripts": "^22.2.1",
"ansi-regex": ">=6.0.1",
"cypress": "^9.5.1",
"cypress-file-upload": "^5.0.8",
"eslint-plugin-cypress": "^2.12.1",
"husky": "^7.0.4",
"json-schema": ">=0.4.0",
"lint-staged": "^12.3.5",
"node-wp-i18n": "^1.2.6",
"nth-check": ">=2.0.1",
"prettier": "2.6.2",
"tmpl": ">=1.0.5"
},
"prettier": "@wordpress/prettier-config"
Expand Down
6 changes: 6 additions & 0 deletions tests/cypress/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "plugin:cypress/recommended",
"rules": {
"jest/expect-expect": "off",
}
}
18 changes: 10 additions & 8 deletions tests/cypress/integration/admin.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
describe( 'Admin can login and make sure plugin is activated', () => {
it( 'Can activate plugin if it is deactivated', () => {
cy.visitAdminPage( 'plugins.php' );
cy.get( '#deactivate-simple-podcasting' ).click();
cy.get( '#activate-simple-podcasting' ).click();
cy.get( '#deactivate-simple-podcasting' ).should( 'be.visible' );
} );
} );
describe('Admin can login and make sure plugin is activated', () => {
before(() => {
cy.login();
});

it('Can activate plugin if it is deactivated', () => {
cy.deactivatePlugin('simple-podcasting');
cy.activatePlugin('simple-podcasting');
});
});
81 changes: 40 additions & 41 deletions tests/cypress/integration/block.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
describe( 'Admin can publish posts with podcast block', () => {
describe('Admin can publish posts with podcast block', () => {
const taxonomy = 'Remote work';
before( () => {
cy.createTaxonomy( taxonomy, 'podcasting_podcasts' );
} );
it( 'Can insert the block and publish the post', () => {
cy.visitAdminPage( 'post-new.php' );
cy.get( 'button[aria-label="Close dialog"]' ).click();
cy.get( 'h1.editor-post-title__input, #post-title-0' )

before(() => {
cy.login();
cy.createTerm(taxonomy, 'podcasting_podcasts');
});

it('Can insert the block and publish the post', () => {
cy.visit('/wp-admin/post-new.php');
cy.get('button[aria-label="Close dialog"]').click();
cy.get('h1.editor-post-title__input, #post-title-0')
.first()
.as( 'title-input' );
cy.get( '@title-input' ).click().type( 'Test episode' );
cy.get( '.edit-post-header-toolbar__inserter-toggle' ).click();
cy.get(
'#components-search-control-0, #block-editor-inserter__search-0'
)
.as('title-input');
cy.get('@title-input').click().type('Test episode');
cy.get('.edit-post-header-toolbar__inserter-toggle').click();
cy.get('#components-search-control-0, #block-editor-inserter__search-0')
.first()
.as( 'block-search' );
cy.get( '@block-search' ).click().type( 'Podcast' );
cy.get( '.editor-block-list-item-podcasting-podcast' ).click();
cy.get( '.edit-post-header-toolbar__inserter-toggle' ).click();
cy.get( '.wp-block-podcasting-podcast input[type="file"]' ).attachFile(
.as('block-search');
cy.get('@block-search').click().type('Podcast');
cy.get('.editor-block-list-item-podcasting-podcast').click();
cy.get('.edit-post-header-toolbar__inserter-toggle').click();
cy.get('.wp-block-podcasting-podcast input[type="file"]').attachFile(
'example.mp3'
);
cy.get( '.wp-block-podcasting-podcast audio' )
.should( 'have.attr', 'src' )
.and( 'include', 'example' );
cy.openDocumentSettingsPanel( 'Podcasts' );
cy.get( '.components-panel__body' )
.contains( 'Podcasts' )
.parents( '.components-panel__body' )
.find( '.components-checkbox-control__label' )
.contains( taxonomy )
cy.get('.wp-block-podcasting-podcast audio')
.should('have.attr', 'src')
.and('include', 'example');
cy.openDocumentSettingsPanel('Podcasts');
cy.get('.components-panel__body')
.contains('Podcasts')
.parents('.components-panel__body')
.find('.components-checkbox-control__label')
.contains(taxonomy)
.click();
cy.get( '.editor-post-publish-panel__toggle' ).click();
cy.get( '.editor-post-publish-button' ).click();
cy.get( '.components-snackbar', { timeout: 10000 } ).should(
'be.visible'
);
cy.get( 'a.components-button.components-snackbar__action' ).click();
cy.get( '.wp-block-podcasting-podcast audio' )
.should( 'have.attr', 'src' )
.and( 'include', 'example' );
cy.visitAdminPage( 'edit.php' );
cy.get( '.column-taxonomy-podcasting_podcasts' ).should(
cy.get('.editor-post-publish-panel__toggle').click();
cy.get('.editor-post-publish-button').click();
cy.get('.components-snackbar', { timeout: 10000 }).should('be.visible');
cy.get('a.components-button.components-snackbar__action').click();
cy.get('.wp-block-podcasting-podcast audio')
.should('have.attr', 'src')
.and('include', 'example');
cy.visit('/wp-admin/edit.php');
cy.get('.column-taxonomy-podcasting_podcasts').should(
'contain.text',
taxonomy
);
} );
} );
});
});
115 changes: 47 additions & 68 deletions tests/cypress/integration/taxonomy.test.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,66 @@
describe( 'Admin can create and update podcast taxonomy', () => {
it( 'Can see taxonomy menu item', () => {
cy.visitAdminPage();
describe('Admin can create and update podcast taxonomy', () => {
before(() => {
cy.login();
});

it('Can see taxonomy menu item', () => {
cy.visit('/wp-admin');
cy.get(
'#toplevel_page_edit-tags-taxonomy-podcasting_podcasts-amp-podcasts-true .wp-menu-name'
).should( 'have.text', 'Podcasts' );
} );
).should('have.text', 'Podcasts');
});

it( 'Can visit taxonomy page', () => {
cy.visitAdminPage(
'edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
it('Can visit taxonomy page', () => {
cy.visit(
'/wp-admin/edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
);
cy.get( '.wp-heading-inline' ).should( 'have.text', 'Podcasts' );
cy.get( '.form-wrap h2' ).should( 'have.text', 'Add New Podcast' );
cy.get( '.notice' ).should(
cy.get('.wp-heading-inline').should('have.text', 'Podcasts');
cy.get('.form-wrap h2').should('have.text', 'Add New Podcast');
cy.get('.notice').should(
'contain.text',
'Once at least one podcast exists'
);
} );
});

it( 'Can delete all taxonomies', () => {
cy.visitAdminPage(
'edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
);
cy.get( '#cb-select-all-1' ).click();
cy.get( '#bulk-action-selector-top' ).select( 'delete' );
cy.get( '#doaction' ).click();
cy.url().should(
'contains',
'http://localhost:8889/wp-admin/edit-tags.php'
);
cy.get( '.wp-list-table' ).should(
'contain.text',
'No podcasts found'
);
} );
it('Can delete all taxonomies', () => {
cy.deleteAllTerms('podcasting_podcasts');
});

it( 'Can add a new taxonomy', () => {
cy.createTaxonomy( 'Remote work', 'podcasting_podcasts' );
cy.get( '.row-title' ).should( 'have.text', 'Remote work' );
} );
it('Can add a new taxonomy', () => {
cy.createTerm('Remote work', 'podcasting_podcasts');
cy.get('.row-title').should('have.text', 'Remote work');
});

it( 'Can edit taxonomy', () => {
cy.visitAdminPage(
'edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
it('Can edit taxonomy', () => {
cy.visit(
'/wp-admin/edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
);
cy.get( '.row-title' ).should( 'have.text', 'Remote work' ).click();
cy.url().should(
'contains',
'http://localhost:8889/wp-admin/term.php'
);
cy.get( '#name' ).click().clear();
cy.get( '#name' ).type( 'Distributed' );
cy.get( '#slug' ).click().clear();
cy.get( '#edittag' ).submit();
cy.url().should(
'contains',
'http://localhost:8889/wp-admin/term.php'
);
cy.visitAdminPage(
'edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
cy.get('.row-title').should('have.text', 'Remote work').click();
cy.url().should('contains', 'http://localhost:8889/wp-admin/term.php');
cy.get('#name').click().clear();
cy.get('#name').type('Distributed');
cy.get('#slug').click().clear();
cy.get('#edittag').submit();
cy.url().should('contains', 'http://localhost:8889/wp-admin/term.php');
cy.visit(
'/wp-admin/edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
);

cy.get( '.row-title' ).should( 'have.text', 'Distributed' );
} );
cy.get('.row-title').should('have.text', 'Distributed');
});

it( 'Can delete taxonomy', () => {
cy.visitAdminPage(
'edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
it('Can delete taxonomy', () => {
cy.visit(
'/wp-admin/edit-tags.php?taxonomy=podcasting_podcasts&podcasts=true'
);
cy.get( '.row-title' ).should( 'have.text', 'Distributed' ).click();
cy.url().should(
'contains',
'http://localhost:8889/wp-admin/term.php'
);
cy.on( 'window:confirm', () => true );
cy.get( '.delete' ).click();
cy.get('.row-title').should('have.text', 'Distributed').click();
cy.url().should('contains', 'http://localhost:8889/wp-admin/term.php');
cy.on('window:confirm', () => true);
cy.get('.delete').click();
cy.url().should(
'contains',
'http://localhost:8889/wp-admin/edit-tags.php'
);
cy.get( '.wp-list-table' ).should(
'contain.text',
'No podcasts found'
);
} );
} );
cy.get('.wp-list-table').should('contain.text', 'No podcasts found');
});
});
Loading