Skip to content

Commit

Permalink
test(custom views): custom view templates e2e tests - follow up (#3346)
Browse files Browse the repository at this point in the history
* test(cypress): add loginToMerchantCenterForCustomView custom command

* chore: changeset

chore: changeset
  • Loading branch information
kark authored Dec 14, 2023
1 parent 3296632 commit bc0ece9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-trainers-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/cypress': patch
---

Add `loginToMerchantCenterForCustomView` Cypress command to streamline end-to-end testing of Custom Views.
10 changes: 1 addition & 9 deletions cypress/e2e/custom-view-template-starter/channels.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
ENTRY_POINT_CUSTOM_VIEW_TEMPLATE_STARTER,
URL_CUSTOM_VIEW_TEMPLATE_STARTER,
} from '../../support/urls';

describe('Channels', () => {
beforeEach(() => {
cy.loginToMerchantCenter({
entryPointUriPath: ENTRY_POINT_CUSTOM_VIEW_TEMPLATE_STARTER,
initialRoute: URL_CUSTOM_VIEW_TEMPLATE_STARTER,
});
cy.loginToMerchantCenterForCustomView();
});
it('should render page', () => {
cy.findByText('Open the Custom View').click();
Expand Down
10 changes: 1 addition & 9 deletions cypress/e2e/custom-view-template-starter/welcome.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
ENTRY_POINT_CUSTOM_VIEW_TEMPLATE_STARTER,
URL_CUSTOM_VIEW_TEMPLATE_STARTER,
} from '../../support/urls';

describe('Welcome', () => {
beforeEach(() => {
cy.loginToMerchantCenter({
entryPointUriPath: ENTRY_POINT_CUSTOM_VIEW_TEMPLATE_STARTER,
initialRoute: URL_CUSTOM_VIEW_TEMPLATE_STARTER,
});
cy.loginToMerchantCenterForCustomView();
});
it('should render page', () => {
cy.findByText('Custom View loader').should('exist');
Expand Down
6 changes: 0 additions & 6 deletions cypress/support/urls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH } from '@commercetools-frontend/constants';

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

export const URL_BASE = `/${projectKey}`;
Expand All @@ -13,7 +11,3 @@ export const URL_APP_KIT_PLAYGROUND_DATE_FORMATTERS = `${URL_APP_KIT_PLAYGROUND}
export const ENTRY_POINT_TEMPLATE_STARTER = 'template-starter';
export const URL_TEMPLATE_STARTER = `${URL_BASE}/${ENTRY_POINT_TEMPLATE_STARTER}`;
export const URL_TEMPLATE_STARTER_CHANNELS = `${URL_TEMPLATE_STARTER}/channels`;

export const ENTRY_POINT_CUSTOM_VIEW_TEMPLATE_STARTER =
CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH;
export const URL_CUSTOM_VIEW_TEMPLATE_STARTER = `${URL_BASE}/${CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH}`;
14 changes: 14 additions & 0 deletions packages/cypress/add-commands/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ declare namespace Cypress {
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
options?: import('./dist/commercetools-frontend-cypress-add-commands.cjs').CommandLoginOptions
): Chainable<Subject>;
/**
* Log into the Custom View.
* Custom Views are assumed to be tested on localhost and `loginByOidc` mechanism is used
*
* @example
* cy.loginToMerchantCenterForCustomView()
*/
loginToMerchantCenterForCustomView(
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
options?: Omit<
import('./dist/commercetools-frontend-cypress-add-commands.cjs').CommandLoginOptions,
'entryPointUriPath' | 'initialRoute'
>
): Chainable<Subject>;
/**
* Log into the Custom Application using the OIDC workflow.
* The command only works for testing an application running on localhost.
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@babel/runtime-corejs3": "^7.22.15",
"@commercetools-frontend/application-config": "22.14.3",
"@commercetools-frontend/application-shell": "22.14.3",
"@commercetools-frontend/constants": "22.14.3",
"@manypkg/get-packages": "1.1.3",
"@types/semver": "^7.5.1",
"semver": "7.5.2",
Expand Down
21 changes: 21 additions & 0 deletions packages/cypress/src/add-commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Matcher as TMatcher } from '@testing-library/dom';
import { CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH } from '@commercetools-frontend/constants';
import {
loginByForm,
loginByOidc,
Expand Down Expand Up @@ -28,6 +29,26 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add(
'loginToMerchantCenterForCustomView',
(
commandOptions: Omit<
CommandLoginOptions,
'entryPointUriPath' | 'initialRoute'
>
) => {
Cypress.log({ name: 'loginToMerchantCenterForCustomView' });

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

loginByOidc({
...commandOptions,
entryPointUriPath: CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH,
initialRoute: `/${projectKey}/${CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH}`,
});
}
);

Cypress.Commands.add('loginByOidc', (commandOptions: CommandLoginOptions) => {
Cypress.log({ name: 'loginByOidc' });
cy.log(
Expand Down
23 changes: 13 additions & 10 deletions pnpm-lock.yaml

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

2 comments on commit bc0ece9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-oixa4w6hr-commercetools.vercel.app

Built with commit bc0ece9.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Deploy preview for application-kit-custom-views ready!

✅ Preview
https://application-kit-custom-views-e5ln83wii-commercetools.vercel.app

Built with commit bc0ece9.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.