Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into gh145-app
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinastefan90 committed Jul 16, 2019
2 parents 5c61519 + 6bf1962 commit 63c4b18
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 37 deletions.
64 changes: 64 additions & 0 deletions cypress/integration/purchase/credit_memo_for_purchase_invoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* #%L
* metasfresh-e2e
* %%
* Copyright (C) 2019 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

/// <reference types="Cypress" />

import {getLanguageSpecific} from '../../support/utils/utils';
import {DocumentActionKey, DocumentStatusKey} from '../../support/utils/constants';
import {PurchaseInvoice, PurchaseInvoiceLine} from "../../support/utils/purchase_invoice";

describe('Create a Credit memo for Purchase Invoice', function() {
const creditMemoVendor = 'Credit Memo (Vendor)';
const businessPartnerName = 'Test Lieferant 1';
const productName = 'Convenience Salat 250g';
const quantity = 200;

it(`Ensure ${creditMemoVendor} is Number Controlled`, function() {
// very bold assumption that this document type always has recordId=1000006
cy.visitWindow('135', '1000006');
cy.setCheckBoxValue('IsDocNoControlled', true);
});

it('Prepare Purchase Invoice', function() {
cy.fixture('misc/misc_dictionary.json').then(miscDictionary => {
new PurchaseInvoice(businessPartnerName, creditMemoVendor)
.addLine(
new PurchaseInvoiceLine().setProduct(productName).setQuantity(quantity)
)
.setDocumentAction(getLanguageSpecific(miscDictionary, DocumentActionKey.Complete))
.setDocumentStatus(getLanguageSpecific(miscDictionary, DocumentStatusKey.Completed))
.apply();
});
});

it('Purchase Invoice is Completed', function() {
cy.expectDocumentStatus(DocumentStatusKey.Completed);
});

it('Purchase Invoice is not paid', function() {
cy.getCheckboxValue('IsPaid').then(checkBoxValue => {
cy.log(`IsPaid = ${checkBoxValue}`);
assert.equal(checkBoxValue, false);
});
});

});
23 changes: 12 additions & 11 deletions cypress/integration/sales/change_shipment_date_shipment_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { BPartner } from '../../support/utils/bpartner';
import { DiscountSchema } from '../../support/utils/discountschema';
import { Bank } from '../../support/utils/bank';
import { Builder } from '../../support/utils/builder';
import {humanReadableNow} from "../../support/utils/utils";

describe('Create Sales order', function() {
const timestamp = new Date().getTime();
const customer = `CustomerTest ${timestamp}`;
const productName = `ProductTest ${timestamp}`;
const productValue = `sales_order_test ${timestamp}`;
const productCategoryName = `ProductCategoryName ${timestamp}`;
const productCategoryValue = `ProductCategoryValue ${timestamp}`;
const discountSchemaName = `DiscountSchemaTest ${timestamp}`;
const priceSystemName = `PriceSystem ${timestamp}`;
const priceListName = `PriceList ${timestamp}`;
const priceListVersionName = `PriceListVersion ${timestamp}`;
const date = humanReadableNow();
const customer = `CustomerTest ${date}`;
const productName = `ProductTest ${date}`;
const productValue = `sales_order_test ${date}`;
const productCategoryName = `ProductCategoryName ${date}`;
const productCategoryValue = `ProductCategoryValue ${date}`;
const discountSchemaName = `DiscountSchemaTest ${date}`;
const priceSystemName = `PriceSystem ${date}`;
const priceListName = `PriceList ${date}`;
const priceListVersionName = `PriceListVersion ${date}`;
const productType = 'Item';

before(function() {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('Create Sales order', function() {
.click();
cy.wait(8000);
cy.get('.quick-input-container .form-group').should('exist');
cy.writeIntoLookupListField('M_Product_ID', `${timestamp}`, productName);
cy.writeIntoLookupListField('M_Product_ID', `${date}`, productName);

cy.get('.form-field-Qty')
.click()
Expand Down
22 changes: 11 additions & 11 deletions cypress/integration/sales/credit_memo_for_sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/// <reference types="Cypress" />

import {getLanguageSpecific} from '../../support/utils/utils';
import {getLanguageSpecific, humanReadableNow} from '../../support/utils/utils';
import {salesInvoices} from '../../page_objects/sales_invoices';
import {Builder} from '../../support/utils/builder';
import {DiscountSchema} from '../../support/utils/discountschema';
Expand All @@ -31,8 +31,8 @@ import {BPartner} from '../../support/utils/bpartner';
import {SalesInvoice, SalesInvoiceLine} from '../../support/utils/sales_invoice';
import {DocumentActionKey, DocumentStatusKey, RewriteURL} from '../../support/utils/constants';

describe('Create a Credit memo for Sales Invoice', function () {
const timestamp = new Date().getTime();
describe('Create a Credit memo for Sales Invoice', function() {
const date = humanReadableNow();

const creditMemo = 'Credit Memo';
let originalSalesInvoiceNumber;
Expand All @@ -44,20 +44,20 @@ describe('Create a Credit memo for Sales Invoice', function () {

// data for "before" section
// priceList
const priceSystemName = `PriceSystem ${timestamp}`;
const priceListName = `PriceList ${timestamp}`;
const priceListVersionName = `PriceListVersion ${timestamp}`;
const priceSystemName = `PriceSystem ${date}`;
const priceListName = `PriceList ${date}`;
const priceListVersionName = `PriceListVersion ${date}`;

// product
const productCategoryName = `ProductCategory ${timestamp}`;
const productCategoryName = `ProductCategory ${date}`;
const productCategoryValue = productCategoryName;
const productName = `Product ${timestamp}`;
const productName = `Product ${date}`;
const productValue = productName;
const productType = 'Item';

// BPartner
const discountSchemaName = `DiscountSchema ${timestamp}`;
const bPartnerName = `bPartner ${timestamp}`;
const discountSchemaName = `DiscountSchema ${date}`;
const bPartnerName = `bPartner ${date}`;

// Sales Invoice
const salesInvoiceTargetDocumentType = 'Sales Invoice';
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Create a Credit memo for Sales Invoice', function () {
});
});

it('Prepare sales invoice', function () {
it('Prepare sales invoice', function() {
cy.fixture('sales/sales_invoice.json').then(salesInvoiceJson => {
new SalesInvoice(bPartnerName, salesInvoiceTargetDocumentType)
.addLine(
Expand Down
7 changes: 4 additions & 3 deletions cypress/integration/sales/sales_order_api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { salesOrders } from '../../page_objects/sales_orders';

import { SalesOrder } from '../../support/utils/sales_order_api';
import { BPartner } from '../../support/utils/bpartner';
import {humanReadableNow} from "../../support/utils/utils";

const timestamp = new Date().getTime();
const customer1Name = `Customer1-${timestamp}`;
const date = humanReadableNow();
const customer1Name = `Customer1-${date}`;

describe('New sales order test', function() {
const salesOrder1Name = `SalesOrder1-${timestamp}`;
const salesOrder1Name = `SalesOrder1-${date}`;
let salesOrder1ID = null;

before(function() {
Expand Down
23 changes: 12 additions & 11 deletions cypress/integration/sales/sales_order_to_shipment_to_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { salesOrders } from '../../page_objects/sales_orders';
import { BPartner } from '../../support/utils/bpartner';
import { DiscountSchema } from '../../support/utils/discountschema';
import { Builder } from '../../support/utils/builder';
import {humanReadableNow} from "../../support/utils/utils";

describe('Create Sales order', function() {
const timestamp = new Date().getTime();
const customer = `CustomerTest ${timestamp}`;
const productName = `ProductTest ${timestamp}`;
const productValue = `sales_order_test ${timestamp}`;
const productCategoryName = `ProductCategoryName ${timestamp}`;
const productCategoryValue = `ProductCategoryValue ${timestamp}`;
const discountSchemaName = `DiscountSchemaTest ${timestamp}`;
const priceSystemName = `PriceSystem ${timestamp}`;
const priceListName = `PriceList ${timestamp}`;
const priceListVersionName = `PriceListVersion ${timestamp}`;
const date = humanReadableNow();
const customer = `CustomerTest ${date}`;
const productName = `ProductTest ${date}`;
const productValue = `sales_order_test ${date}`;
const productCategoryName = `ProductCategoryName ${date}`;
const productCategoryValue = `ProductCategoryValue ${date}`;
const discountSchemaName = `DiscountSchemaTest ${date}`;
const priceSystemName = `PriceSystem ${date}`;
const priceListName = `PriceList ${date}`;
const priceListVersionName = `PriceListVersion ${date}`;
const productType = 'Item';

before(function() {
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('Create Sales order', function() {
.click();
// cy.wait(8000);
cy.get('.quick-input-container .form-group').should('exist');
cy.writeIntoLookupListField('M_Product_ID', `${timestamp}`, productName);
cy.writeIntoLookupListField('M_Product_ID', `${date}`, productName);

cy.get('.form-field-Qty')
.click()
Expand Down
160 changes: 160 additions & 0 deletions cypress/support/utils/purchase_invoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
export class PurchaseInvoice {
constructor(businessPartnerName, targetDocumentType) {
cy.log(`PurchaseInvoice - businessPartnerName=${businessPartnerName}, targetDocumentType=${targetDocumentType}`);
this.businessPartner = businessPartnerName;
this.targetDocumentType = targetDocumentType;
this._toString = `businessPartnerName=${businessPartnerName}, targetDocumentType=${targetDocumentType}`;
this.lines = [];
}

addLine(purchaseInvoiceLine) {
//console.log(`PurchaseInvoice - add InvoiceLine = ${JSON.stringify(purchaseInvoiceLine)}`);
this.lines.push(purchaseInvoiceLine);
return this;
}

setDocumentAction(documentAction) {
this.documentAction = documentAction;
return this;
}

setDocumentStatus(documentStatus) {
this.documentStatus = documentStatus;
return this;
}

setPriceList(priceList) {
this.priceList = priceList;
return this;
}

/** Creates a new invoice and stores its documentId as alias newInvoiceDocumentId. */
apply() {
cy.log(`PurchaseInvoice - apply START (${this._toString})`);
PurchaseInvoice.applyPurchaseInvoice(this);
cy.log(`PurchaseInvoice - apply STOP (${this._toString})`);
}

static applyPurchaseInvoice(purchaseInvoice) {
describe(`Create new PurchaseInvoice: ${purchaseInvoice._toString}`, () => {
cy.visitWindow('183', 'NEW', 'newInvoiceDocumentId' /*documentIdAliasName*/);

cy.get('.header-breadcrumb-sitename')
.should('contain', new Date().getDate())
.should('contain', new Date().getFullYear());

cy.writeIntoLookupListField('C_BPartner_ID', purchaseInvoice.businessPartner, purchaseInvoice.businessPartner);

cy.getStringFieldValue('M_PriceList_ID').should('not.be.empty');
cy.getStringFieldValue('C_Currency_ID').should('not.be.empty');
if (purchaseInvoice.priceList) {
cy.selectInListField('M_PriceList_ID', purchaseInvoice.priceList);
}

cy.getStringFieldValue('DocumentNo').should('be.empty');
cy.selectInListField('C_DocTypeTarget_ID', purchaseInvoice.targetDocumentType);
cy.getStringFieldValue('DocumentNo').should('not.be.empty');

purchaseInvoice.lines.forEach(line => {
PurchaseInvoice.applyLine(line);
});

if (purchaseInvoice.documentAction) {
if (purchaseInvoice.documentStatus) {
cy.processDocument(purchaseInvoice.documentAction, purchaseInvoice.documentStatus);
} else {
cy.processDocument(purchaseInvoice.documentAction);
}
}
});
}

/**
* Possible workaround for applyLine_buggy:
* It could be that setting the qty before setting the product id will fix the issue where 'done' button is pressed BEFORE
* the QtyEntered is saved.
*
* This is just a workaround though which isn't very cool to use.
*/
static applyLine(purchaseInvoiceLine) {
cy.selectTab('C_InvoiceLine');
cy.pressAddNewButton();

cy.writeIntoStringField(
'QtyEntered',
purchaseInvoiceLine.quantity,
true /*modal*/,
null /*rewriteUrl*/,
true /*noRequest, bc the patch response is e.g. 20 and we would be waiting for e.g. '20' */
);
// instead of waiting for the patch in writeIntoStringField, we wait for the "pending" indicator to go away
cy.get('.indicator-pending').should('not.exist');

cy.writeIntoLookupListField(
'M_Product_ID',
purchaseInvoiceLine.product,
purchaseInvoiceLine.product,
false /*typeList*/,
true /*modal*/
);

if (purchaseInvoiceLine.tuQuantity) {
cy.writeIntoStringField('QtyEnteredTU', purchaseInvoiceLine.tuQuantity, true /*modal*/);
}
if (purchaseInvoiceLine.packingItem) {
cy.writeIntoLookupListField(
'M_HU_PI_Item_Product_ID',
purchaseInvoiceLine.packingItem,
purchaseInvoiceLine.packingItem,
false /*typeList*/,
true /*modal*/
);
}
cy.pressDoneButton();
}

/*
static applyLine_buggy(purchaseInvoiceLine) {
cy.selectTab('C_InvoiceLine');
cy.pressAddNewButton();
cy.writeIntoLookupListField('M_Product_ID', purchaseInvoiceLine.product, purchaseInvoiceLine.product);
cy.writeIntoStringField('QtyEntered', purchaseInvoiceLine.quantity, true, null, true);
if (purchaseInvoiceLine.packingItem) {
cy.writeIntoLookupListField('M_HU_PI_Item_Product_ID', purchaseInvoiceLine.packingItem, purchaseInvoiceLine.packingItem, true, true);
}
if (purchaseInvoiceLine.tuQuantity) {
cy.writeIntoStringField('QtyEnteredTU', purchaseInvoiceLine.tuQuantity, true, null, true);
}
// something's flaky around here and, it seems that i need this delay as 'QtyEntered' or 'QtyEnteredTU' is sometimes NOT updated (it remains 1).
// problem is it only happens sometimes :(.
// how to fix? i'm not sure :( (is there a function "wait_until_all_requests_are_finished_before_pressing_done" ? maybe that helps)
// how to quickly test? ask me and i'll help.
cy.wait(5000);
cy.pressDoneButton();
}
*/
}

export class PurchaseInvoiceLine {
setProduct(product) {
this.product = product;
return this;
}

setPackingItem(packingItem) {
this.packingItem = packingItem;
return this;
}

setQuantity(quantity) {
this.quantity = quantity;
return this;
}

setTuQuantity(tuQuantity) {
this.tuQuantity = tuQuantity;
return this;
}
}
5 changes: 4 additions & 1 deletion cypress/support/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ const findByName = (dataArray, name) => {
/**
* Human readable date and time with millis!
*
* The returned time format is: `15T11:32:17.211` `([day]T[HH]:[MM]:[SS].[millis])`
*
* @returns {string}
*/
const humanReadableNow = () => {
return new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString();
const date = new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString();
return date.slice(8, date.length - 1);
};

export {getLanguageSpecific, wrapRequest, findByName, humanReadableNow};

0 comments on commit 63c4b18

Please sign in to comment.