Skip to content

Commit

Permalink
[v14] refactor(mc-scripts): to remove IE from browserslit (#836)
Browse files Browse the repository at this point in the history
* refactor(mc-scripts): to remove IE from browserslit

* fix(playground): to use supported permissions, fix icon color

* refactor(cypress): to simplify login setup
  • Loading branch information
emmenko committed Jul 15, 2019
1 parent 54d90dc commit 058cc31
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 44 deletions.
7 changes: 2 additions & 5 deletions cypress/integration/playground/state-machines.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { URL_BASE } from '../../support/urls';
import { URL_STATE_MACHINES } from '../../support/urls';

describe('State machines', () => {
describe('List view', () => {
it('should render page', () => {
cy.setDesktopViewport();
cy.login();
cy.visit(`${URL_BASE}/state-machines`);

cy.login({ redirectToUri: URL_STATE_MACHINES });
cy.getByText('State Machines').should('exist');
});
});
Expand Down
7 changes: 2 additions & 5 deletions cypress/integration/template-starter/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { URL_BASE } from '../../support/urls';
import { URL_EXAMPLES_STARTER } from '../../support/urls';

describe('Main view', () => {
it('should render page', () => {
cy.setDesktopViewport();
cy.login();
cy.visit(`${URL_BASE}/examples-starter`);

cy.login({ redirectToUri: URL_EXAMPLES_STARTER });
cy.getByText('Hello, world').should('exist');
});
});
51 changes: 32 additions & 19 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'cypress-testing-library/add-commands';

function isLocalhost() {
const url = new URL(Cypress.config('baseUrl'));
return url.hostname === 'localhost';
}

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
Expand Down Expand Up @@ -30,25 +35,33 @@ Cypress.Commands.add('logout', () => {
cy.visit('/logout');
});

Cypress.Commands.add('login', () => {
// Clear and previous session data (cookie and local storage)
cy.visit('/logout');
cy.visit('/login');

// Make sure all needed fields exist
cy.getByText('Email').should('exist');
cy.getByText('Password').should('exist');

// Fill out the form from `.env` or environment variables (CI)
cy.get('[name=email]').type(Cypress.env('LOGIN_USER'));
cy.get('[name=password]').type(Cypress.env('LOGIN_PASSWORD'));

// Sign in
cy.get('[aria-label="Sign in"]').click();

// Make sure that sign in worked
cy.get('[data-test=top-navigation').should('exist');
});
Cypress.Commands.add(
'login',
({ redirectToUri, isForcedMenuOpen = false } = {}) => {
cy.setDesktopViewport();
cy.window().then(win =>
win.localStorage.setItem('isForcedMenuOpen', isForcedMenuOpen)
);
cy.visit('/logout');
// Wait to be in the "/login" route, then redirect to "/login" again
// to ensure we clear all query parameters, as they seem to interfer
// with the login form.
if (!isLocalhost()) {
cy.url().should('include', '/login');
}
cy.visit(`/login`);
cy.getByText('Email').should('exist');
cy.getByText('Password').should('exist');
cy.getByLabelText(/email/i).type(Cypress.env('LOGIN_USER'));
cy.getByLabelText(/password/i).type(Cypress.env('LOGIN_PASSWORD'), {
log: false,
});
cy.get('[aria-label="Sign in"]').click();
cy.get('[data-test=top-navigation').should('exist');
cy.visit(`${Cypress.config('baseUrl')}${redirectToUri}`);
cy.url().should('include', redirectToUri);
}
);

Cypress.Commands.add('setDesktopViewport', () => {
// we use ui-elements which only render elements to the DOM when they are visible to the user
Expand Down
8 changes: 4 additions & 4 deletions cypress/support/urls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const URL_GRAPHQL = 'https://mc-api.escemo.com/graphql';
export const URL_API_TOKENS = 'https://mc-api.escemo.com/tokens';
export const URL_LOGOUT = '/logout';

export const projectKey = Cypress.env('PROJECT_KEY');

export const URL_BASE = `/${projectKey}`;

export const URL_STATE_MACHINES = `${URL_BASE}/state-machines`;

export const URL_EXAMPLES_STARTER = `${URL_BASE}/examples-starter`;
2 changes: 1 addition & 1 deletion packages/mc-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"production": [
">1%",
"not op_mini all",
"ie 11"
"not dead"
],
"development": [
"last 2 firefox versions",
Expand Down
2 changes: 0 additions & 2 deletions packages/permissions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ We recommend to put the permissions used by your application into a `constants.j
```js
// constants.js
export const PERMISSIONS = {
// Resource Accesses
ViewProducts: 'ViewProducts',
ManageProducts: 'ManageProducts',
ViewOrders: 'ViewOrders',
ViewStates: 'ViewStates',
ManageProductTypes: 'ManageProductTypes',
ViewProductTypes: 'ViewProductTypes',
};
Expand Down
2 changes: 1 addition & 1 deletion playground/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"key": "state-machines",
"uriPath": "state-machines",
"icon": "RocketIcon",
"permissions": ["ViewStates", "ManageStates"],
"permissions": ["ManageDeveloperSettings", "ViewDeveloperSettings"],
"featureToggle": null,
"submenu": [],
"labelAllLocales": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class StateMachinesList extends React.Component {
<Spacings.Stack scale="m">
{this.props.cachedStateMachineObjectsCount !== null && (
<Spacings.Inline alignItems="center">
<DotIcon size="small" theme="green" />
<DotIcon size="small" color="primary" />
<Text.Detail isItalic={true}>
<FormattedMessage
{...messages.objectsInCache}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe('list view', () => {
it('the user can see a list of state machines', async () => {
const { getByText } = render({
sdkMocks: [createStateMachinesListSdkMock()],
permissions: { canViewStates: true, canManageStates: true },
permissions: {
canViewDeveloperSettings: true,
canManageDeveloperSettings: true,
},
});
await waitForElement(() => getByText(/State machines/i));
await waitForElement(() => getByText(/There are 2 objects in the cache/i));
Expand All @@ -73,7 +76,10 @@ describe('list view', () => {
createStateMachinesListSdkMock(),
createStateMachinesDetailSdkMock(),
],
permissions: { canViewStates: true, canManageStates: true },
permissions: {
canViewDeveloperSettings: true,
canManageDeveloperSettings: true,
},
});
await waitForElement(() => getByText(/There are 2 objects in the cache/i));
fireEvent.click(getByText('sm-1'));
Expand Down
4 changes: 2 additions & 2 deletions playground/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const PERMISSIONS = {
ViewStates: 'ViewStates',
ManageStates: 'ManageStates',
ManageDeveloperSettings: 'ManageDeveloperSettings',
ViewDeveloperSettings: 'ViewDeveloperSettings',
};
10 changes: 8 additions & 2 deletions playground/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const ApplicationRoutes = props => (
path={`${props.match.path}/:id`}
render={routerProps => (
<RestrictedByPermissions
permissions={[PERMISSIONS.ViewStates, PERMISSIONS.ManageStates]}
permissions={[
PERMISSIONS.ViewDeveloperSettings,
PERMISSIONS.ManageDeveloperSettings,
]}
unauthorizedComponent={PageUnauthorized}
shouldMatchSomePermissions={true}
>
Expand All @@ -34,7 +37,10 @@ const ApplicationRoutes = props => (
<Route
render={routerProps => (
<RestrictedByPermissions
permissions={[PERMISSIONS.ViewStates, PERMISSIONS.ManageStates]}
permissions={[
PERMISSIONS.ViewDeveloperSettings,
PERMISSIONS.ManageDeveloperSettings,
]}
unauthorizedComponent={PageUnauthorized}
shouldMatchSomePermissions={true}
>
Expand Down

0 comments on commit 058cc31

Please sign in to comment.