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

Chore: Adding Cypress tests to cover existing functional tests #912

Merged
merged 5 commits into from
Feb 5, 2019

Conversation

ConradJChan
Copy link
Contributor

  • Remove existing functional tests
  • Add README for running cypress tests

@boxcla
Copy link

boxcla commented Feb 4, 2019

Verified that @ConradJChan has signed the CLA. Thanks for the pull request!

src/index.html Outdated
@@ -93,6 +93,7 @@
/* global Box */
var preview = new Box.Preview();
preview.show(fileid, token, {
...options,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files aren't transpiled by Babel, so I believe this will fail in IE11.

const token = Cypress.env('ACCESS_TOKEN');
const fileId = Cypress.env('FILE_ID_DOC');

/* eslint-disable */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What rules are we breaking here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think jsdoc comments for the functions

const showControls = () => {
// Hover over the preview to trigger the controls
cy.getByTestId('bp').trigger('mouseover');
// Assert that the controls are shown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of code comments, but this logic seems pretty self-explanatory to me. Is a comment needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will remove

cy.contains('The Content Platform for Your Apps');
// Get the current dimensions of the page
getPage(1).then(($page) => {
cy.wrap($page[0].scrollWidth).as('origWidth');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally want to avoid abbreviation where possible.


showControls();
// Click the zoom out button
cy.getByTestId('Zoom out').click();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good use case for getByTitle.

showControls();
cy.getByTestId('Click to enter page number').click();
cy.getByTestId('page-num-input').should('be.visible').type('2').blur();
// cy.getByTestId('page-num-input').type('2').blur();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is intentional, but try to avoid commented code.

};

/* eslint-disable */
const getPage = (pageNum) => cy.get(`.page[data-page-number=${pageNum}]`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is used in more than one file, we should probably share it between them somehow.

it('Should handle page navigation via buttons', () => {
getPage(1).should('be.visible');
cy.contains('The Content Platform for Your Apps');
cy.getByTestId('current-page').invoke('text').should('equal', '1');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: You can alias these elements for reuse later in the test rather than selecting them each time.

cy.getByTestId('current-page').invoke('text').should('equal', '1');

showControls();
cy.getByTestId('Next page').click();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably use contains or getByTitle for any natural language selectors, ideally.

Conrad Chan and others added 3 commits February 4, 2019 15:39
Merge branch 'cypress-migration' of github.com:ConradJChan/box-content-preview into cypress-migration

beforeEach(() => {
cy.server();
cy.route('GET', '**/files/*?fields=download_url', { download_url: '' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be an .int.js test if we're stubbing the endpoints.

@ConradJChan ConradJChan merged commit 0093c93 into box:master Feb 5, 2019
@ConradJChan ConradJChan deleted the cypress-migration branch February 5, 2019 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants