From 001b017078135600408cac65fee4a6bb25033ae7 Mon Sep 17 00:00:00 2001 From: MorganeLecurieux Date: Mon, 19 Sep 2022 11:52:08 -0600 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=99=88=20Test=20bm=20creation=20?= =?UTF-8?q?+=20plan=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress/e2e/t2-create-customer.cy.ts | 18 +++ cypress/e2e/t3-create-bm.cy.ts | 120 ++++++++++++++++++ cypress/e2e/t4-create-plan.cy.ts | 62 +++++++++ cypress/e2e/t5-edit-plan.cy.ts | 70 ++++++++++ cypress/support/commands.ts | 8 ++ cypress/support/index.d.ts | 13 ++ cypress/support/reusableConstants.ts | 2 + src/components/GenericPlaceholder.tsx | 3 +- .../billableMetrics/BillableMetricForm.tsx | 1 + .../customers/AddCustomerDialog.tsx | 1 + src/components/customers/CustomerItem.tsx | 7 +- .../subscriptions/AddPlanToCustomerDialog.tsx | 6 +- .../CustomerSubscriptionsList.tsx | 1 + src/components/designSystem/ButtonLink.tsx | 4 +- src/components/designSystem/NavigationTab.tsx | 3 +- src/components/form/ComboBox/ComboBoxItem.tsx | 3 +- src/components/plans/AddChargeDialog.tsx | 2 + src/components/plans/ChargeAccordion.tsx | 2 + src/components/plans/PlanForm.tsx | 2 + src/components/plans/PlanItem.tsx | 8 +- src/pages/BillableMetricsList.tsx | 2 +- src/pages/CreateBillableMetric.tsx | 1 + src/pages/CreatePlan.tsx | 7 +- src/pages/CustomersList.tsx | 5 +- src/pages/PlansList.tsx | 3 +- 25 files changed, 343 insertions(+), 11 deletions(-) create mode 100644 cypress/e2e/t2-create-customer.cy.ts create mode 100644 cypress/e2e/t3-create-bm.cy.ts create mode 100644 cypress/e2e/t4-create-plan.cy.ts create mode 100644 cypress/e2e/t5-edit-plan.cy.ts create mode 100644 cypress/support/index.d.ts create mode 100644 cypress/support/reusableConstants.ts diff --git a/cypress/e2e/t2-create-customer.cy.ts b/cypress/e2e/t2-create-customer.cy.ts new file mode 100644 index 000000000..f7c3b2a43 --- /dev/null +++ b/cypress/e2e/t2-create-customer.cy.ts @@ -0,0 +1,18 @@ +import { customerName } from '../support/reusableConstants' + +describe('Create customer', () => { + beforeEach(() => { + cy.login('usertest@lago.com', 'P@ssw0rd') + cy.visit('/customers') + }) + + it('should create customer', () => { + cy.get('[data-test="create-customer"]').click() + cy.get('input[name="name"]').type(customerName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="externalId"]').type('id-george-de-la-jungle') + cy.get('[data-test="submit"]').click() + cy.url().should('include', '/customer/') + cy.contains(customerName).should('exist') + }) +}) diff --git a/cypress/e2e/t3-create-bm.cy.ts b/cypress/e2e/t3-create-bm.cy.ts new file mode 100644 index 000000000..48c69573b --- /dev/null +++ b/cypress/e2e/t3-create-bm.cy.ts @@ -0,0 +1,120 @@ +describe('Create billable metrics', () => { + beforeEach(() => { + cy.login('usertest@lago.com', 'P@ssw0rd') + cy.visit('/billable-metrics') + }) + + it('should create count billable metric', () => { + const randomId = Math.round(Math.random() * 1000) + const bmName = `bm count ${randomId}` + + cy.get('[data-test="create-bm"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/billable-metrics') + cy.get('input[name="name"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="aggregationType"]').click() + cy.get('[data-test="count_agg"]').click() + cy.get('input[name="fieldName"]').should('not.exist') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/billable-metrics') + cy.contains(bmName).should('exist') + }) + + it('should create uniq count billable metric', () => { + const randomId = Math.round(Math.random() * 1000) + const bmName = `bm uniq count ${randomId}` + + cy.get('[data-test="create-bm"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/billable-metrics') + cy.get('input[name="name"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="aggregationType"]').click() + cy.get('[data-test="unique_count_agg"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="fieldName"]').type('whatever') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/billable-metrics') + cy.contains(bmName).should('exist') + }) + + it('should create max billable metric', () => { + const randomId = Math.round(Math.random() * 1000) + const bmName = `bm max ${randomId}` + + cy.get('[data-test="create-bm"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/billable-metrics') + cy.get('input[name="name"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="aggregationType"]').click() + cy.get('[data-test="max_agg"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="fieldName"]').type('whatever') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/billable-metrics') + cy.contains(bmName).should('exist') + }) + + it('should create sum billable metric', () => { + const randomId = Math.round(Math.random() * 1000) + const bmName = `bm sum ${randomId}` + + cy.get('[data-test="create-bm"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/billable-metrics') + cy.get('input[name="name"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="aggregationType"]').click() + cy.get('[data-test="sum_agg"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="fieldName"]').type('whatever') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/billable-metrics') + cy.contains(bmName).should('exist') + }) + + it('should create recurring count billable metric', () => { + const randomId = Math.round(Math.random() * 1000) + const bmName = `bm recurring count ${randomId}` + + cy.get('[data-test="create-bm"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/billable-metrics') + cy.get('input[name="name"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(bmName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="aggregationType"]').click() + cy.get('[data-test="recurring_count_agg"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="fieldName"]').type('whatever') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/billable-metrics') + cy.contains(bmName).should('exist') + }) +}) diff --git a/cypress/e2e/t4-create-plan.cy.ts b/cypress/e2e/t4-create-plan.cy.ts new file mode 100644 index 000000000..311aae942 --- /dev/null +++ b/cypress/e2e/t4-create-plan.cy.ts @@ -0,0 +1,62 @@ +import { planWithChargesName } from '../support/reusableConstants' + +describe('Create plan', () => { + beforeEach(() => { + cy.login('usertest@lago.com', 'P@ssw0rd') + cy.visit('/plans') + }) + + it('should be able to access plans', () => { + cy.get('[data-test="create-plan"]').should('exist') + cy.get('[data-test="empty"]').should('exist') + }) + + it('should be able to create a simple plan', () => { + const randomId = Math.round(Math.random() * 1000) + const planName = `plan ${randomId}` + + cy.get('[data-test="create-plan"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/plans') + cy.get('input[name="name"]').type(planName) + cy.get('input[name="code"]').type(planName) + cy.get('textarea[name="description"]').type('I am a description') + cy.get('input[name="amountCents"]').type('30000') + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/plans') + cy.contains(planName).should('exist') + }) + + it('should be able to create a plan with charges', () => { + cy.get('[data-test="create-plan"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/create/plans') + cy.get('input[name="name"]').type(planWithChargesName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="code"]').type(planWithChargesName) + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('textarea[name="description"]').type('I am a description') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="amountCents"]').type('30000') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('input[name="amountCurrency"]').click() + cy.get('[data-test="UAH"]').click() + + cy.get('[data-test="add-charge"]').click() + cy.get('[data-test="submit-add-charge"]').should('be.disabled') + cy.get('input[name="billableMetricId"]').click() + cy.get('[data-option-index="0"]').click() + cy.get('[data-test="submit-add-charge"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('[data-test="remove-charge"]').should('exist').and('not.be.disabled') + cy.get('input[name="chargeModel"]').should('have.value', 'Standard pricing') + cy.get('input[name="amount"]').type('5000') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('input[name="amountCurrency"]').eq(1).should('be.disabled') + cy.get('input[name="amountCurrency"]').eq(1).should('have.value', 'UAH') + + cy.get('[data-test="submit"]').click() + cy.get('[data-test="go-back"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/plans') + cy.contains(planWithChargesName).should('exist') + }) +}) diff --git a/cypress/e2e/t5-edit-plan.cy.ts b/cypress/e2e/t5-edit-plan.cy.ts new file mode 100644 index 000000000..0b3ac4e11 --- /dev/null +++ b/cypress/e2e/t5-edit-plan.cy.ts @@ -0,0 +1,70 @@ +import { planWithChargesName, customerName } from '../support/reusableConstants' + +describe('Create plan', () => { + beforeEach(() => { + cy.login('usertest@lago.com', 'P@ssw0rd') + }) + + it('should be able to update all information of unused plan', () => { + cy.visit('/plans') + cy.get(`[data-test="${planWithChargesName}"]`).click() + cy.get('input[name="name"]').should('not.be.disabled') + cy.get('input[name="code"]').should('not.be.disabled') + cy.get('textarea[name="description"]').should('not.be.disabled') + cy.get('input[name="amountCents"]').should('not.be.disabled') + cy.get('input[name="amountCurrency"]').eq(0).should('not.be.disabled') + cy.get('[data-test="remove-charge"]').should('exist').and('not.be.disabled') + cy.get('[data-test="open-charge"]').click() + cy.get('input[name="chargeModel"]').should('not.be.disabled') + cy.get('input[name="amount"]').should('not.be.disabled') + cy.get('input[name="amountCurrency"]').eq(1).should('be.disabled') + cy.get('[data-test="submit"]').should('be.disabled') + + cy.get('input[name="code"]').type('new code plan with charge') + cy.get('[data-test="submit"]').click() + }) + + it('should add plan to customer', () => { + cy.visit('/customers') + cy.get(`[data-test="${customerName}"]`).click() + cy.get(`[data-test="add-subscription"]`).click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('input[name="planId"]').click() + cy.get('[data-option-index="0"]').click() + cy.get('[data-test="submit"]').click() + cy.get('[data-test="submit"]').should('not.exist') + cy.contains(customerName).should('exist') + }) + + it('should not be able to update all information of unused plan', () => { + cy.visit('/plans') + cy.get(`[data-test="${planWithChargesName}"]`).click() + cy.get('input[name="name"]').should('not.be.disabled') + cy.get('input[name="code"]').should('be.disabled') + cy.get('textarea[name="description"]').should('not.be.disabled') + cy.get('input[name="amountCents"]').should('be.disabled') + cy.get('input[name="amountCurrency"]').eq(0).should('be.disabled') + cy.get('[data-test="remove-charge"]').should('not.exist') + cy.get('[data-test="open-charge"]').click() + cy.get('input[name="chargeModel"]').should('be.disabled') + cy.get('input[name="amount"]').should('be.disabled') + cy.get('input[name="amountCurrency"]').eq(1).should('be.disabled') + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('[data-test="open-charge"]').click() + + cy.get('[data-test="add-charge"]').click() + cy.get('[data-test="submit-add-charge"]').should('be.disabled') + cy.get('input[name="billableMetricId"]').click() + cy.get('[data-option-index="1"]').click() + cy.get('[data-test="submit-add-charge"]').click() + cy.get('[data-test="submit"]').should('be.disabled') + cy.get('[data-test="remove-charge"]').should('exist').and('not.be.disabled') + cy.get('input[name="chargeModel"]').eq(1).should('have.value', 'Standard pricing') + cy.get('input[name="amount"]').eq(1).type('3000') + cy.get('[data-test="submit"]').should('not.be.disabled') + cy.get('input[name="amountCurrency"]').eq(2).should('be.disabled') + cy.get('input[name="amountCurrency"]').eq(2).should('have.value', 'UAH') + + cy.get('[data-test="submit"]').click() + }) +}) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 95857aea4..9a0483051 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -35,3 +35,11 @@ // } // } // } + +Cypress.Commands.add('login', (email: string, password: string) => { + cy.visit('/login') + cy.get('input[name="email"]').type(email) + cy.get('input[name="password"]').type(password) + cy.get('[data-test="submit"]').click() + cy.url().should('be.equal', Cypress.config().baseUrl + '/') +}) diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts new file mode 100644 index 000000000..eecf59137 --- /dev/null +++ b/cypress/support/index.d.ts @@ -0,0 +1,13 @@ +/// + +declare namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + /** + * Login user + * @example + * cy.login('usertest@lago.com', 'P@ssw0rd') + */ + login(email: string, password: string): Chainable + } +} diff --git a/cypress/support/reusableConstants.ts b/cypress/support/reusableConstants.ts new file mode 100644 index 000000000..ee0efb7fe --- /dev/null +++ b/cypress/support/reusableConstants.ts @@ -0,0 +1,2 @@ +export const planWithChargesName = `a plan with charges` +export const customerName = 'George de la jungle' diff --git a/src/components/GenericPlaceholder.tsx b/src/components/GenericPlaceholder.tsx index a850b542c..8e7810ce1 100644 --- a/src/components/GenericPlaceholder.tsx +++ b/src/components/GenericPlaceholder.tsx @@ -31,8 +31,9 @@ export const GenericPlaceholder = ({ noMargins = false, buttonVariant, buttonAction, + ...props }: GenericPlaceholderProps | GenericPlaceholderNoButtonProps) => ( - + {image} {title} {subtitle} diff --git a/src/components/billableMetrics/BillableMetricForm.tsx b/src/components/billableMetrics/BillableMetricForm.tsx index a5e5957d5..4b8e468a8 100644 --- a/src/components/billableMetrics/BillableMetricForm.tsx +++ b/src/components/billableMetrics/BillableMetricForm.tsx @@ -240,6 +240,7 @@ export const BillableMetricForm = ({ diff --git a/src/components/customers/AddCustomerDialog.tsx b/src/components/customers/AddCustomerDialog.tsx index 1773503b1..1238f7d2c 100644 --- a/src/components/customers/AddCustomerDialog.tsx +++ b/src/components/customers/AddCustomerDialog.tsx @@ -173,6 +173,7 @@ export const AddCustomerDialog = forwardRef( - diff --git a/src/components/designSystem/NavigationTab.tsx b/src/components/designSystem/NavigationTab.tsx index 7ba8e003f..5a21b4880 100644 --- a/src/components/designSystem/NavigationTab.tsx +++ b/src/components/designSystem/NavigationTab.tsx @@ -1,6 +1,7 @@ import { ReactNode } from 'react' import styled, { css } from 'styled-components' import { useLocation, matchPath } from 'react-router-dom' +import _omit from 'lodash/omit' import { theme, NAV_HEIGHT } from '~/styles' @@ -68,7 +69,7 @@ export const NavigationTab = ({ type="tab" active={link === activeTab?.link} onClick={!!onClick ? () => onClick(tab) : undefined} - {...props} + {..._omit(props, ['component', 'match'])} > {title} diff --git a/src/components/form/ComboBox/ComboBoxItem.tsx b/src/components/form/ComboBox/ComboBoxItem.tsx index 05ca36e47..3fb1fe2b9 100644 --- a/src/components/form/ComboBox/ComboBoxItem.tsx +++ b/src/components/form/ComboBox/ComboBoxItem.tsx @@ -38,12 +38,13 @@ export const ComboBoxItem = ({ }, className )} + data-test={value} key={value} {...allProps} > {customValue ? ( <> - + {labelNode ?? label} diff --git a/src/components/plans/AddChargeDialog.tsx b/src/components/plans/AddChargeDialog.tsx index 3dd995d39..a52773cf6 100644 --- a/src/components/plans/AddChargeDialog.tsx +++ b/src/components/plans/AddChargeDialog.tsx @@ -75,6 +75,7 @@ export const AddChargeDialog = forwardRef( {translate('text_6244277fe0975300fe3fb94a')} - + {translate('text_624455d859b1b000a8e17bf9')} diff --git a/src/pages/CustomersList.tsx b/src/pages/CustomersList.tsx index 77b637746..bd0aa6c91 100644 --- a/src/pages/CustomersList.tsx +++ b/src/pages/CustomersList.tsx @@ -48,7 +48,10 @@ const CustomersList = () => { {translate('text_624efab67eb2570101d117a5')} - diff --git a/src/pages/PlansList.tsx b/src/pages/PlansList.tsx index a1ef658e5..6bb8d23fe 100644 --- a/src/pages/PlansList.tsx +++ b/src/pages/PlansList.tsx @@ -49,7 +49,7 @@ const PlansList = () => { {translate('text_62442e40cea25600b0b6d84a')} - + {translate('text_62442e40cea25600b0b6d84c')} @@ -65,6 +65,7 @@ const PlansList = () => { /> ) : !loading && (!list || !list.length) ? (