Skip to content

Commit

Permalink
console: oss test optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
soorajshankar authored and hasura-bot committed Aug 18, 2021
1 parent fa152d8 commit c0ea2b0
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 68 deletions.
6 changes: 6 additions & 0 deletions console/cypress/helpers/constants.ts
@@ -1 +1,7 @@
export const ADMIN_SECRET_HEADER_KEY = 'x-hasura-admin-secret';

// TODO cypress default timeout is 4000, we can remove this `AWAIT_SHORT` after verifying that this is followed by a test command that works with timeout
// https://docs.cypress.io/guides/references/configuration#Timeouts
export const AWAIT_SHORT = 2000;
export const AWAIT_MODERATE = 5000;
export const AWAIT_LONG = 7000;
25 changes: 25 additions & 0 deletions console/cypress/integration/_onboarding/spec.ts
@@ -0,0 +1,25 @@
import { getElementFromAlias } from '../../helpers/dataHelpers';

export const viewOnboarding = () => {
// Click on create
cy.get(getElementFromAlias('onboarding-popup'))
.should('be.visible')
.should('contain.text', `Hi there, let's get started with Hasura!`);
// cy.get(getElementFromAlias('btn-hide-for-now')).click();
};
export const hideNow = () => {
// Click on create
cy.get(getElementFromAlias('btn-hide-for-now')).click();
cy.get(getElementFromAlias('onboarding-popup')).should('not.exist');
};

export const dontShowAgain = () => {
// Click on create
cy.reload();
cy.get(getElementFromAlias('onboarding-popup')).should('be.visible');

cy.get(getElementFromAlias('btn-ob-dont-show-again')).click();
cy.get(getElementFromAlias('onboarding-popup')).should('not.exist');
cy.reload();
cy.get(getElementFromAlias('onboarding-popup')).should('not.exist');
};
30 changes: 30 additions & 0 deletions console/cypress/integration/_onboarding/test.ts
@@ -0,0 +1,30 @@
import {
viewOnboarding,
hideNow,
dontShowAgain,
} from './spec';
import { testMode } from '../../helpers/common';
import { setMetaData } from '../validators/validators';
import { getIndexRoute } from '../../helpers/dataHelpers';

const setup = () => {
describe('Setup route', () => {
it('Visit the index route', () => {
cy.visit(getIndexRoute());
setMetaData();
});
});
};

export const runActionsTests = () => {
describe('onboarding', () => {
it('should show onboarding guide', viewOnboarding);
it('should hide when user click on Hide Now', hideNow);
it('should hide forever when user click on Dont Show again', dontShowAgain);
});
};

if (testMode !== 'cli') {
setup();
runActionsTests();
}
56 changes: 16 additions & 40 deletions console/cypress/integration/actions/spec.ts
Expand Up @@ -4,6 +4,7 @@ import {
getElementFromClassName,
} from '../../helpers/dataHelpers';
import { setPromptValue } from '../../helpers/common';
import { AWAIT_LONG } from '../../helpers/constants';
import { getTimeoutSeconds } from '../../helpers/eventHelpers';

const statements = {
Expand Down Expand Up @@ -44,7 +45,6 @@ const clearActionDef = () => {
which: 46,
force: true,
});
cy.wait(2000);
};

const clearActionTypes = () => {
Expand All @@ -54,17 +54,14 @@ const clearActionTypes = () => {
which: 46,
force: true,
});
cy.wait(2000);
};

const typeIntoActionDef = (content: string) => {
cy.get('textarea').first().type(content, { force: true });
cy.wait(2000);
};

const typeIntoActionTypes = (content: string) => {
cy.get('textarea').eq(1).type(content, { force: true });
cy.wait(2000);
};

const clearHandler = () => {
Expand All @@ -80,34 +77,29 @@ const clearHandler = () => {
force: true,
}
);
cy.wait(2000);
};

const typeIntoHandler = (content: string) => {
cy.get(getElementFromAlias('action-create-handler-input')).type(content, {
force: true,
});
cy.wait(2000);
};

const clickOnCreateAction = () => {
cy.get(getElementFromAlias('create-action-btn')).click({ force: true });
cy.get('.notification', { timeout: 5000 })
cy.get('.notification', { timeout: AWAIT_LONG })
.should('be.visible')
.and('contain', 'Created action successfully');
cy.wait(5000);
};

export const routeToGraphiql = () => {
cy.visit('/api/api-explorer');
cy.wait(7000);
cy.url().should('eq', `${baseUrl}/api/api-explorer`);
cy.url({ timeout: AWAIT_LONG }).should('eq', `${baseUrl}/api/api-explorer`);
};

export const createMutationAction = () => {
// Click on create
cy.get(getElementFromAlias('data-create-actions')).click();
cy.wait(7000);
// Clear default text on
clearActionDef();
// type statement
Expand Down Expand Up @@ -145,27 +137,24 @@ export const verifyMutation = () => {
.type(`{enter}{uparrow}${statements.createMutationGQLQuery}`, {
force: true,
});
cy.wait(3000);
cy.get('textarea')
.eq(1)
.type(`{enter}{uparrow}${statements.createMutationQueryVars}`, {
force: true,
});
cy.wait(3000);
cy.get(getElementFromClassName('execute-button')).click();
// FIXME: NOT GOOD!
cy.wait(30000);
cy.get('.cm-property').contains('login');
cy.get('.cm-property').contains('accessToken');
cy.get('.cm-string').contains('Ew8jkGCNDGAo7p35RV72e0Lk3RGJoJKB');

cy.wait(2000);
};

export const modifyMutationAction = () => {
cy.visit('/actions/manage/login/modify');
cy.wait(7000);
cy.url().should('eq', `${baseUrl}/actions/manage/login/modify`);
cy.url({ timeout: AWAIT_LONG }).should(
'eq',
`${baseUrl}/actions/manage/login/modify`
);

clearHandler();
typeIntoHandler(statements.changeHandlerText);
Expand All @@ -177,48 +166,42 @@ export const modifyMutationAction = () => {
.clear()
.type('50');
cy.get(getElementFromAlias('save-modify-action-changes')).click();
cy.get('.notification', { timeout: 5000 })
cy.get('.notification', { timeout: AWAIT_LONG })
.should('be.visible')
.and('contain', 'Action saved successfully');
cy.get(getElementFromAlias('modify-action-timeout-seconds')).should(
'have.value',
'50'
);
cy.wait(5000);

// permissions part
cy.get(getElementFromAlias('actions-permissions')).click();
cy.wait(2000);

cy.get(getElementFromAlias('role-textbox')).type('hakuna_matata');
cy.wait(1000);

cy.get(getElementFromAlias('hakuna_matata-Permission')).click();
cy.wait(1000);
cy.get(getElementFromAlias('save-permissions-for-action')).click();

cy.get(getElementFromAlias('actions-modify')).click();

cy.wait(3000);
};

const deleteAction = (promptValue: string) => {
setPromptValue(promptValue);
cy.get(getElementFromAlias('delete-action')).click();
cy.window().its('prompt').should('be.called');
cy.wait(7000);
};

export const deleteMutationAction = () => deleteAction('login');

export const createQueryAction = () => {
// Routing to the index page
cy.visit('/actions/manage/actions');
cy.wait(7000);
cy.url().should('eq', `${baseUrl}/actions/manage/actions`);
cy.url({ timeout: AWAIT_LONG }).should(
'eq',
`${baseUrl}/actions/manage/actions`
);
// Click on create
cy.get(getElementFromAlias('data-create-actions')).click();
cy.wait(7000);
// Clear default text on
clearActionDef();
// type statement
Expand Down Expand Up @@ -248,39 +231,32 @@ export const verifyQuery = () => {
.type(`{enter}{uparrow}${statements.createQueryGQLQuery}`, { force: true })
.wait(4000);
cy.get(getElementFromClassName('execute-button')).click();
cy.wait(30000);
cy.get('.cm-property').contains('addNumbers');
cy.get('.cm-property').contains('sum');
cy.get('.cm-number').contains('10');

cy.wait(2000);
};

export const modifyQueryAction = () => {
cy.visit('/actions/manage/addNumbers/modify');
cy.wait(7000);
cy.url().should('eq', `${baseUrl}/actions/manage/addNumbers/modify`);
cy.url({ timeout: AWAIT_LONG }).should(
'eq',
`${baseUrl}/actions/manage/addNumbers/modify`
);

clearHandler();
typeIntoHandler(statements.changeHandlerText);

cy.get(getElementFromAlias('save-modify-action-changes')).click();
cy.wait(5000);

// permissions part
cy.get(getElementFromAlias('actions-permissions')).click();
cy.wait(2000);

cy.get(getElementFromAlias('role-textbox')).type('MANAGER');
cy.wait(1000);

cy.get(getElementFromAlias('MANAGER-Permission')).click();
cy.wait(1000);
cy.get(getElementFromAlias('save-permissions-for-action')).click();

cy.get(getElementFromAlias('actions-modify')).click();

cy.wait(3000);
};

export const deleteQueryAction = () => deleteAction('addNumbers');
2 changes: 1 addition & 1 deletion console/cypress/integration/actions/test.ts
Expand Up @@ -13,7 +13,7 @@ const setup = () => {
describe('Setup route', () => {
it('Visit the index route', () => {
cy.visit('/actions/manage/actions');
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/api-explorer/graphql/test.ts
Expand Up @@ -16,7 +16,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit('/');
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/404/test.ts
Expand Up @@ -7,7 +7,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
2 changes: 1 addition & 1 deletion console/cypress/integration/data/computed-fields/test.ts
Expand Up @@ -18,7 +18,7 @@ const setup = () => {
describe('Setup route', () => {
it('Visit the index route', () => {
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/create-table/test.ts
Expand Up @@ -19,7 +19,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
2 changes: 1 addition & 1 deletion console/cypress/integration/data/custom-functions/test.ts
Expand Up @@ -17,7 +17,7 @@ const setup = () => {
describe('Setup route', () => {
it('Visit the index route', () => {
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
});
Expand Down
2 changes: 1 addition & 1 deletion console/cypress/integration/data/insert-browse/test.ts
Expand Up @@ -29,7 +29,7 @@ const setup = () => {
describe('Setup route', () => {
it('Visit the index route', () => {
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
});
Expand Down
Expand Up @@ -21,7 +21,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/migration-mode/test.ts
Expand Up @@ -9,7 +9,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/modify/test.ts
Expand Up @@ -31,7 +31,6 @@ const setup = () => {
it('Clicking on Data tab opens the correct route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/permissions/test.ts
Expand Up @@ -19,7 +19,6 @@ const setup = () => {
it('Clicking on Data tab opens the correct route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/raw-sql/test.ts
Expand Up @@ -16,7 +16,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down
2 changes: 1 addition & 1 deletion console/cypress/integration/data/relationships/test.ts
Expand Up @@ -16,7 +16,7 @@ const setup = () => {
describe('Check Data Tab', () => {
it('Clicking on Data tab opens the correct route', () => {
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
});
Expand Down
1 change: 0 additions & 1 deletion console/cypress/integration/data/views/test.ts
Expand Up @@ -21,7 +21,6 @@ const setup = () => {
it('Visit the index route', () => {
// Visit the index route
cy.visit(getIndexRoute());
cy.wait(7000);
// Get and set validation metadata
setMetaData();
});
Expand Down

0 comments on commit c0ea2b0

Please sign in to comment.