diff --git a/.gitignore b/.gitignore index 8cb76a829..f4b1ab270 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ e2e/dms/*/ !e2e/dms/c4c !e2e/dms/c81 !e2e/dms/ecc +!e2e/dms/a87 npm-debug.log .eslintcache datasources.*.json diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index f3096aabb..1b9150053 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -1,5 +1,4 @@ const UserError = require('vn-loopback/util/user-error'); - module.exports = Self => { Self.remoteMethodCtx('downloadFile', { description: 'Download a document', @@ -34,29 +33,8 @@ module.exports = Self => { }); Self.downloadFile = async function(ctx, id) { - const storageConnector = Self.app.dataSources.storage.connector; - const models = Self.app.models; - const dms = await Self.findById(id); - - const hasReadRole = await models.DmsType.hasReadRole(ctx, dms.dmsTypeFk); - if (!hasReadRole) + if (!await Self.checkRole(ctx, id)) throw new UserError(`You don't have enough privileges`); - - const pathHash = storageConnector.getPathHash(dms.id); - try { - await models.Container.getFile(pathHash, dms.file); - } catch (e) { - if (e.code != 'ENOENT') - throw e; - - const error = new UserError(`File doesn't exists`); - error.statusCode = 404; - - throw error; - } - - const stream = models.Container.downloadStream(pathHash, dms.file); - - return [stream, dms.contentType, `filename="${dms.file}"`]; + return await Self.getFile(id); }; }; diff --git a/back/methods/dms/specs/downloadFile.spec.js b/back/methods/dms/specs/downloadFile.spec.js index 99820ed38..701a484df 100644 --- a/back/methods/dms/specs/downloadFile.spec.js +++ b/back/methods/dms/specs/downloadFile.spec.js @@ -11,7 +11,7 @@ describe('dms downloadFile()', () => { expect(result[1]).toEqual('text/plain'); }); - it(`should return an error for a user without enough privileges`, async() => { + it('should return an error for a user without enough privileges', async() => { let clientId = 101; let ctx = {req: {accessToken: {userId: clientId}}}; diff --git a/back/models/dms.js b/back/models/dms.js index 9a06928db..8be539a0f 100644 --- a/back/models/dms.js +++ b/back/models/dms.js @@ -1,6 +1,37 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { require('../methods/dms/downloadFile')(Self); require('../methods/dms/uploadFile')(Self); require('../methods/dms/removeFile')(Self); require('../methods/dms/updateFile')(Self); + + Self.checkRole = async function(ctx, id) { + const models = Self.app.models; + const dms = await Self.findById(id); + + return await models.DmsType.hasReadRole(ctx, dms.dmsTypeFk); + }; + + Self.getFile = async function(id) { + const storageConnector = Self.app.dataSources.storage.connector; + const models = Self.app.models; + const dms = await Self.findById(id); + const pathHash = storageConnector.getPathHash(dms.id); + try { + await models.Container.getFile(pathHash, dms.file); + } catch (e) { + if (e.code != 'ENOENT') + throw e; + + const error = new UserError(`File doesn't exists`); + error.statusCode = 404; + + throw error; + } + + const stream = models.Container.downloadStream(pathHash, dms.file); + + return [stream, dms.contentType, `filename="${dms.file}"`]; + }; }; diff --git a/back/models/specs/dms.spec.js b/back/models/specs/dms.spec.js new file mode 100644 index 000000000..8e76a4956 --- /dev/null +++ b/back/models/specs/dms.spec.js @@ -0,0 +1,53 @@ +const app = require('vn-loopback/server/server'); +describe('Dms', () => { + const Dms = app.models.Dms; + + describe('getFile()', () => { + it('should return a response with text content-type', async() => { + const result = await Dms.getFile(1); + + expect(result[1]).toEqual('text/plain'); + }); + + it('should return an error for a file does not exists', async() => { + let error = {}; + try { + await Dms.getFile(6); + } catch (e) { + error = e; + } + + expect(error.statusCode).toBe(404); + }); + + it('should return an error for a record does not exists', async() => { + let error = {}; + try { + await app.models.Dms.getFile('NotExistentId'); + } catch (e) { + error = e; + } + + expect(error.statusCode).not.toBe(404); + expect(error).toEqual(jasmine.any(Error)); + }); + }); + + describe('checkRole()', () => { + const dmsId = 1; + it('should return a true for an employee with permission', async() => { + let ctx = {req: {accessToken: {userId: 107}}}; + const result = await Dms.checkRole(ctx, dmsId); + + expect(result).toBeTruthy(); + }); + + it('should return false for an employee without permission', async() => { + let ctx = {req: {accessToken: {userId: 101}}}; + const result = await Dms.checkRole(ctx, dmsId); + + expect(result).toBeFalsy(); + }); + }); +}); + diff --git a/db/changes/10161-postValentineDay/00-borrame.sql b/db/changes/10161-postValentineDay/00-borrame.sql new file mode 100644 index 000000000..22d1f5dec --- /dev/null +++ b/db/changes/10161-postValentineDay/00-borrame.sql @@ -0,0 +1,4 @@ +ALTER TABLE `vn`.`workerDocument` +ADD COLUMN `isReadableByWorker` TINYINT(1) NOT NULL DEFAULT 0 AFTER `document`; + +UPDATE `vn`.`workerDocument` SET `isReadableByWorker` = '1' WHERE (`id` = '1'); diff --git a/db/changes/10162-fallas/00-acl.sql b/db/changes/10162-fallas/00-acl.sql new file mode 100644 index 000000000..376788af1 --- /dev/null +++ b/db/changes/10162-fallas/00-acl.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('WorkerLog', '*', 'READ', 'ALLOW', 'ROLE', 'hr'); diff --git a/db/changes/10162-fallas/00-workerLog.sql b/db/changes/10162-fallas/00-workerLog.sql new file mode 100644 index 000000000..730b60aa5 --- /dev/null +++ b/db/changes/10162-fallas/00-workerLog.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`workerLog` + ADD COLUMN `changedModel` VARCHAR(45) NULL DEFAULT NULL AFTER `description`, + ADD COLUMN `oldInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, + ADD COLUMN `newInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, + ADD COLUMN `changedModelId` int(11) DEFAULT NULL, + ADD COLUMN `changedModelValue` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL; \ No newline at end of file diff --git a/db/changes/10170-NOFallas/00-aclWorkerDms.sql b/db/changes/10170-NOFallas/00-aclWorkerDms.sql new file mode 100644 index 000000000..46e56f77e --- /dev/null +++ b/db/changes/10170-NOFallas/00-aclWorkerDms.sql @@ -0,0 +1,5 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES +('WorkerDms', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), +('WorkerDms', 'downloadFile', 'READ', 'ALLOW', 'ROLE', 'employee'); +DELETE FROM `salix`.`ACL` WHERE (`id` = '205'); diff --git a/db/changes/10170-NOFallas/00-zone_getEvents.sql b/db/changes/10170-NOFallas/00-zone_getEvents.sql new file mode 100644 index 000000000..991150db7 --- /dev/null +++ b/db/changes/10170-NOFallas/00-zone_getEvents.sql @@ -0,0 +1,119 @@ +USE `vn`; +DROP procedure IF EXISTS `zone_getEvents`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`( + vGeoFk INT, + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vGeoFk The geo id + * @param vAgencyModeFk The agency mode id + */ + DECLARE vDeliveryMethodFk VARCHAR(255); + + DROP TEMPORARY TABLE IF EXISTS tZone; + CREATE TEMPORARY TABLE tZone + (id INT PRIMARY KEY) + ENGINE = MEMORY; + + SELECT dm.`code` INTO vDeliveryMethodFk + FROM agencyMode am + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE am.id = vAgencyModeFk; + + IF vDeliveryMethodFk = 'PICKUP' THEN + INSERT INTO tZone + SELECT id + FROM zone + WHERE agencyModeFk = vAgencyModeFk; + ELSE + CALL zone_getFromGeo(vGeoFk); + + IF vAgencyModeFk IS NOT NULL THEN + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk = vAgencyModeFk; + ELSE + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); + END IF; + DROP TEMPORARY TABLE tmp.zone; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tZone t + JOIN zoneEvent e ON e.zoneFk = t.id; + + SELECT e.zoneFk, e.dated + FROM tZone t + JOIN zoneExclusion e ON e.zoneFk = t.id; + + DROP TEMPORARY TABLE tZone; +END$$ + +DELIMITER ; + +USE `vn`; +DROP procedure IF EXISTS `zone_getEvents__`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents__`( + vProvinceFk INT, + vPostCode VARCHAR(255), + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vAgencyModeFk The agency mode id + * @param vProvinceFk The province id + * @param vPostCode The postcode or %NULL to use the province + */ + + DECLARE vGeoFk INT; + + IF vPostCode IS NOT NULL THEN + SELECT p.geoFk INTO vGeoFk + FROM postCode p + JOIN town t ON t.id = p.townFk + WHERE p.`code` = vPostCode + AND t.provinceFk = vProvinceFk; + ELSE + SELECT geoFk INTO vGeoFk + FROM province + WHERE id = vProvinceFk; + END IF; + + CALL zone_getFromGeo(vGeoFk); + + IF vAgencyModeFk IS NOT NULL THEN + DELETE t FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk != vAgencyModeFk; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tmp.zone t + JOIN zoneEvent e ON e.zoneFk = t.id; + + SELECT e.zoneFk, e.dated + FROM tmp.zone t + JOIN zoneExclusion e ON e.zoneFk = t.id; + + DROP TEMPORARY TABLE tmp.zone; +END$$ + +DELIMITER ; + diff --git a/db/changes/10170-NOFallas/00-zone_getWarehouse.sql b/db/changes/10170-NOFallas/00-zone_getWarehouse.sql new file mode 100644 index 000000000..a65643ff5 --- /dev/null +++ b/db/changes/10170-NOFallas/00-zone_getWarehouse.sql @@ -0,0 +1,87 @@ +USE `vn`; +DROP procedure IF EXISTS `zone_getWarehouse`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) +BEGIN +/** + * Devuelve el listado de agencias disponibles para la fecha, + * dirección y almacén pasados. + * + * @param vAddress + * @param vWarehouse warehouse + * @param vLanded Fecha de recogida + * @select Listado de agencias disponibles + */ + + CALL zone_getFromGeo(address_getGeo(vAddress)); + CALL zone_getOptionsForLanding(vLanded, FALSE); + + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, + am.deliveryMethodFk, + TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, + zw.warehouseFk, + z.id zoneFk + FROM tmp.zoneOption zo + JOIN zone z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk + WHERE zw.warehouseFk = vWarehouse + GROUP BY z.agencyModeFk + ORDER BY agencyMode; + + DROP TEMPORARY TABLE + tmp.zone, + tmp.zoneOption; + +END$$ + +DELIMITER ; + +USE `vn`; +DROP procedure IF EXISTS `zone_getWarehouse__`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse__`(vAddress INT, vLanded DATE, vWarehouse INT) +BEGIN +/** + * Devuelve el listado de agencias disponibles para la fecha, + * dirección y almacén pasados. + * + * @param vAddress + * @param vWarehouse warehouse + * @param vLanded Fecha de recogida + * @select Listado de agencias disponibles + */ + + CALL zone_getFromGeo(address_getGeo(vAddress)); + CALL zone_getOptionsForLanding(vLanded, FALSE); + + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, + am.deliveryMethodFk, + TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, + zw.warehouseFk, + z.id zoneFk + FROM tmp.zoneOption zo + JOIN zone z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk + WHERE zw.warehouseFk + GROUP BY z.agencyModeFk + ORDER BY agencyMode; + + DROP TEMPORARY TABLE + tmp.zone, + tmp.zoneOption; + +END$$ + +DELIMITER ; + + diff --git a/db/changes/10180-holyWeek/00-ticketWeekly.sql b/db/changes/10180-holyWeek/00-ticketWeekly.sql new file mode 100644 index 000000000..05d65e124 --- /dev/null +++ b/db/changes/10180-holyWeek/00-ticketWeekly.sql @@ -0,0 +1,13 @@ +ALTER TABLE `vn`.`ticketWeekly` +ADD COLUMN `agencyModeFk` INT(11) NULL DEFAULT NULL AFTER `weekDay`, +ADD INDEX `agencyModeFk_idx` (`agencyModeFk` ASC); + +ALTER TABLE `vn`.`ticketWeekly` +ADD CONSTRAINT `agencyModeFk` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `vn`.`agencyMode` (`id`) + ON DELETE SET NULL + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`ticketWeekly` +CHANGE COLUMN `weekDay` `weekDay` TINYINT(1) NOT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6' ; diff --git a/db/changes/10180-holyWeek/00-ticket_cloneWeekly.sql b/db/changes/10180-holyWeek/00-ticket_cloneWeekly.sql new file mode 100644 index 000000000..544296feb --- /dev/null +++ b/db/changes/10180-holyWeek/00-ticket_cloneWeekly.sql @@ -0,0 +1,130 @@ +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_cloneWeekly`(IN vWeek INT) +BEGIN + DECLARE vIsDone BOOL; + DECLARE vLanding DATE; + DECLARE vShipment DATE; + DECLARE vWarehouse INT; + DECLARE vTicket INT; + DECLARE vWeekDay INT; + DECLARE vClient INT; + DECLARE vEmpresa INT; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewTicket INT; + DECLARE vYear INT; + + DECLARE rsTicket CURSOR FOR + SELECT tw.ticketFk, weekDay, t.clientFk, t.warehouseFk, t.companyFk, t.addressFk, tw.agencyModeFk + FROM ticketWeekly tw + JOIN ticket t ON tt.ticketFk = t.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; + + SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0); + + OPEN rsTicket; + + myLoop: LOOP + BEGIN + DECLARE vError TEXT; + DECLARE vSalesPersonEmail VARCHAR(150); + DECLARE vMailSent BOOL; + DECLARE vSubject VARCHAR(150); + DECLARE vMessage TEXT; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + vError = MESSAGE_TEXT; + + END; + + SET vIsDone = FALSE; + FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk; + + IF vIsDone THEN + + LEAVE myLoop; + END IF; + SELECT date INTO vShipment + FROM `time` + WHERE `year` = vYear AND `week` = vWeek + AND WEEKDAY(date) = vWeekDay; + + -- busca si el ticket ya ha sido clonado + IF (SELECT COUNT(*) FROM vn.ticket tOrig + JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk + JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id + JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk + JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk + WHERE tOrig.id = vTicket AND DATE(tClon.shipped) = vShipment) > 0 + THEN + ITERATE myLoop; + END IF; + CALL vn.zone_getLanded(vShipment, vAddressFk, vAgencyModeFk, vWarehouse); + + SELECT landed INTO vLanding from tmp.zoneGetLanded LIMIT 1; + + CALL vn.ticketCreateWithoutZone(vClient, vShipment, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk, NULL, vLanding, account.userGetId(), vNewTicket); + + IF (vLanding IS NULL) THEN + + SELECT e.email INTO vSalesPersonEmail + FROM vn.client c + JOIN vn.worker sp ON sp.id = c.salesPersonFk + JOIN account.emailUser e ON e.userFk = sp.userFk + WHERE c.id = vClient; + + SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicket, + ' para el dia: ', vShipment); + SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicket, + ' para el dia: ', vShipment, + ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket, + ' pero ha que revisar las fechas y la agencia'); + + SELECT COUNT(*) INTO vMailSent + FROM vn.mail + WHERE sender = vSalesPersonEmail + AND subject = vSubject; + + IF NOT vMailSent THEN + INSERT INTO vn.mail (sender,`subject`,body) + VALUES (vSalesPersonEmail, vSubject, vMessage); + END IF; + CALL vn.ticketStateUpdate (vNewTicket, 'FIXING'); + END IF; + + INSERT INTO vn.sale (ticketFk, itemFk, concept, quantity, price, discount, priceFixed, isPriceFixed) + SELECT vNewTicket, saleOrig.itemFk , saleOrig.concept , saleOrig.quantity, saleOrig.price , saleOrig.discount, saleOrig.priceFixed, saleOrig.isPriceFixed + FROM vn.ticket tOrig + JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk + LEFT JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id + LEFT JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk + LEFT JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk AND DATE(tClon.shipped) = vShipment + WHERE tOrig.id = vTicket AND saleClon.id IS NULL; + + INSERT IGNORE INTO vn.saleCloned(saleOriginalFk, saleClonedFk) + SELECT saleOriginal.id, saleClon.id + FROM vn.sale saleOriginal + JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity + WHERE saleOriginal.ticketFk = vTicket AND saleClon.ticketFk = vNewTicket; + + INSERT INTO ticketRequest (description, ordered, shipped, salesPersonCode, buyerCode, quantity, price, + itemFk ,clientFk, response, total, buyed, saleFk) + SELECT tr.description, tr.ordered, tr.shipped, tr.salesPersonCode, tr.buyerCode, tr.quantity, tr.price, + tr.itemFk, tr.clientFk, tr.response, tr.total, tr.buyed, tr.saleFk + FROM sale s JOIN ticketRequest tr ON tr.saleFk = s.id + JOIN sale s2 ON s.concept = s2.concept AND s.quantity = s2.quantity AND m.Id_Article = m2.Id_Article + WHERE s.ticketFk = vTicket AND s2.ticketFk = vNewTicket; + + CALL vn.ticketCalculateClon(vNewTicket, vTicket); + END; + END LOOP; + + CLOSE rsTicket; + +END$$ + +DELIMITER ; + diff --git a/db/changes/10180-holyWeek/01-migrateFromTicketToTicketWeekly.sql b/db/changes/10180-holyWeek/01-migrateFromTicketToTicketWeekly.sql new file mode 100644 index 000000000..939a8e73c --- /dev/null +++ b/db/changes/10180-holyWeek/01-migrateFromTicketToTicketWeekly.sql @@ -0,0 +1,6 @@ +UPDATE vn.ticketWeekly tw + JOIN vn.ticket t ON t.id = tw.ticketFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk +SET tw.agencyModeFk = t.agencyModeFk +WHERE am.name NOT LIKE '%turno%'; + diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index fbe33159a..792787154 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -101,6 +101,16 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare (1, 'First sector', 1, 1, 'FIRST', 999, 999), (2, 'Second sector', 2, 0, 'SECOND', 100, 150); +INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) + VALUES + ('1', '700', '01', '1', '700-01', '70001'), + ('2', '700', '02', '2', '700-02', '70002'); + +INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`) + VALUES + ('GVC', '1', '0', '1', '0', '106'), + ('HEJ', '2', '0', '1', '0', '106'); + INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) VALUES (1, 'Main Warehouse'); @@ -156,7 +166,7 @@ UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Silla247Expensive'; UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Refund'; UPDATE `vn`.`agencyMode` SET `id` = 10 WHERE `name` = 'Other agency'; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 1; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 3 WHERE `id` = 1; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 3; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 4; @@ -471,19 +481,19 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `m3Max`) VALUES - (1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, 30.50), - (2, 'Zone pickup B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, 30.50), - (3, 'Zone 247 A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 7, 1, 2, 0, 40.50), - (4, 'Zone 247 B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 7, 1, 2, 0, 40.50), - (5, 'Zone expensive A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 8, 1, 1000, 0, 50.50), - (6, 'Zone expensive B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 8, 1, 1000, 0, 50.50), - (7, 'Zone refund', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 23, 0, 0, 0, 60.50), - (8, 'Zone others', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 10, 0, 0, 0, 60.50), - (9, 'Zone superMan', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 2, 0, 0, 0, NULL), - (10, 'Zone teleportation', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 3, 0, 0, 0, NULL), - (11, 'Zone pickup C', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, NULL), - (12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 4, 0, 0, 0, NULL), - (13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 5, 0, 0, 0, NULL); + (1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 30.50), + (2, 'Zone pickup B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 30.50), + (3, 'Zone 247 A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 40.50), + (4, 'Zone 247 B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 40.50), + (5, 'Zone expensive A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 50.50), + (6, 'Zone expensive B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 50.50), + (7, 'Zone refund', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 60.50), + (8, 'Zone others', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 60.50), + (9, 'Zone superMan', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 2, 0, 0, 0, NULL), + (10, 'Zone teleportation', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 3, 0, 0, 0, NULL), + (11, 'Zone pickup C', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, NULL), + (12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 4, 0, 0, 0, NULL), + (13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 5, 0, 0, 0, NULL); INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) VALUES @@ -554,6 +564,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (10, 23, 4, 'Reclama ticket: 8'), (11, 24, 4, 'Reclama ticket: 7'); +-- FIX for state hours on local, inter_afterInsert +UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND); + + INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) VALUES (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), @@ -928,6 +942,18 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) (32, 36, -92.324), (32, 39, 0.994); +INSERT INTO `vn`.`itemShelving` (`id`, `itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`) + VALUES + ('1', '2', 'GVC', 'A', '0', '1', '1', '1', '1', '1', '1', '106'), + ('2', '4', 'HEJ', 'A', '0', '2', '1', '1', '1', '1', '1', '106'); + +INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) + VALUES + ('1', '1', '1', '', '106'), + ('2', '2', '5', '', '106'), + ('1', '7', '1', '', '106'), + ('2', '8', '5', '', '106'); + INSERT INTO `vncontrol`.`accion`(`accion_id`, `accion`) VALUES (3, 'ACTION ONE'), @@ -1913,14 +1939,10 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) (7, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)), (7, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)), (7, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), - (7, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)), - (8, 'day', CURDATE()), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); + (7, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); + +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`) + VALUES (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`) VALUES @@ -1954,11 +1976,13 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES - (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), - (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', CURDATE()), - (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE()), - (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', CURDATE()), - (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', CURDATE()); + (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), + (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', CURDATE()), + (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE()), + (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', CURDATE()), + (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', CURDATE()), + (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', CURDATE()); + INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) VALUES @@ -1969,9 +1993,10 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`) (104, 2), (104, 3); -INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`) +INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`) VALUES - (1, 106, 4); + (1, 106, 4, TRUE), + (2, 107, 3, FALSE); INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`) VALUES diff --git a/e2e/dms/a87/4.txt b/e2e/dms/a87/4.txt new file mode 100644 index 000000000..a46bfbeda --- /dev/null +++ b/e2e/dms/a87/4.txt @@ -0,0 +1 @@ +File: 4.txt. It works! \ No newline at end of file diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 5fe362043..636819860 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -1,4 +1,3 @@ -import {url as defaultURL} from './config'; function checkVisibility(selector) { let selectorMatches = document.querySelectorAll(selector); @@ -59,19 +58,31 @@ let actions = { return document.location.hash.includes(expectedHash); }, {}, expectedHash); } catch (error) { - throw new Error(`failed to reach URL containing: ${expectedHash}`); + throw new Error(`Failed to reach URL containing: ${expectedHash}`); } - await this.waitForContentLoaded(); + await this.waitForSpinnerLoad(); return true; }, - waitUntilNotPresent: async function(selector) { - await this.wait(selector => { - return document.querySelector(selector) == null; - }, selector); - }, - doLogin: async function(userName, password = 'nightmare') { + let state = await this.getState(); + + if (state != 'login') { + try { + await this.gotoState('login'); + } catch (err) { + let dialog = await this.evaluate( + () => document.querySelector('button[response="accept"]')); + + if (dialog) + await this.waitToClick('button[response="accept"]'); + else + throw err; + } + } + + await this.waitForState('login'); + await this.waitForSelector(`vn-login vn-textfield[ng-model="$ctrl.user"]`, {visible: true}); await this.clearInput(`vn-login vn-textfield[ng-model="$ctrl.user"]`); await this.write(`vn-login vn-textfield[ng-model="$ctrl.user"]`, userName); @@ -81,27 +92,14 @@ let actions = { }, login: async function(userName) { - await this.goto(`${defaultURL}/#!/login`); - let dialog = await this.evaluate(() => { - return document.querySelector('button[response="accept"]'); - }); - if (dialog) - await this.waitToClick('button[response="accept"]'); - await this.doLogin(userName); - await this.waitForFunction(() => { - return document.location.hash === '#!/'; - }, {}); + await this.waitForState('home'); }, selectModule: async function(moduleName) { - let snakeName = moduleName.replace(/[\w]([A-Z])/g, m => { - return m[0] + '-' + m[1]; - }).toLowerCase(); - - let selector = `vn-home a[ui-sref="${moduleName}.index"]`; - await this.waitToClick(selector); - await this.expectURL(snakeName); + let state = `${moduleName}.index`; + await this.waitToClick(`vn-home a[ui-sref="${state}"]`); + await this.waitForState(state); }, loginAndModule: async function(userName, moduleName) { @@ -109,56 +107,85 @@ let actions = { await this.selectModule(moduleName); }, - datePicker: async function(selector, changeMonth, day) { - let date = new Date(); - if (changeMonth) date.setMonth(date.getMonth() + changeMonth); - date.setDate(day ? day : 16); - date = date.toISOString().substr(0, 10); - - await this.wait(selector); - await this.evaluate((selector, date) => { - let input = document.querySelector(selector).$ctrl.input; - input.value = date; - input.dispatchEvent(new Event('change')); - }, selector, date); + getState: async function() { + return await this.evaluate(() => { + let $state = angular.element(document.body).injector().get('$state'); + return $state.current.name; + }); }, - pickTime: async function(selector, time) { - await this.wait(selector); - await this.evaluate((selector, time) => { - let input = document.querySelector(selector).$ctrl.input; - input.value = time; - input.dispatchEvent(new Event('change')); - }, selector, time); + gotoState: async function(state, params) { + await this.evaluate((state, params) => { + let $state = angular.element(document.body).injector().get('$state'); + return $state.go(state, params); + }, state, params); + await this.waitForSpinnerLoad(); }, - clearTextarea: async function(selector) { - await this.waitForSelector(selector, {visible: true}); - await this.evaluate(inputSelector => { - return document.querySelector(`${inputSelector} textarea`).value = ''; - }, selector); + waitForState: async function(state) { + await this.waitFor(state => { + let $state = angular.element(document.body).injector().get('$state'); + return !$state.transition && $state.is(state); + }, {}, state); + await this.waitForSpinnerLoad(); }, - clearInput: async function(selector) { - await this.waitForSelector(selector); + waitForTransition: async function() { + await this.waitFor(() => { + const $state = angular.element(document.body).injector().get('$state'); + return !$state.transition; + }); + await this.waitForSpinnerLoad(); + }, - let field = await this.evaluate(selector => { - return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field; - }, selector); + accessToSection: async function(state) { + await this.waitForSelector('vn-left-menu'); + let nested = await this.evaluate(state => { + return document.querySelector(`vn-left-menu li li > a[ui-sref="${state}"]`) != null; + }, state); - if ((field != null && field != '') || field == '0') { - let coords = await this.evaluate(selector => { - let rect = document.querySelector(selector).getBoundingClientRect(); - return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width}; + if (nested) { + let selector = 'vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]'; + await this.evaluate(selector => { + document.querySelector(selector).scrollIntoViewIfNeeded(); }, selector); - await this.mouse.move(coords.x, coords.y); - await this.waitForSelector(`${selector} [icon="clear"]`, {visible: true}); - await this.waitToClick(`${selector} [icon="clear"]`); + await this.waitToClick(selector); + await this.wait('vn-left-menu .expanded'); } - await this.evaluate(selector => { - return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field == ''; - }, selector); + await this.evaluate(state => { + let navButton = document.querySelector(`vn-left-menu li > a[ui-sref="${state}"]`); + navButton.scrollIntoViewIfNeeded(); + return navButton.click(); + }, state); + + await this.waitForState(state); + }, + + reloadSection: async function(state) { + await this.click('vn-icon[icon="desktop_windows"]'); + await this.accessToSection(state); + }, + + forceReloadSection: async function(sectionRoute) { + await this.waitToClick('vn-icon[icon="desktop_windows"]'); + await this.waitToClick('button[response="accept"]'); + await this.wait('vn-card.summary'); + await this.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); + }, + + doSearch: async function(searchValue) { + await this.clearInput('vn-searchbar'); + if (searchValue) + await this.write('vn-searchbar', searchValue); + + await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); + await this.waitForTransition(); + }, + + accessToSearchResult: async function(searchValue) { + await this.doSearch(searchValue); + await this.waitFor('.vn-descriptor'); }, getProperty: async function(selector, property) { @@ -167,6 +194,12 @@ let actions = { }, selector, property); }, + getClassName: async function(selector) { + const element = await this.$(selector); + const handle = await element.getProperty('className'); + return await handle.jsonValue(); + }, + waitPropertyLength: async function(selector, property, minLength) { await this.waitForFunction((selector, property, minLength) => { const element = document.querySelector(selector); @@ -214,6 +247,11 @@ let actions = { await this.waitForTextInField(selector, text); }, + overwrite: async function(selector, text) { + await this.clearInput(selector); + await this.write(selector, text); + }, + waitToClick: async function(selector) { await this.waitForSelector(selector); await this.waitForFunction(checkVisibility, {}, selector); @@ -320,66 +358,102 @@ let actions = { }, hideSnackbar: async function() { - await this.waitFor(750); // holds up for the snackbar to be visible for a small period of time. + // Holds up for the snackbar to be visible for a small period of time. + if (process.env.E2E_DEBUG) + await this.waitFor(300); + await this.evaluate(() => { - let hideButton = document.querySelector('#shapes .shown button'); + let hideButton = document + .querySelector('vn-snackbar .shape.shown button'); if (hideButton) - return document.querySelector('#shapes .shown button').click(); + return hideButton.click(); }); + await this.waitFor('vn-snackbar .shape.shown', {hidden: true}); }, - waitForLastSnackbar: async function() { - const selector = 'vn-snackbar .shown .text'; - + waitForSnackbar: async function() { + const selector = 'vn-snackbar .shape.shown'; await this.waitForSelector(selector); - let snackBarText = await this.evaluate(selector => { + + let message = await this.evaluate(selector => { const shape = document.querySelector(selector); + const message = { + text: shape.querySelector('.text').innerText + }; - return shape.innerText; + const types = ['error', 'success']; + for (let type of types) { + if (shape.classList.contains(type)) { + message.type = type; + break; + } + } + + return message; }, selector); + await this.hideSnackbar(); - return snackBarText; + return message; }, - accessToSearchResult: async function(searchValue) { - await this.clearInput('vn-searchbar'); - await this.write('vn-searchbar', searchValue); - await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); - await this.waitForContentLoaded(); + pickDate: async function(selector, date) { + date = date || new Date(); + + const tzoffset = date.getTimezoneOffset() * 60000; + const localIso = (new Date(date.getTime() - tzoffset)) + .toISOString(); + + await this.wait(selector); + await this.evaluate((selector, localIso) => { + let input = document.querySelector(selector).$ctrl.input; + input.value = localIso.substr(0, 10); + input.dispatchEvent(new Event('change')); + }, selector, localIso); }, - accessToSection: async function(sectionRoute) { - await this.waitForSelector('vn-left-menu'); - let nested = await this.evaluate(sectionRoute => { - return document.querySelector(`vn-left-menu li li > a[ui-sref="${sectionRoute}"]`) != null; - }, sectionRoute); + pickTime: async function(selector, time) { + await this.wait(selector); + await this.evaluate((selector, time) => { + let input = document.querySelector(selector).$ctrl.input; + input.value = time; + input.dispatchEvent(new Event('change')); + }, selector, time); + }, - if (nested) { - await this.waitToClick('vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]'); - await this.wait('vn-left-menu .expanded'); + clearTextarea: async function(selector) { + await this.waitForSelector(selector, {visible: true}); + await this.evaluate(inputSelector => { + return document.querySelector(`${inputSelector} textarea`).value = ''; + }, selector); + }, + + clearInput: async function(selector) { + await this.waitForSelector(selector); + + let field = await this.evaluate(selector => { + return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field; + }, selector); + + if ((field != null && field != '') || field == '0') { + let coords = await this.evaluate(selector => { + let rect = document.querySelector(selector).getBoundingClientRect(); + return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width}; + }, selector); + await this.mouse.move(coords.x, coords.y); + await this.waitForSelector(`${selector} [icon="clear"]`, {visible: true}); + await this.waitToClick(`${selector} [icon="clear"]`); } - await this.evaluate(sectionRoute => { - let navButton = document.querySelector(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); - navButton.scrollIntoViewIfNeeded(); - return navButton.click(); - }, sectionRoute); - await this.waitForNavigation({waitUntil: ['networkidle0']}); - await this.waitForContentLoaded(); + await this.evaluate(selector => { + return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field == ''; + }, selector); }, autocompleteSearch: async function(selector, searchValue) { let builtSelector = await this.selectorFormater(selector); - await this.waitForContentLoaded(); await this.waitToClick(selector); - await this.waitForSelector(selector => { - document - .querySelector(`${selector} vn-drop-down`).$ctrl.content - .querySelectorAll('li'); - }, selector); - - await this.write('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield', searchValue); + await this.write('.vn-drop-down.shown vn-textfield', searchValue); try { await this.waitForFunction((selector, searchValue) => { @@ -391,7 +465,7 @@ let actions = { }, {}, selector, searchValue); } catch (error) { let inputValue = await this.evaluate(() => { - return document.querySelector('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield input').value; + return document.querySelector('.vn-drop-down.shown vn-textfield input').value; }); throw new Error(`${builtSelector} value is ${inputValue}! ${error}`); } @@ -401,29 +475,7 @@ let actions = { .includes(searchValue.toLowerCase()); }, {}, builtSelector, searchValue); - await this.waitForMutation('.vn-drop-down', 'childList'); - await this.waitForContentLoaded(); - }, - - reloadSection: async function(sectionRoute) { - await this.waitForContentLoaded(); - await Promise.all([ - this.waitForNavigation({waitUntil: 'networkidle0'}), - this.click('vn-icon[icon="desktop_windows"]', {}), - ]); - - await Promise.all([ - this.waitForNavigation({waitUntil: 'networkidle0'}), - this.click(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`, {}), - ]); - await this.waitForContentLoaded(); - }, - - forceReloadSection: async function(sectionRoute) { - await this.waitToClick('vn-icon[icon="desktop_windows"]'); - await this.waitToClick('button[response="accept"]'); - await this.wait('vn-card.summary'); - await this.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); + await this.waitFor('.vn-drop-down', {hidden: true}); }, checkboxState: async function(selector) { @@ -457,7 +509,7 @@ let actions = { }, waitForSpinnerLoad: async function() { - await this.waitUntilNotPresent('vn-topbar vn-spinner'); + await this.waitFor('vn-topbar vn-spinner', {hidden: true}); }, waitForWatcherData: async function(selector) { @@ -509,35 +561,42 @@ let actions = { closePopup: async function(selector) { await Promise.all([ this.keyboard.press('Escape'), - this.waitForSelector('.vn-popup', {hidden: true}), + this.waitFor('.vn-popup', {hidden: true}), ]); }, - waitForContentLoaded: async function() { - await this.waitFor(1000); - }, - respondToDialog: async function(response) { - await this.waitForSelector('.vn-dialog.vn-popup.shown'); + await this.waitForSelector('.vn-dialog.shown'); const firstCount = await this.evaluate(text => { - const dialogs = document.querySelectorAll('.vn-dialog.vn-popup'); + const dialogs = document.querySelectorAll('.vn-dialog'); const dialogOnTop = dialogs[dialogs.length - 1]; const button = dialogOnTop.querySelector(`div.buttons [response="${text}"]`); button.click(); return dialogs.length; }, response); - this.waitForFunction(firstCount => { - const dialogs = document.querySelectorAll('.vn-dialog.vn-popup'); + await this.waitForFunction(firstCount => { + const dialogs = document.querySelectorAll('.vn-dialog'); return dialogs.length < firstCount; }, {}, firstCount); + }, + + waitForContentLoaded: async function() { + await this.waitForSpinnerLoad(); } }; export function extendPage(page) { for (let name in actions) { page[name] = async(...args) => { - return await actions[name].call(page, ...args); + try { + return await actions[name].apply(page, args); + } catch (err) { + let stringArgs = args + .map(i => typeof i == 'function' ? 'Function' : i) + .join(', '); + throw new Error(`.${name}(${stringArgs}): ${err.message}`); + } }; } diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index 1ca0726c0..02ef82b1b 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -4,16 +4,26 @@ import {extendPage} from './extensions'; import {url as defaultURL} from './config'; export async function getBrowser() { - let headless = !process.env.E2E_SHOW; + const args = [ + `--no-sandbox`, + `--window-size=${ 1920 },${ 1080 }` + ]; + + let env = process.env; + + if (env.E2E_DEBUG) { + args.push('--auto-open-devtools-for-tabs'); + env.E2E_SHOW = true; + } + + const headless = !env.E2E_SHOW; const browser = await Puppeteer.launch({ - args: [ - '--no-sandbox', - `--window-size=${ 1920 },${ 1080 }` - ], + args, defaultViewport: null, headless: headless, slowMo: 0, // slow down by ms }); + let page = (await browser.pages())[0]; await page.evaluateOnNewDocument(() => { Object.defineProperty(navigator, 'language', { @@ -28,8 +38,8 @@ export async function getBrowser() { }); }); page = extendPage(page); - page.setDefaultTimeout(10000); - await page.goto(defaultURL, {waitUntil: 'networkidle0'}); + page.setDefaultTimeout(4000); + await page.goto(defaultURL, {waitUntil: 'load'}); return {page, close: browser.close.bind(browser)}; } diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 0cee79405..551573836 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -2,6 +2,8 @@ export default { globalItems: { applicationsMenuButton: '#apps', + userMenuButton: '#user', + logoutButton: '#logout', applicationsMenuVisible: '.modules-menu', clientsButton: '.modules-menu > li[ui-sref="client.index"]', itemsButton: '.modules-menu > li[ui-sref="item.index"]', @@ -10,7 +12,6 @@ export default { claimsButton: '.modules-menu > li[ui-sref="claim.index"]', returnToModuleIndexButton: 'a[ui-sref="order.index"]', homeButton: 'vn-topbar > div.side.start > a', - userMenuButton: '#user', userLocalWarehouse: '.user-popover vn-autocomplete[ng-model="$ctrl.localWarehouseFk"]', userLocalBank: '.user-popover vn-autocomplete[ng-model="$ctrl.localBankFk"]', userLocalCompany: '.user-popover vn-autocomplete[ng-model="$ctrl.localCompanyFk"]', @@ -99,7 +100,6 @@ export default { receivedCoreVNLCheckbox: 'vn-client-billing-data vn-check[label="Received core VNL"]', receivedB2BVNLCheckbox: 'vn-client-billing-data vn-check[label="Received B2B VNL"]', swiftBic: 'vn-client-billing-data vn-autocomplete[ng-model="$ctrl.client.bankEntityFk"]', - clearswiftBicButton: 'vn-client-billing-data vn-autocomplete[ng-model="$ctrl.client.bankEntityFk"] .icons > vn-icon[icon=clear]', newBankEntityButton: 'vn-client-billing-data vn-icon-button[vn-tooltip="New bank entity"] > button', newBankEntityName: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newBankEntity.name"]', newBankEntityBIC: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newBankEntity.bic"]', @@ -178,12 +178,11 @@ export default { }, clientBalance: { - balanceButton: 'vn-left-menu a[ui-sref="client.card.balance.index"]', company: 'vn-client-balance-index vn-autocomplete[ng-model="$ctrl.companyId"]', newPaymentButton: `vn-float-button`, newPaymentBank: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]', newPaymentAmount: '.vn-dialog.shown vn-input-number[ng-model="$ctrl.receipt.amountPaid"]', - saveButton: '.vn-dialog.shown vn-button[label="Save"]', + saveButton: '.vn-dialog.shown [response="accept"]', firstBalanceLine: 'vn-client-balance-index vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(8)' }, @@ -208,7 +207,7 @@ export default { createItemButton: `vn-float-button`, firstSearchResult: 'vn-item-index a:nth-child(1)', searchResult: 'vn-item-index a.vn-tr', - searchResultPreviewButton: 'vn-item-index .buttons > [icon="desktop_windows"]', + firstResultPreviewButton: 'vn-item-index vn-tbody > :nth-child(1) .buttons > [icon="desktop_windows"]', searchResultCloneButton: 'vn-item-index .buttons > [icon="icon-clone"]', acceptClonationAlertButton: '.vn-confirm.shown [response="accept"]', topbarSearch: 'vn-topbar', @@ -260,7 +259,6 @@ export default { secondRequestDecline: 'vn-item-request vn-tbody > vn-tr:nth-child(1) vn-icon-button[icon="thumb_down"]', declineReason: 'vn-textarea[ng-model="$ctrl.denyObservation"]', acceptDeclineReason: 'button[response="accept"]', - }, itemBasicData: { basicDataButton: 'vn-left-menu a[ui-sref="item.card.basicData"]', @@ -339,8 +337,8 @@ export default { }, itemDiary: { secondTicketId: 'vn-item-diary vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(2) > span', + fourthBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(4) > vn-td.balance > span', firstBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(1) > vn-td.balance', - fourthBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(4) > vn-td.balance', warehouse: 'vn-item-diary vn-autocomplete[ng-model="$ctrl.warehouseFk"]', }, itemLog: { @@ -353,14 +351,14 @@ export default { route: 'vn-ticket-summary vn-label-value[label="Route"] > section > span > span', total: 'vn-ticket-summary vn-one.taxes > p:nth-child(3) > strong', sale: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr', - firstSaleItemId: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', + firstSaleItemId: 'vn-ticket-summary [name="sales"] vn-table vn-tbody > :nth-child(1) > vn-td:nth-child(2) > span', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor', itemDescriptorPopoverItemDiaryButton: 'vn-item-descriptor a[href="#!/item/2/diary?warehouseFk=5&ticketFk=20"]', popoverDiaryButton: '.vn-popover.shown vn-item-descriptor vn-icon[icon="icon-transaction"]', firstSaleQuantity: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3)', firstSaleDiscount: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6)', - invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(6) > section > span', + invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(7) > section > span', setOk: 'vn-ticket-summary vn-button[label="SET OK"] > button' }, ticketsIndex: { @@ -368,16 +366,23 @@ export default { advancedSearchInvoiceOut: 'vn-ticket-search-panel vn-textfield[ng-model="filter.refFk"]', newTicketButton: 'vn-ticket-index a', searchResult: 'vn-ticket-index vn-card > vn-table > div > vn-tbody > a.vn-tr', + secondTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(2) > vn-td:nth-child(1) > vn-check', + thirdTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(3) > vn-td:nth-child(1) > vn-check', + sixthTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(6) > vn-td:nth-child(1) > vn-check', + payoutButton: 'vn-ticket-index vn-button[icon="icon-recovery"]', + payoutCompany: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.companyFk"]', + payoutBank: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]', + submitPayout: '.vn-dialog button[response="accept"]', searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', - searchResultDate: 'vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(5)', + searchResultDate: 'vn-ticket-summary [label=Landed] span', topbarSearch: 'vn-searchbar', advancedSearchButton: 'vn-ticket-search-panel button[type=submit]', searchButton: 'vn-searchbar vn-icon[icon="search"]', - searchWeeklyButton: 'vn-searchbar vn-icon[icon="search"]', moreMenu: 'vn-ticket-index vn-icon-menu[icon=more_vert]', sixthWeeklyTicket: 'vn-ticket-weekly-index vn-table vn-tr:nth-child(6)', weeklyTicket: 'vn-ticket-weekly-index vn-table > div > vn-tbody > vn-tr', firstWeeklyTicketDeleteIcon: 'vn-ticket-weekly-index vn-tr:nth-child(1) vn-icon-button[icon="delete"]', + firstWeeklyTicketAgency: 'vn-ticket-weekly-index vn-tr:nth-child(1) [ng-model="weekly.agencyModeFk"]', acceptDeleteTurn: '.vn-confirm.shown button[response="accept"]' }, createTicketView: { @@ -430,7 +435,6 @@ export default { firstQuantity: 'vn-ticket-package vn-horizontal:nth-child(1) vn-input-number[ng-model="package.quantity"]', firstRemovePackageButton: 'vn-icon-button[vn-tooltip="Remove package"]', addPackageButton: 'vn-icon-button[vn-tooltip="Add package"]', - clearPackageAutocompleteButton: 'vn-autocomplete[label="Package"] .icons > vn-icon[icon=clear]', savePackagesButton: `button[type=submit]` }, ticketSales: { @@ -455,7 +459,6 @@ export default { firstSaleZoomedImage: 'body > div > div > img', firstSaleQuantity: 'vn-ticket-sale [ng-model="sale.quantity"]', firstSaleQuantityCell: 'vn-ticket-sale vn-tr:nth-child(1) > vn-td-editable:nth-child(5)', - firstSaleQuantityClearInput: 'vn-textfield[ng-model="sale.quantity"] div.suffix > i', firstSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > vn-autocomplete', firstSalePrice: 'vn-ticket-sale vn-table vn-tr:nth-child(1) > vn-td:nth-child(7) > span', firstSalePriceInput: '.vn-popover.shown [ng-model="$ctrl.editedPrice"]', @@ -485,7 +488,6 @@ export default { deleteSaleButton: 'vn-ticket-sale vn-tool-bar > vn-button[icon="delete"]', transferSaleButton: 'vn-ticket-sale vn-tool-bar > vn-button[icon="call_split"]', moveToTicketInput: '.vn-popover.shown vn-textfield[ng-model="$ctrl.transfer.ticketId"]', - moveToTicketInputClearButton: '.vn-popover.shown i[title="Clear"]', moveToTicketButton: '.vn-popover.shown vn-icon[icon="arrow_forward_ios"]', moveToNewTicketButton: '.vn-popover.shown vn-button[label="New ticket"]', acceptDeleteLineButton: '.vn-confirm.shown button[response=accept]', @@ -539,8 +541,8 @@ export default { firstPrice: 'vn-ticket-service vn-horizontal:nth-child(1) vn-input-number[ng-model="service.price"]', firstVatType: 'vn-ticket-service vn-autocomplete[label="Tax class"]', fistDeleteServiceButton: 'vn-ticket-service form vn-horizontal:nth-child(1) vn-icon-button[icon="delete"]', - newServiceTypeName: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newServiceType.name"]', - newServiceTypeExpense: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.newServiceType.expenseFk"]', + newServiceTypeName: '.vn-dialog.shown vn-textfield[ng-model="newServiceType.name"]', + newServiceTypeExpense: '.vn-dialog.shown vn-autocomplete[ng-model="newServiceType.expenseFk"]', serviceLine: 'vn-ticket-service > form > vn-card > vn-one:nth-child(2) > vn-horizontal', saveServiceButton: 'button[type=submit]', saveServiceTypeButton: '.vn-dialog.shown tpl-buttons > button' @@ -548,7 +550,6 @@ export default { createStateView: { state: 'vn-autocomplete[ng-model="$ctrl.stateFk"]', worker: 'vn-autocomplete[ng-model="$ctrl.workerFk"]', - clearStateInputButton: 'vn-autocomplete[ng-model="$ctrl.stateFk"] .icons > vn-icon[icon=clear]', saveStateButton: `button[type=submit]` }, claimsIndex: { diff --git a/e2e/paths/01-login/01_login.spec.js b/e2e/paths/01-login/01_login.spec.js index abb022011..ed507df4e 100644 --- a/e2e/paths/01-login/01_login.spec.js +++ b/e2e/paths/01-login/01_login.spec.js @@ -1,3 +1,4 @@ +import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; describe('Login path', async() => { @@ -12,32 +13,55 @@ describe('Login path', async() => { await browser.close(); }); - it('should receive an error when the username is incorrect', async() => { - await page.doLogin('badUser', ''); - const result = await page.waitForLastSnackbar(); + describe('Bad login', async() => { + it('should receive an error when the password is invalid', async() => { + await page.doLogin('employee', 'badPassword'); + const message = await page.waitForSnackbar(); + const state = await page.getState(); - expect(result.length).toBeGreaterThan(0); + expect(message.type).toBe('error'); + expect(state).toBe('login'); + }); + + it('should receive an error when the username is invalid', async() => { + await page.doLogin('badUser', ''); + const message = await page.waitForSnackbar(); + const state = await page.getState(); + + expect(message.type).toBe('error'); + expect(state).toBe('login'); + }); + + it('should receive an error when the username is blank', async() => { + await page.doLogin('', ''); + const message = await page.waitForSnackbar(); + const state = await page.getState(); + + expect(message.type).toBe('error'); + expect(state).toBe('login'); + }); }); - it('should receive an error when the username is blank', async() => { - await page.doLogin('', ''); - const result = await page.waitForLastSnackbar(); + describe('Successful login', async() => { + it('should log in and go to home state', async() => { + await page.doLogin('employee'); + await page.waitFor('vn-home'); + const state = await page.getState(); - expect(result.length).toBeGreaterThan(0); + expect(state).toBe('home'); + }); }); - it('should receive an error when the password is incorrect', async() => { - await page.doLogin('employee', 'badPassword'); - const result = await page.waitForLastSnackbar(); + describe('Logout', async() => { + it('should logout and return to login state', async() => { + await page.doLogin('employee'); - expect(result.length).toBeGreaterThan(0); - }); + await page.waitToClick(selectors.globalItems.userMenuButton); + await page.waitToClick(selectors.globalItems.logoutButton); + await page.waitFor('vn-login'); + const state = await page.getState(); - it('should log in', async() => { - await page.doLogin('employee', 'nightmare'); - await page.waitForNavigation(); - let url = await page.expectURL('#!/'); - - expect(url).toBe(true); + expect(state).toBe('login'); + }); }); }); diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 65db9e7c6..2fdc4b091 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -1,9 +1,10 @@ import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; -describe('Client create path', async() => { +describe('Client create path', () => { let browser; let page; + beforeAll(async() => { browser = await getBrowser(); page = browser.page; @@ -15,9 +16,7 @@ describe('Client create path', async() => { }); it(`should search for the user Carol Danvers to confirm it isn't created yet`, async() => { - await page.write(selectors.clientsIndex.topbarSearch, 'Carol Danvers'); - await page.waitToClick(selectors.clientsIndex.searchButton); - await page.waitForNumberOfElements(selectors.clientsIndex.searchResult, 0); + await page.doSearch('Carol Danvers'); const result = await page.countElement(selectors.clientsIndex.searchResult); expect(result).toEqual(0); @@ -25,17 +24,14 @@ describe('Client create path', async() => { it('should now access to the create client view by clicking the create-client floating button', async() => { await page.waitToClick(selectors.clientsIndex.createClientButton); - await page.wait(selectors.createClientView.createButton); - let url = await page.expectURL('#!/client/create'); - - expect(url).toBe(true); + await page.waitForState('client.create'); }); it('should receive an error when clicking the create button having all the form fields empty', async() => { await page.waitToClick(selectors.createClientView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it('should receive an error when clicking the create button having name and Business name fields empty', async() => { @@ -44,9 +40,9 @@ describe('Client create path', async() => { await page.write(selectors.createClientView.email, 'CarolDanvers@verdnatura.es'); await page.autocompleteSearch(selectors.createClientView.salesPerson, 'replenisher'); await page.waitToClick(selectors.createClientView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it(`should attempt to create a new user with all it's data but wrong email`, async() => { @@ -60,9 +56,9 @@ describe('Client create path', async() => { await page.clearInput(selectors.createClientView.email); await page.write(selectors.createClientView.email, 'incorrect email format'); await page.waitToClick(selectors.createClientView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it(`should attempt to create a new user with all it's data but wrong postal code`, async() => { @@ -71,9 +67,9 @@ describe('Client create path', async() => { await page.clearInput(selectors.createClientView.postcode); await page.write(selectors.createClientView.postcode, '479999'); await page.waitToClick(selectors.createClientView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`The postcode doesn't exist. Please enter a correct one`); + expect(message.text).toBe(`The postcode doesn't exist. Please enter a correct one`); }); it(`should check for autocompleted city, province and country`, async() => { @@ -95,9 +91,9 @@ describe('Client create path', async() => { await page.clearInput(selectors.createClientView.postcode); await page.write(selectors.createClientView.postcode, '46000'); await page.waitToClick(selectors.createClientView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should click on the Clients button of the top bar menu', async() => { @@ -105,15 +101,11 @@ describe('Client create path', async() => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.wait(selectors.clientsIndex.createClientButton); - let url = await page.expectURL('#!/client/index'); - - expect(url).toBe(true); + await page.waitForState('client.index'); }); it(`should search for the user Carol Danvers to confirm it exists`, async() => { await page.accessToSearchResult('Carol Danvers'); - let url = await page.expectURL('#!/client/114/summary'); - - expect(url).toBe(true); + await page.waitForState('client.card.summary'); }); }); diff --git a/e2e/paths/02-client/02_edit_basic_data.spec.js b/e2e/paths/02-client/02_edit_basic_data.spec.js index 6ae512542..2e53a6ef8 100644 --- a/e2e/paths/02-client/02_edit_basic_data.spec.js +++ b/e2e/paths/02-client/02_edit_basic_data.spec.js @@ -35,9 +35,9 @@ describe('Client Edit basicData path', () => { await page.write(selectors.clientBasicData.email, 'PWallace@verdnatura.es'); await page.autocompleteSearch(selectors.clientBasicData.channel, 'Rumors on the streets'); await page.waitToClick(selectors.clientBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the name have been edited', async() => { @@ -99,9 +99,9 @@ describe('Client Edit basicData path', () => { await page.autocompleteSearch(selectors.clientBasicData.salesPerson, 'replenisherNick'); await page.autocompleteSearch(selectors.clientBasicData.channel, 'Metropolis newspaper'); await page.waitToClick(selectors.clientBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should now confirm the name have been edited', async() => { diff --git a/e2e/paths/02-client/03_edit_fiscal_data.spec.js b/e2e/paths/02-client/03_edit_fiscal_data.spec.js index 4cd54b87d..978627a60 100644 --- a/e2e/paths/02-client/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client/03_edit_fiscal_data.spec.js @@ -36,9 +36,7 @@ describe('Client Edit fiscalData path', () => { it(`should click on the fiscal data button`, async() => { await page.waitToClick(selectors.clientFiscalData.fiscalDataButton); - let url = await page.expectURL('fiscal-data'); - - expect(url).toBe(true); + await page.waitForState('client.card.fiscalData'); }); it('should not be able to edit the verified data checkbox', async() => { @@ -80,9 +78,9 @@ describe('Client Edit fiscalData path', () => { await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Invalid Tax number'); + expect(message.text).toBe('Invalid Tax number'); }); it(`should edit the fiscal this time with a valid fiscal id`, async() => { @@ -90,16 +88,16 @@ describe('Client Edit fiscalData path', () => { await page.write(selectors.clientFiscalData.fiscalId, '94980061C'); await page.waitToClick(selectors.clientFiscalData.saveButton); await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should propagate the Equalization tax', async() => { await page.waitToClick(selectors.clientFiscalData.acceptPropagationButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Equivalent tax spreaded'); + expect(message.text).toBe('Equivalent tax spreaded'); }); it('should receive an error if the fiscal id contains A or B at the beginning', async() => { @@ -107,26 +105,24 @@ describe('Client Edit fiscalData path', () => { await page.clearInput(selectors.clientFiscalData.fiscalId); await page.write(selectors.clientFiscalData.fiscalId, 'A94980061C'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Cannot check Equalization Tax in this NIF/CIF'); + expect(message.text).toBe('Cannot check Equalization Tax in this NIF/CIF'); }); it('should finally edit the fixcal data correctly as VIES isnt checked and fiscal id is valid for EQtax', async() => { await page.clearInput(selectors.clientFiscalData.fiscalId); await page.write(selectors.clientFiscalData.fiscalId, '94980061C'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); // confirm all addresses have now EQtax checked step 1 it(`should click on the addresses button to access to the client's addresses`, async() => { await page.waitToClick(selectors.clientAddresses.addressesButton); - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); // confirm all addresses have now EQtax checked step 2 @@ -154,17 +150,17 @@ describe('Client Edit fiscalData path', () => { await page.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox); await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should propagate the Equalization tax changes', async() => { await page.waitFor(1000); await page.waitToClick(selectors.clientFiscalData.acceptPropagationButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Equivalent tax spreaded'); + expect(message.text).toBe('Equivalent tax spreaded'); }); it('should confirm its name have been edited', async() => { @@ -261,9 +257,7 @@ describe('Client Edit fiscalData path', () => { // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 1 it(`should click on the addresses button to access to the client's addresses`, async() => { await page.waitToClick(selectors.clientAddresses.addressesButton); - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 2 @@ -272,9 +266,9 @@ describe('Client Edit fiscalData path', () => { await page.waitForTextInField(selectors.clientAddresses.city, 'Silla'); await page.waitToClick(selectors.clientAddresses.equalizationTaxCheckbox); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 3 diff --git a/e2e/paths/02-client/04_edit_billing_data.spec.js b/e2e/paths/02-client/04_edit_billing_data.spec.js index b757940be..394324509 100644 --- a/e2e/paths/02-client/04_edit_billing_data.spec.js +++ b/e2e/paths/02-client/04_edit_billing_data.spec.js @@ -26,25 +26,26 @@ describe('Client Edit billing data path', () => { await page.waitToClick(selectors.clientBillingData.receivedCoreVNLCheckbox); await page.waitToClick(selectors.clientBillingData.receivedB2BVNLCheckbox); await page.waitToClick(selectors.clientBillingData.saveButton); - let snackbarMessage = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(snackbarMessage).toEqual('That payment method requires an IBAN'); + expect(message.text).toBe('That payment method requires an IBAN'); }); - it(`should create a new BIC code`, async() => { + // 2215: Windows (hidden mode): Entity code doesn't get the focus, '9999' is written in entity name. + xit(`should create a new BIC code`, async() => { await page.waitToClick(selectors.clientBillingData.newBankEntityButton); await page.write(selectors.clientBillingData.newBankEntityName, 'Gotham City Bank'); await page.write(selectors.clientBillingData.newBankEntityCode, '9999'); await page.write(selectors.clientBillingData.newBankEntityBIC, 'GTHMCT'); await page.waitToClick(selectors.clientBillingData.acceptBankEntityButton); await page.waitForTextInField(selectors.clientBillingData.swiftBic, 'Gotham City Bank'); - let newcode = await page.waitToGetProperty(selectors.clientBillingData.swiftBic, 'value'); + const newcode = await page.waitToGetProperty(selectors.clientBillingData.swiftBic, 'value'); expect(newcode).toEqual('GTHMCT Gotham City Bank'); }); - it(`should confirm the IBAN pay method was sucessfully saved`, async() => { - let payMethod = await page.waitToGetProperty(selectors.clientBillingData.payMethod, 'value'); + xit(`should confirm the IBAN pay method was sucessfully saved`, async() => { + const payMethod = await page.waitToGetProperty(selectors.clientBillingData.payMethod, 'value'); expect(payMethod).toEqual('PayMethod with IBAN'); }); @@ -60,46 +61,45 @@ describe('Client Edit billing data path', () => { }); it(`should save the form with all its new data`, async() => { - await page.waitFor(3000); await page.waitForWatcherData(selectors.clientBillingData.watcher); await page.waitToClick(selectors.clientBillingData.saveButton); - let snackbarMessage = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(snackbarMessage).toEqual('Notification sent!'); + expect(message.text).toBe('Notification sent!'); }); it('should confirm the due day have been edited', async() => { - let dueDate = await page.waitToGetProperty(selectors.clientBillingData.dueDay, 'value'); + const dueDate = await page.waitToGetProperty(selectors.clientBillingData.dueDay, 'value'); expect(dueDate).toEqual('60'); }); it('should confirm the IBAN was saved', async() => { - let IBAN = await page.waitToGetProperty(selectors.clientBillingData.IBAN, 'value'); + const IBAN = await page.waitToGetProperty(selectors.clientBillingData.IBAN, 'value'); expect(IBAN).toEqual('ES9121000418450200051332'); }); it('should confirm the swift / BIC code was saved', async() => { - let code = await page.waitToGetProperty(selectors.clientBillingData.swiftBic, 'value'); + const code = await page.waitToGetProperty(selectors.clientBillingData.swiftBic, 'value'); expect(code).toEqual('CAIXESBB Caixa Bank'); }); it('should confirm Received LCR checkbox is checked', async() => { - let result = await page.checkboxState(selectors.clientBillingData.receivedCoreLCRCheckbox); + const result = await page.checkboxState(selectors.clientBillingData.receivedCoreLCRCheckbox); expect(result).toBe('checked'); }); it('should confirm Received core VNL checkbox is unchecked', async() => { - let result = await page.checkboxState(selectors.clientBillingData.receivedCoreVNLCheckbox); + const result = await page.checkboxState(selectors.clientBillingData.receivedCoreVNLCheckbox); expect(result).toBe('unchecked'); }); it('should confirm Received B2B VNL checkbox is unchecked', async() => { - let result = await page.checkboxState(selectors.clientBillingData.receivedB2BVNLCheckbox); + const result = await page.checkboxState(selectors.clientBillingData.receivedB2BVNLCheckbox); expect(result).toBe('unchecked'); }); diff --git a/e2e/paths/02-client/05_add_address.spec.js b/e2e/paths/02-client/05_add_address.spec.js index c9228e1cf..2fe238fea 100644 --- a/e2e/paths/02-client/05_add_address.spec.js +++ b/e2e/paths/02-client/05_add_address.spec.js @@ -18,9 +18,7 @@ describe('Client Add address path', () => { it(`should click on the add new address button to access to the new address form`, async() => { await page.waitToClick(selectors.clientAddresses.createAddress); - let url = await page.expectURL('address/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.create'); }); it('should receive an error after clicking save button as consignee, street and town fields are empty', async() => { @@ -30,9 +28,9 @@ describe('Client Add address path', () => { await page.write(selectors.clientAddresses.phone, '999887744'); await page.write(selectors.clientAddresses.mobileInput, '999887744'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it('should confirm that the city and province are propertly filled', async() => { @@ -50,31 +48,29 @@ describe('Client Add address path', () => { await page.write(selectors.clientAddresses.consignee, 'Bruce Bunner'); await page.write(selectors.clientAddresses.streetAddress, '320 Park Avenue New York'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Incoterms is required for a non UEE member'); + expect(message.text).toBe('Incoterms is required for a non UEE member'); }); it(`should receive an error after clicking save button as customsAgent is empty`, async() => { await page.autocompleteSearch(selectors.clientAddresses.incoterms, 'Free Alongside Ship'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Customs agent is required for a non UEE member'); + expect(message.text).toBe('Customs agent is required for a non UEE member'); }); it(`should create a new address with all it's data`, async() => { await page.autocompleteSearch(selectors.clientAddresses.customsAgent, 'Agent one'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should navigate back to the addresses index`, async() => { - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); it(`should confirm the new address exists and it's the default one`, async() => { @@ -86,9 +82,9 @@ describe('Client Add address path', () => { it('should click on the make default icon of the second address', async() => { await page.waitToClick(selectors.clientAddresses.secondMakeDefaultStar); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the default address is the expected one`, async() => { @@ -101,26 +97,22 @@ describe('Client Add address path', () => { it(`should click on the edit icon of the default address`, async() => { await page.waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand'); await page.waitToClick(selectors.clientAddresses.firstEditAddress); - let url = await page.expectURL('/edit'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.edit'); }); it(`should click on the active checkbox and receive an error to save it because it is the default address`, async() => { await page.waitForWatcherData(selectors.clientAddresses.watcher); await page.waitToClick(selectors.clientAddresses.activeCheckbox); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('The default consignee can not be unchecked'); + expect(message.text).toBe('The default consignee can not be unchecked'); }); it(`should go back to the addreses section by clicking the cancel button`, async() => { await page.waitForSelector('#shapes .shown', {hidden: true}); await page.waitToClick(selectors.clientAddresses.cancelEditAddressButton); await page.waitToClick('.vn-confirm.shown button[response="accept"]'); - let url = await page.expectURL('address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); }); diff --git a/e2e/paths/02-client/06_add_address_notes.spec.js b/e2e/paths/02-client/06_add_address_notes.spec.js index 58a949698..bf367f5ae 100644 --- a/e2e/paths/02-client/06_add_address_notes.spec.js +++ b/e2e/paths/02-client/06_add_address_notes.spec.js @@ -19,27 +19,25 @@ describe('Client add address notes path', () => { it(`should click on the edit icon of the default address`, async() => { await page.waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street'); await page.waitToClick(selectors.clientAddresses.firstEditAddress); - let url = await page.expectURL('/edit'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.edit'); }); it('should not save a description without observation type', async() => { await page.waitToClick(selectors.clientAddresses.addObservationButton); await page.write(selectors.clientAddresses.firstObservationDescription, 'first description'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it('should not save an observation type without description', async() => { await page.clearInput(selectors.clientAddresses.firstObservationDescription); await page.autocompleteSearch(selectors.clientAddresses.firstObservationType, 'comercial'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it('should create two new observations', async() => { @@ -48,8 +46,8 @@ describe('Client add address notes path', () => { await page.autocompleteSearch(selectors.clientAddresses.secondObservationType, 'observation one'); await page.write(selectors.clientAddresses.secondObservationDescription, 'second description'); await page.waitToClick(selectors.clientAddresses.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/02-client/07_edit_web_access.spec.js b/e2e/paths/02-client/07_edit_web_access.spec.js index f9b023716..95886f57c 100644 --- a/e2e/paths/02-client/07_edit_web_access.spec.js +++ b/e2e/paths/02-client/07_edit_web_access.spec.js @@ -21,16 +21,14 @@ describe('Client Edit web access path', () => { await page.clearInput(selectors.clientWebAccess.userName); await page.write(selectors.clientWebAccess.userName, 'Hulk'); await page.waitToClick(selectors.clientWebAccess.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm web access is now unchecked', async() => { - await page.waitToClick(selectors.clientBasicData.basicDataButton); - await page.wait(selectors.clientBasicData.name); - await page.waitToClick(selectors.clientsIndex.othersButton); - await page.waitToClick(selectors.clientWebAccess.webAccessButton); + await page.accessToSection('client.card.basicData'); + await page.accessToSection('client.card.webAccess'); const result = await page.checkboxState(selectors.clientWebAccess.enableWebAccessCheckbox); expect(result).toBe('unchecked'); diff --git a/e2e/paths/02-client/08_add_notes.spec.js b/e2e/paths/02-client/08_add_notes.spec.js index b759cbd07..d0b117ac9 100644 --- a/e2e/paths/02-client/08_add_notes.spec.js +++ b/e2e/paths/02-client/08_add_notes.spec.js @@ -17,25 +17,21 @@ describe('Client Add notes path', () => { }); it(`should reach the notes index`, async() => { - let url = await page.expectURL('/note'); - - expect(url).toBe(true); + await page.waitForState('client.card.note.index'); }); it(`should click on the add note button`, async() => { await page.waitToClick(selectors.clientNotes.addNoteFloatButton); - let url = await page.expectURL('/note/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.note.create'); }); it(`should create a note`, async() => { await page.waitFor(selectors.clientNotes.note); await page.type(`${selectors.clientNotes.note} textarea`, 'Meeting with Black Widow 21st 9am'); await page.waitToClick(selectors.clientNotes.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the note was created', async() => { diff --git a/e2e/paths/02-client/09_add_credit.spec.js b/e2e/paths/02-client/09_add_credit.spec.js index 05c50e809..8d1c9be1c 100644 --- a/e2e/paths/02-client/09_add_credit.spec.js +++ b/e2e/paths/02-client/09_add_credit.spec.js @@ -18,18 +18,16 @@ describe('Client Add credit path', () => { it(`should click on the add credit button`, async() => { await page.waitToClick(selectors.clientCredit.addCreditFloatButton); - let url = await page.expectURL('/credit/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.credit.create'); }); it(`should edit the credit`, async() => { await page.clearInput(selectors.clientCredit.credit); await page.write(selectors.clientCredit.credit, '999'); await page.waitToClick(selectors.clientCredit.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the credit was updated', async() => { diff --git a/e2e/paths/02-client/10_add_greuge.spec.js b/e2e/paths/02-client/10_add_greuge.spec.js index c934a42f1..b7e130683 100644 --- a/e2e/paths/02-client/10_add_greuge.spec.js +++ b/e2e/paths/02-client/10_add_greuge.spec.js @@ -18,17 +18,15 @@ describe('Client Add greuge path', () => { it(`should click on the add greuge button`, async() => { await page.waitToClick(selectors.clientGreuge.addGreugeFloatButton); - let url = await page.expectURL('greuge/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.greuge.create'); }); it(`should receive an error if all fields are empty but date and type on submit`, async() => { await page.autocompleteSearch(selectors.clientGreuge.type, 'Diff'); await page.waitToClick(selectors.clientGreuge.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it(`should create a new greuge with all its data`, async() => { @@ -36,9 +34,9 @@ describe('Client Add greuge path', () => { await page.waitForTextInField(selectors.clientGreuge.amount, '999'); await page.write(selectors.clientGreuge.description, 'new armor for Batman!'); await page.waitToClick(selectors.clientGreuge.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the greuge was added to the list', async() => { diff --git a/e2e/paths/02-client/12_lock_of_verified_data.spec.js b/e2e/paths/02-client/12_lock_of_verified_data.spec.js index 870ce7cb1..79a9e17ac 100644 --- a/e2e/paths/02-client/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client/12_lock_of_verified_data.spec.js @@ -30,9 +30,9 @@ describe('Client lock verified data path', () => { await page.clearInput(selectors.clientFiscalData.socialName); await page.write(selectors.clientFiscalData.socialName, 'Captain America Civil War'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the social name have been edited', async() => { @@ -60,9 +60,9 @@ describe('Client lock verified data path', () => { await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm Verified data checkbox is checked', async() => { @@ -77,9 +77,9 @@ describe('Client lock verified data path', () => { await page.clearInput(selectors.clientFiscalData.socialName); await page.write(selectors.clientFiscalData.socialName, 'Ant man and the Wasp'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should again confirm the social name have been edited', async() => { @@ -107,9 +107,9 @@ describe('Client lock verified data path', () => { await page.clearInput(selectors.clientFiscalData.socialName); await page.write(selectors.clientFiscalData.socialName, 'This wont happen'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(jasmine.arrayContaining([`You can't make changes on a client with verified data`])); + expect(message.text).toBe(`You can't make changes on a client with verified data`); }); }); @@ -131,9 +131,9 @@ describe('Client lock verified data path', () => { await page.clearInput(selectors.clientFiscalData.socialName); await page.write(selectors.clientFiscalData.socialName, 'new social name edition'); await page.waitToClick(selectors.clientFiscalData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should now confirm the social name have been edited once and for all', async() => { diff --git a/e2e/paths/02-client/13_log.spec.js b/e2e/paths/02-client/13_log.spec.js index 462d66347..93397d301 100644 --- a/e2e/paths/02-client/13_log.spec.js +++ b/e2e/paths/02-client/13_log.spec.js @@ -20,16 +20,13 @@ describe('Client log path', () => { await page.clearInput(selectors.clientBasicData.name); await page.write(selectors.clientBasicData.name, 'this is a test'); await page.waitToClick(selectors.clientBasicData.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should navigate to the log section', async() => { - await page.waitToClick(selectors.clientLog.logButton); - let url = await page.expectURL('log'); - - expect(url).toBe(true); + await page.accessToSection('client.card.log'); }); it('should check the previous value of the last logged change', async() => { @@ -46,7 +43,6 @@ describe('Client log path', () => { let lastModificationCurrentValue = await page. waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText'); - expect(lastModificationPreviousValue).toEqual('name: DavidCharlesHaller'); expect(lastModificationCurrentValue).toEqual('name: this is a test'); }); diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index ef7930c8d..108f76710 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -18,9 +18,9 @@ describe('Client balance path', () => { it('should now edit the local user config data', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'CCs'); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should access to the balance section to check the data shown matches the local settings', async() => { @@ -33,26 +33,24 @@ describe('Client balance path', () => { it('should now clear the user local settings', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); it('should click the new payment button', async() => { await page.closePopup(); await page.reloadSection('client.card.balance.index'); - let url = await page.expectURL('/balance'); - - expect(url).toBe(true); + await page.waitForState('client.card.balance.index'); }); it('should create a new payment that clears the debt', async() => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt'); await page.waitToClick(selectors.clientBalance.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); it('should check balance is now 0 and the company is now VNL becouse the user local settings were removed', async() => { @@ -69,13 +67,11 @@ describe('Client balance path', () => { it('should create a new payment that sets the balance to positive value', async() => { await page.waitToClick(selectors.clientBalance.newPaymentButton); - await page.waitFor(3000); // didn't manage to make this dynamic to allow clearInput to find the icon clear... :( - await page.clearInput(selectors.clientBalance.newPaymentAmount); - await page.write(selectors.clientBalance.newPaymentAmount, '100'); + await page.overwrite(selectors.clientBalance.newPaymentAmount, '100'); await page.waitToClick(selectors.clientBalance.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); it('should check balance is now -100', async() => { @@ -87,14 +83,11 @@ describe('Client balance path', () => { it('should create a new payment that sets the balance back to the original negative value', async() => { await page.waitToClick(selectors.clientBalance.newPaymentButton); - await page.waitFor(3000); // didn't manage to make this dynamic to allow clearInput to find the icon clear... :( - await page.waitForSelector('.vn-dialog.vn-popup.shown', {visible: true}); - await page.clearInput(selectors.clientBalance.newPaymentAmount); - await page.write(selectors.clientBalance.newPaymentAmount, '-150'); + await page.overwrite(selectors.clientBalance.newPaymentAmount, '-150'); await page.waitToClick(selectors.clientBalance.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); it('should check balance is now 50', async() => { @@ -110,17 +103,12 @@ describe('Client balance path', () => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.wait(selectors.clientsIndex.createClientButton); - let url = await page.expectURL('#!/client/index'); - - expect(url).toBe(true); + await page.waitForState('client.index'); }); it('should now search for the user Petter Parker', async() => { await page.accessToSearchResult('Petter Parker'); - await page.waitToClick(selectors.clientBalance.balanceButton); - let url = await page.expectURL('/balance'); - - expect(url).toBe(true); + await page.accessToSection('client.card.balance.index'); }); it('should not be able to click the new payment button as it isnt present', async() => { diff --git a/e2e/paths/02-client/15_user_config.spec.js b/e2e/paths/02-client/15_user_config.spec.js index 89d4e004a..28f2ef29e 100644 --- a/e2e/paths/02-client/15_user_config.spec.js +++ b/e2e/paths/02-client/15_user_config.spec.js @@ -16,7 +16,6 @@ describe('User config', () => { describe('as salesPerson', () => { it('should login', async() => { await page.login('salesPerson'); - await page.waitForContentLoaded(); }); it('should now open the user config form to check the settings', async() => { @@ -26,7 +25,6 @@ describe('User config', () => { let expectedLocalWarehouse = await page .expectPropertyValue(selectors.globalItems.userLocalWarehouse, 'value', ''); - let expectedLocalBank = await page .expectPropertyValue(selectors.globalItems.userLocalBank, 'value', ''); @@ -50,7 +48,6 @@ describe('User config', () => { describe('as employee', () => { it('should log in', async() => { await page.login('employee'); - await page.waitForContentLoaded(); }); it('should open the user config form to check the settings', async() => { @@ -59,7 +56,6 @@ describe('User config', () => { let expectedLocalWarehouse = await page .expectPropertyValue(selectors.globalItems.userLocalWarehouse, 'value', ''); - let expectedLocalBank = await page .expectPropertyValue(selectors.globalItems.userLocalBank, 'value', ''); @@ -83,16 +79,15 @@ describe('User config', () => { await page.autocompleteSearch(selectors.globalItems.userLocalWarehouse, 'Warehouse Four'); await page.autocompleteSearch(selectors.globalItems.userLocalBank, 'Pay on receipt'); await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'VNL'); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); }); describe('as salesPerson 2nd run', () => { it('should log in once more', async() => { await page.login('salesPerson'); - await page.waitForContentLoaded(); }); it('should again open the user config form to check the local settings', async() => { @@ -123,9 +118,9 @@ describe('User config', () => { await page.clearInput(selectors.globalItems.userConfigFirstAutocomplete); await page.clearInput(selectors.globalItems.userConfigSecondAutocomplete); await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); }); }); diff --git a/e2e/paths/02-client/17_dms.spec.js b/e2e/paths/02-client/17_dms.spec.js index 95b37093a..32cca05f3 100644 --- a/e2e/paths/02-client/17_dms.spec.js +++ b/e2e/paths/02-client/17_dms.spec.js @@ -20,9 +20,9 @@ describe('Client DMS', () => { it('should delete de first file', async() => { await page.waitToClick(selectors.dms.deleteFileButton); await page.respondToDialog('accept'); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should click on the first document line worker name making the descriptor visible`, async() => { diff --git a/e2e/paths/02-client/18_contacts.spec.js b/e2e/paths/02-client/18_contacts.spec.js index fd8b68283..87e75a975 100644 --- a/e2e/paths/02-client/18_contacts.spec.js +++ b/e2e/paths/02-client/18_contacts.spec.js @@ -22,17 +22,17 @@ describe('Client contacts', () => { await page.write(selectors.clientContacts.name, 'Ansible'); await page.write(selectors.clientContacts.phone, 'FTL comms'); await page.waitToClick(selectors.clientContacts.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should delete de contact', async() => { await page.waitFor(3000); await page.waitToClick(selectors.clientContacts.deleteFirstPhone); await page.waitToClick(selectors.clientContacts.saveButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/02-client/19_summary.spec.js b/e2e/paths/02-client/19_summary.spec.js index 11b5a298e..ab39154cf 100644 --- a/e2e/paths/02-client/19_summary.spec.js +++ b/e2e/paths/02-client/19_summary.spec.js @@ -17,9 +17,7 @@ describe('Client summary path', () => { }); it('should reach the first route summary section', async() => { - let url = await page.expectURL('#!/client/102/summary'); - - expect(url).toBe(true); + await page.waitForState('client.card.summary'); }); it('should display details from the client on the header', async() => { diff --git a/e2e/paths/03-worker/01_summary.spec.js b/e2e/paths/03-worker/01_summary.spec.js index 86a95eee3..4ea87481a 100644 --- a/e2e/paths/03-worker/01_summary.spec.js +++ b/e2e/paths/03-worker/01_summary.spec.js @@ -16,9 +16,7 @@ describe('Worker summary path', () => { }); it('should reach the employee summary section', async() => { - const url = await page.expectURL('#!/worker/3/summary'); - - expect(url).toBe(true); + await page.waitForState('worker.card.summary'); }); it('should check the summary contains the name and userName on the header', async() => { diff --git a/e2e/paths/03-worker/02_basicData.spec.js b/e2e/paths/03-worker/02_basicData.spec.js index 21443c517..a24ffd033 100644 --- a/e2e/paths/03-worker/02_basicData.spec.js +++ b/e2e/paths/03-worker/02_basicData.spec.js @@ -24,9 +24,9 @@ describe('Worker basic data path', () => { await page.clearInput(selectors.workerBasicData.phone); await page.write(selectors.workerBasicData.phone, '444332211'); await page.waitToClick(selectors.workerBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should reload the section then check the name was edited', async() => { diff --git a/e2e/paths/03-worker/03_pbx.spec.js b/e2e/paths/03-worker/03_pbx.spec.js index 83849a5dd..f2a567af2 100644 --- a/e2e/paths/03-worker/03_pbx.spec.js +++ b/e2e/paths/03-worker/03_pbx.spec.js @@ -19,17 +19,17 @@ describe('Worker pbx path', () => { it('should receive an error when the extension exceeds 4 characters', async() => { await page.write(selectors.workerPbx.extension, '55555'); await page.waitToClick(selectors.workerPbx.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Extension format is invalid'); + expect(message.text).toBe('Extension format is invalid'); }); it('should sucessfully save the changes', async() => { await page.clearInput(selectors.workerPbx.extension); await page.write(selectors.workerPbx.extension, '4444'); await page.waitToClick(selectors.workerPbx.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved! User must access web'); + expect(message.text).toBe('Data saved! User must access web'); }); }); diff --git a/e2e/paths/03-worker/04_time_control.spec.js b/e2e/paths/03-worker/04_time_control.spec.js index 36aaca61e..c94137e2f 100644 --- a/e2e/paths/03-worker/04_time_control.spec.js +++ b/e2e/paths/03-worker/04_time_control.spec.js @@ -57,9 +57,9 @@ describe('Worker time control path', () => { await page.waitForTextInElement(selectors.workerTimeControl.thirdEntryOfMonday, wrongScanTime); await page.waitToClick(selectors.workerTimeControl.thirdEntryOfMondayDelete); await page.respondToDialog('accept'); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Entry removed'); + expect(message.text).toBe('Entry removed'); }); it(`should scan out Hank Pym to leave early`, async() => { @@ -316,16 +316,12 @@ describe('Worker time control path', () => { it('should search for a worker and access to its summary', async() => { await page.accessToSearchResult('HankPym'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('worker.card.summary'); }); it('should access to the time control section', async() => { await page.accessToSection('worker.card.timeControl'); - let url = await page.expectURL('/time-control'); - - expect(url).toBe(true); + await page.waitForState('worker.card.timeControl'); }); it('should lovingly scan in Hank Pym', async() => { diff --git a/e2e/paths/04-item/01_summary.spec.js b/e2e/paths/04-item/01_summary.spec.js index 01e730668..7658cb752 100644 --- a/e2e/paths/04-item/01_summary.spec.js +++ b/e2e/paths/04-item/01_summary.spec.js @@ -15,14 +15,14 @@ describe('Item summary path', () => { }); it('should search for an item', async() => { - await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3); - await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon longbow 2m'); - await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); + await page.doSearch('Ranged weapon'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); + + await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon'); + await page.waitToClick(selectors.itemsIndex.firstResultPreviewButton); const isVisible = await page.isVisible(selectors.itemSummary.basicData); + expect(nResults).toBe(3); expect(isVisible).toBeTruthy(); }); @@ -67,13 +67,13 @@ describe('Item summary path', () => { }); it('should search for other item', async() => { - await page.clearInput('vn-searchbar'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.write(selectors.itemsIndex.topbarSearch, 'Melee Reinforced'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); - await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); + await page.doSearch('Melee Reinforced'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); + + await page.waitToClick(selectors.itemsIndex.firstResultPreviewButton); await page.waitForSelector(selectors.itemSummary.basicData, {visible: true}); + + expect(nResults).toBe(2); }); it(`should now check the item summary preview shows fields from basic data`, async() => { @@ -104,9 +104,7 @@ describe('Item summary path', () => { it(`should navigate to the one of the items detailed section`, async() => { await page.accessToSearchResult('Melee weapon combat fist 15cm'); - let url = await page.expectURL('summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it(`should check the descritor edit button is not visible for employee`, async() => { diff --git a/e2e/paths/04-item/02_basic_data.spec.js b/e2e/paths/04-item/02_basic_data.spec.js index ce56b9a5c..7a9b9a1e7 100644 --- a/e2e/paths/04-item/02_basic_data.spec.js +++ b/e2e/paths/04-item/02_basic_data.spec.js @@ -34,9 +34,9 @@ describe('Item Edit basic data path', () => { await page.waitToClick(selectors.itemBasicData.isActiveCheckbox); await page.waitToClick(selectors.itemBasicData.priceInKgCheckbox); await page.waitToClick(selectors.itemBasicData.submitBasicDataButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should create a new intrastat`, async() => { @@ -53,9 +53,9 @@ describe('Item Edit basic data path', () => { it('should save with the new intrastat', async() => { await page.waitToClick(selectors.itemBasicData.submitBasicDataButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the item name was edited`, async() => { diff --git a/e2e/paths/04-item/03_tax.spec.js b/e2e/paths/04-item/03_tax.spec.js index ef2d68096..b05dcb286 100644 --- a/e2e/paths/04-item/03_tax.spec.js +++ b/e2e/paths/04-item/03_tax.spec.js @@ -21,9 +21,9 @@ describe('Item edit tax path', () => { await page.autocompleteSearch(selectors.itemTax.secondClass, 'General VAT'); await page.autocompleteSearch(selectors.itemTax.thirdClass, 'General VAT'); await page.waitToClick(selectors.itemTax.submitTaxButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the first item tax class was edited`, async() => { diff --git a/e2e/paths/04-item/04_tags.spec.js b/e2e/paths/04-item/04_tags.spec.js index 098ac75eb..f53ff3582 100644 --- a/e2e/paths/04-item/04_tags.spec.js +++ b/e2e/paths/04-item/04_tags.spec.js @@ -24,9 +24,9 @@ describe('Item create tags path', () => { await page.clearInput(selectors.itemTags.seventhRelevancy); await page.write(selectors.itemTags.seventhRelevancy, '4'); await page.waitToClick(selectors.itemTags.submitItemTagsButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the fourth row data is the expected one`, async() => { diff --git a/e2e/paths/04-item/05_niche.spec.js b/e2e/paths/04-item/05_niche.spec.js index 4da8ed5fe..4ad0398c2 100644 --- a/e2e/paths/04-item/05_niche.spec.js +++ b/e2e/paths/04-item/05_niche.spec.js @@ -23,9 +23,9 @@ describe('Item create niche path', () => { await page.autocompleteSearch(selectors.itemNiches.thirdWarehouse, 'Warehouse Two'); await page.write(selectors.itemNiches.thirdCode, 'A4'); await page.waitToClick(selectors.itemNiches.submitNichesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the first niche is the expected one`, async() => { diff --git a/e2e/paths/04-item/06_botanical.spec.js b/e2e/paths/04-item/06_botanical.spec.js index edcc94f28..84a144f1d 100644 --- a/e2e/paths/04-item/06_botanical.spec.js +++ b/e2e/paths/04-item/06_botanical.spec.js @@ -21,9 +21,9 @@ describe('Item Create botanical path', () => { await page.autocompleteSearch(selectors.itemBotanical.genus, 'Abelia'); await page.autocompleteSearch(selectors.itemBotanical.species, 'dealbata'); await page.waitToClick(selectors.itemBotanical.submitBotanicalButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the botanical for the item was created`, async() => { @@ -56,9 +56,9 @@ describe('Item Create botanical path', () => { await page.autocompleteSearch(selectors.itemBotanical.genus, 'Abies'); await page.autocompleteSearch(selectors.itemBotanical.species, 'decurrens'); await page.waitToClick(selectors.itemBotanical.submitBotanicalButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the botanical for the item was edited`, async() => { diff --git a/e2e/paths/04-item/07_barcode.spec.js b/e2e/paths/04-item/07_barcode.spec.js index 7750b4b6d..0220b3a9d 100644 --- a/e2e/paths/04-item/07_barcode.spec.js +++ b/e2e/paths/04-item/07_barcode.spec.js @@ -21,9 +21,9 @@ describe('Item Create barcodes path', () => { await page.waitToClick(selectors.itemBarcodes.addBarcodeButton); await page.write(selectors.itemBarcodes.thirdCode, '5'); await page.waitToClick(selectors.itemBarcodes.submitBarcodesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the barcode 5 is created and it is now the third barcode as the first was deleted`, async() => { diff --git a/e2e/paths/04-item/08_create_and_clone.spec.js b/e2e/paths/04-item/08_create_and_clone.spec.js index d06ef4682..4d035a4c3 100644 --- a/e2e/paths/04-item/08_create_and_clone.spec.js +++ b/e2e/paths/04-item/08_create_and_clone.spec.js @@ -16,34 +16,25 @@ describe('Item Create/Clone path', () => { describe('create', () => { it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, async() => { - await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Infinity Gauntlet'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 0); - const result = await page.countElement(selectors.itemsIndex.searchResult); + await page.doSearch('Infinity Gauntlet'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); it('should access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should return to the item index by clickig the cancel button', async() => { await page.waitToClick(selectors.itemCreateView.cancelButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it('should now access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should create the Infinity Gauntlet item', async() => { @@ -52,9 +43,9 @@ describe('Item Create/Clone path', () => { await page.autocompleteSearch(selectors.itemCreateView.intrastat, 'Coral y materiales similares'); await page.autocompleteSearch(selectors.itemCreateView.origin, 'Holand'); await page.waitToClick(selectors.itemCreateView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm Infinity Gauntlet item was created', async() => { @@ -87,39 +78,28 @@ describe('Item Create/Clone path', () => { it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); await page.wait(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it(`should search for the item Infinity Gauntlet`, async() => { - await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Infinity Gauntlet'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1); - const result = await page.countElement(selectors.itemsIndex.searchResult); + await page.doSearch('Infinity Gauntlet'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); - expect(result).toEqual(1); + expect(nResults).toEqual(1); }); it(`should clone the Infinity Gauntlet`, async() => { await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Infinity Gauntlet'); await page.waitToClick(selectors.itemsIndex.searchResultCloneButton); await page.waitToClick(selectors.itemsIndex.acceptClonationAlertButton); - let url = await page.expectURL('tags'); - - expect(url).toBe(true); + await page.waitForState('item.tags'); }); it('should search for the item Infinity Gauntlet and find two', async() => { - await page.waitToClick(selectors.itemTags.goToItemIndexButton); - await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Infinity Gauntlet'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); - const result = await page.countElement(selectors.itemsIndex.searchResult); + await page.doSearch('Infinity Gauntlet'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); - expect(result).toEqual(2); + expect(nResults).toEqual(2); }); }); }); diff --git a/e2e/paths/04-item/09_regularize.spec.js b/e2e/paths/04-item/09_regularize.spec.js index 838b24cf0..6de995515 100644 --- a/e2e/paths/04-item/09_regularize.spec.js +++ b/e2e/paths/04-item/09_regularize.spec.js @@ -18,9 +18,9 @@ describe('Item regularize path', () => { await page.waitForSpinnerLoad(); await page.waitToClick(selectors.globalItems.userMenuButton); await page.autocompleteSearch(selectors.globalItems.userLocalWarehouse, 'Warehouse Four'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should check the local settings were saved', async() => { @@ -34,9 +34,7 @@ describe('Item regularize path', () => { it('should search for an specific item', async() => { await page.accessToSearchResult('Ranged weapon pistol 9mm'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it('should open the regularize dialog and check the warehouse matches the local user settings', async() => { @@ -51,9 +49,9 @@ describe('Item regularize path', () => { await page.write(selectors.itemDescriptor.regularizeQuantity, '100'); await page.autocompleteSearch(selectors.itemDescriptor.regularizeWarehouse, 'Warehouse One'); await page.waitToClick(selectors.itemDescriptor.regularizeSaveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should click on the Tickets button of the top bar menu', async() => { @@ -63,27 +61,22 @@ describe('Item regularize path', () => { page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}), page.waitToClick(selectors.globalItems.ticketsButton) ]); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should clear the user local settings now', async() => { - await page.waitForContentLoaded(); await page.waitToClick(selectors.globalItems.userMenuButton); + await page.waitForContentLoaded(); await page.clearInput(selectors.globalItems.userConfigFirstAutocomplete); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should search for the ticket with alias missing', async() => { - await page.accessToSearchResult('Carol Danvers'); await page.keyboard.press('Escape'); await page.accessToSearchResult('missing'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should check the ticket sale quantity is showing a negative value`, async() => { @@ -105,16 +98,12 @@ describe('Item regularize path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.itemsButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it('should search for the item once again', async() => { await page.accessToSearchResult('Ranged weapon pistol 9mm'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it('should regularize the item once more', async() => { @@ -123,9 +112,9 @@ describe('Item regularize path', () => { await page.write(selectors.itemDescriptor.regularizeQuantity, '100'); await page.autocompleteSearch(selectors.itemDescriptor.regularizeWarehouse, 'Warehouse One'); await page.waitToClick(selectors.itemDescriptor.regularizeSaveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should again click on the Tickets button of the top bar menu', async() => { @@ -136,16 +125,12 @@ describe('Item regularize path', () => { page.waitToClick(selectors.globalItems.ticketsButton) ]); await page.waitForTransitionEnd('vn-searchbar'); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should search for the ticket with id 25 once again', async() => { await page.accessToSearchResult('25'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should check the ticket contains now two sales`, async() => { diff --git a/e2e/paths/04-item/10_index.spec.js b/e2e/paths/04-item/10_index.spec.js index e15469283..b4c4b636e 100644 --- a/e2e/paths/04-item/10_index.spec.js +++ b/e2e/paths/04-item/10_index.spec.js @@ -34,9 +34,9 @@ describe('Item index path', () => { await page.waitToClick(selectors.itemsIndex.buyerCheckbox); await page.waitToClick(selectors.itemsIndex.destinyCheckbox); await page.waitToClick(selectors.itemsIndex.saveFieldsButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should navigate forth and back to see the images column is still visible', async() => { @@ -68,9 +68,9 @@ describe('Item index path', () => { await page.waitToClick(selectors.itemsIndex.buyerCheckbox); await page.waitToClick(selectors.itemsIndex.destinyCheckbox); await page.waitToClick(selectors.itemsIndex.saveFieldsButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should now navigate forth and back to see the ids column is now visible', async() => { diff --git a/e2e/paths/04-item/11_item_log.spec.js b/e2e/paths/04-item/11_item_log.spec.js index 213365c12..7ea679f4a 100644 --- a/e2e/paths/04-item/11_item_log.spec.js +++ b/e2e/paths/04-item/11_item_log.spec.js @@ -15,19 +15,15 @@ describe('Item log path', () => { }); it(`should search for the Knowledge artifact to confirm it isn't created yet`, async() => { - await page.write(selectors.itemsIndex.topbarSearch, 'Knowledge artifact'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 0); - const result = await page.countElement(selectors.itemsIndex.searchResult); + await page.doSearch('Knowledge artifact'); + const nResults = await page.countElement(selectors.itemsIndex.searchResult); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); it('should access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should create the Knowledge artifact item', async() => { @@ -36,25 +32,21 @@ describe('Item log path', () => { await page.autocompleteSearch(selectors.itemCreateView.intrastat, 'Coral y materiales similares'); await page.autocompleteSearch(selectors.itemCreateView.origin, 'Holand'); await page.waitToClick(selectors.itemCreateView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); await page.wait(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it(`should search for the created item and navigate to it's log section`, async() => { await page.accessToSearchResult('Knowledge artifact'); await page.accessToSection('item.card.log'); - let url = await page.expectURL('/log'); - - expect(url).toBe(true); + await page.waitForState('item.card.log'); }); it(`should confirm the log is showing 5 entries`, async() => { diff --git a/e2e/paths/04-item/12_descriptor.spec.js b/e2e/paths/04-item/12_descriptor.spec.js index 84614cf30..35be1135e 100644 --- a/e2e/paths/04-item/12_descriptor.spec.js +++ b/e2e/paths/04-item/12_descriptor.spec.js @@ -19,7 +19,7 @@ describe('Item descriptor path', () => { it('should check the descriptor inactive icon is dark as the item is active', async() => { await page.wait(selectors.itemDescriptor.inactiveIcon); await page.waitForClassNotPresent(selectors.itemDescriptor.inactiveIcon, 'bright'); - let darkIcon = await page.isVisible(selectors.itemDescriptor.inactiveIcon); + const darkIcon = await page.isVisible(selectors.itemDescriptor.inactiveIcon); expect(darkIcon).toBeTruthy(); }); @@ -27,15 +27,15 @@ describe('Item descriptor path', () => { it('should set the item to inactive', async() => { await page.waitToClick(selectors.itemBasicData.isActiveCheckbox); await page.waitToClick(selectors.itemBasicData.submitBasicDataButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should reload the section and check the inactive icon is bright', async() => { await page.reloadSection('item.card.basicData'); await page.waitForClassPresent(selectors.itemDescriptor.inactiveIcon, 'bright'); - let brightIcon = await page.isVisible(selectors.itemDescriptor.inactiveIcon); + const brightIcon = await page.isVisible(selectors.itemDescriptor.inactiveIcon); expect(brightIcon).toBeTruthy(); }); @@ -43,8 +43,8 @@ describe('Item descriptor path', () => { it('should set the item back to active', async() => { await page.waitToClick(selectors.itemBasicData.isActiveCheckbox); await page.waitToClick(selectors.itemBasicData.submitBasicDataButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/04-item/13_request.spec.js b/e2e/paths/04-item/13_request.spec.js index d6aecbb48..ab48e0c37 100644 --- a/e2e/paths/04-item/13_request.spec.js +++ b/e2e/paths/04-item/13_request.spec.js @@ -16,9 +16,7 @@ describe('Item request path', () => { }); it('should reach the item request section', async() => { - const result = await page.expectURL('/item/request'); - - expect(result).toBe(true); + await page.waitForState('item.request'); }); it('should fill the id and quantity then check the concept was updated', async() => { @@ -38,9 +36,8 @@ describe('Item request path', () => { it('should now click on the second declain request icon then type the reason', async() => { await page.waitToClick(selectors.itemRequest.secondRequestDecline); - await page.write(selectors.itemRequest.declineReason, 'not quite as expected'); - await page.waitToClick(selectors.itemRequest.acceptDeclineReason); - await page.waitForContentLoaded(); + await page.write(selectors.itemRequest.declineReason, 'Not quite as expected'); + await page.respondToDialog('accept'); let status = await page.waitToGetProperty(selectors.itemRequest.firstRequestStatus, 'innerText'); expect(status).toContain('Denegada'); diff --git a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js index a6d34a473..e8b0ad8e7 100644 --- a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js +++ b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js @@ -74,9 +74,9 @@ describe('Ticket List sale path', () => { await page.keyboard.press('Enter'); await page.write(selectors.ticketSales.secondSaleQuantity, '1'); await page.keyboard.press('Enter'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); // #1865 @@ -84,9 +84,9 @@ describe('Ticket List sale path', () => { await page.focusElement(selectors.ticketSales.secondSaleConceptCell); await page.write(selectors.ticketSales.secondSaleConceptInput, 'Aegis of Valor'); await page.keyboard.press('Enter'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should add a third empty item to the sale list', async() => { @@ -102,9 +102,9 @@ describe('Ticket List sale path', () => { await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox); await page.waitToClick(selectors.ticketSales.deleteSaleButton); await page.waitToClick(selectors.ticketSales.acceptDeleteLineButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should verify there's only 1 single line remaining`, async() => { diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index f2265797c..a22b0e022 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -19,245 +19,218 @@ xdescribe('Ticket Edit sale path', () => { }); it(`should click on the first sale claim icon to navigate over there`, async() => { - const url = await nightmare - .waitToClick(selectors.ticketSales.firstSaleClaimIcon) - .wait(selectors.claimBasicData.claimState) - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.firstSaleClaimIcon); + await page.wait(selectors.claimBasicData.claimState); + const url = await page.parsedUrl(); expect(url.hash).toEqual('#!/claim/2/basic-data'); }); it('should navigate to the tickets index', async() => { - const url = await nightmare - .waitToClick(selectors.globalItems.applicationsMenuButton) - .wait(selectors.globalItems.applicationsMenuVisible) - .waitToClick(selectors.globalItems.ticketsButton) - .wait(selectors.ticketsIndex.topbarSearch) - .parsedUrl(); + await page.waitToClick(selectors.globalItems.applicationsMenuButton); + await page.wait(selectors.globalItems.applicationsMenuVisible); + await page.waitToClick(selectors.globalItems.ticketsButton); + await page.wait(selectors.ticketsIndex.topbarSearch); + const url = await page.parsedUrl(); expect(url.hash).toEqual('#!/ticket/index'); }); it(`should search for a ticket and then navigate to it's sales`, async() => { - const url = await nightmare - .accessToSearchResult(16) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.accessToSearchResult(16); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); it(`should check the zoomed image isn't present`, async() => { - const result = await nightmare - .countElement(selectors.ticketSales.firstSaleZoomedImage); + const result = await page.countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(0); }); it(`should click on the thumbnail image of the 1st sale and see the zoomed image`, async() => { - const result = await nightmare - .clickIfVisible(selectors.ticketSales.firstSaleThumbnailImage) - .countElement(selectors.ticketSales.firstSaleZoomedImage); + await page.clickIfVisible(selectors.ticketSales.firstSaleThumbnailImage); + const result = await page.countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(1); }); it(`should click on the zoomed image to close it`, async() => { - const result = await nightmare - .clickIfVisible(selectors.ticketSales.firstSaleZoomedImage) - .countElement(selectors.ticketSales.firstSaleZoomedImage); + await page.clickIfVisible(selectors.ticketSales.firstSaleZoomedImage); + const result = await page.countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(0); }); it(`should confirm the item descriptor insnt visible yet`, async() => { - const visible = await nightmare - .isVisible(selectors.ticketSales.saleDescriptorPopover); + const visible = await page.isVisible(selectors.ticketSales.saleDescriptorPopover); expect(visible).toBeFalsy(); }); it(`should click on the first sale ID making the item descriptor visible`, async() => { - const visible = await nightmare - .waitToClick(selectors.ticketSales.firstSaleId) - .waitImgLoad(selectors.ticketSales.firstSaleDescriptorImage) - .isVisible(selectors.ticketSales.saleDescriptorPopover); + await page.waitToClick(selectors.ticketSales.firstSaleId); + await page.waitImgLoad(selectors.ticketSales.firstSaleDescriptorImage); + const visible = await page.isVisible(selectors.ticketSales.saleDescriptorPopover); expect(visible).toBeTruthy(); }); it(`should click on the descriptor image of the 1st sale and see the zoomed image`, async() => { - const result = await nightmare - .clickIfVisible('vn-item-descriptor img') - .countElement(selectors.ticketSales.firstSaleZoomedImage); + await page.clickIfVisible('vn-item-descriptor img'); + const result = await page.countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(1); }); it(`should now click on the zoomed image to close it`, async() => { - const result = await nightmare - .clickIfVisible(selectors.ticketSales.firstSaleZoomedImage) - .countElement(selectors.ticketSales.firstSaleZoomedImage); + await page.clickIfVisible(selectors.ticketSales.firstSaleZoomedImage); + const result = await page.countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(0); }); it(`should click on the summary icon of the item-descriptor to access to the item summary`, async() => { - const url = await nightmare - .waitToClick(selectors.ticketSales.saleDescriptorPopoverSummaryButton) - .waitForURL('/summary') - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.saleDescriptorPopoverSummaryButton); + await page.waitForURL('/summary'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/summary'); }); it('should return to ticket sales section', async() => { - const url = await nightmare - .waitToClick(selectors.globalItems.applicationsMenuButton) - .wait(selectors.globalItems.applicationsMenuVisible) - .waitToClick(selectors.globalItems.ticketsButton) - .accessToSearchResult(16) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.waitToClick(selectors.globalItems.applicationsMenuButton); + await page.wait(selectors.globalItems.applicationsMenuVisible); + await page.waitToClick(selectors.globalItems.ticketsButton); + await page.accessToSearchResult(16); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); it('should try to add a higher quantity value and then receive an error', async() => { - const result = await nightmare - .focusElement(selectors.ticketSales.firstSaleQuantityCell) - .write(selectors.ticketSales.firstSaleQuantity, '11\u000d') - .waitForLastSnackbar(); + await page.focusElement(selectors.ticketSales.firstSaleQuantityCell); + await page.write(selectors.ticketSales.firstSaleQuantity, '11\u000d'); + const message = await page.waitForSnackbar(); - expect(result).toEqual('The new quantity should be smaller than the old one'); + expect(message.text).toBe('The new quantity should be smaller than the old one'); }); it('should remove 1 from the first sale quantity', async() => { - const result = await nightmare - .focusElement(selectors.ticketSales.firstSaleQuantityCell) - .write(selectors.ticketSales.firstSaleQuantity, '9\u000d') - .waitForLastSnackbar(); + await page.focusElement(selectors.ticketSales.firstSaleQuantityCell); + await page.write(selectors.ticketSales.firstSaleQuantity, '9\u000d'); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should update the price', async() => { - const result = await nightmare - .waitToClick(`${selectors.ticketSales.firstSalePrice} > span`) - .write(selectors.ticketSales.firstSalePriceInput, '5\u000d') - .waitForLastSnackbar(); + await page.waitToClick(`${selectors.ticketSales.firstSalePrice} > span`); + await page.write(selectors.ticketSales.firstSalePriceInput, '5\u000d'); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the price have been updated', async() => { - const result = await nightmare - .waitToGetProperty(`${selectors.ticketSales.firstSalePrice} span`, 'innerText'); + const result = await page.waitToGetProperty(`${selectors.ticketSales.firstSalePrice} span`, 'innerText'); expect(result).toContain('5.00'); }); it('should confirm the total price for that item have been updated', async() => { - const result = await nightmare - .waitToGetProperty(selectors.ticketSales.firstSaleImport, 'innerText'); + const result = await page.waitToGetProperty(selectors.ticketSales.firstSaleImport, 'innerText'); expect(result).toContain('45.00'); }); it('should update the discount', async() => { - const result = await nightmare - .waitToClick(`${selectors.ticketSales.firstSaleDiscount} > span`) - .write(selectors.ticketSales.firstSaleDiscountInput, '50\u000d') - .waitForLastSnackbar(); + await page.waitToClick(`${selectors.ticketSales.firstSaleDiscount} > span`); + await page.write(selectors.ticketSales.firstSaleDiscountInput, '50\u000d'); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the discount have been updated', async() => { - const result = await nightmare - .waitForTextInElement(`${selectors.ticketSales.firstSaleDiscount} > span`, '50.00%') - .waitToGetProperty(`${selectors.ticketSales.firstSaleDiscount} > span`, 'innerText'); + await page.waitForTextInElement(`${selectors.ticketSales.firstSaleDiscount} > span`, '50.00%'); + const result = await page.waitToGetProperty(`${selectors.ticketSales.firstSaleDiscount} > span`, 'innerText'); expect(result).toContain('50.00%'); }); it('should confirm the total import for that item have been updated', async() => { - const result = await nightmare - .waitForTextInElement(selectors.ticketSales.firstSaleImport, '22.50') - .waitToGetProperty(selectors.ticketSales.firstSaleImport, 'innerText'); + await page.waitForTextInElement(selectors.ticketSales.firstSaleImport, '22.50'); + const result = await page.waitToGetProperty(selectors.ticketSales.firstSaleImport, 'innerText'); expect(result).toContain('22.50'); }); it('should select the third sale and create a claim of it', async() => { - const url = await nightmare - .waitToClick(selectors.ticketSales.thirdSaleCheckbox) - .waitToClick(selectors.ticketSales.moreMenu) - .waitToClick(selectors.ticketSales.moreMenuCreateClaim) - .wait(selectors.claimBasicData.claimState) - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketSales.moreMenu); + await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim); + await page.wait(selectors.claimBasicData.claimState); + const url = await page.parsedUrl(); expect(url.hash).toContain('basic-data'); }); it('should click on the Claims button of the top bar menu', async() => { - const url = await nightmare - .waitToClick(selectors.globalItems.applicationsMenuButton) - .wait(selectors.globalItems.applicationsMenuVisible) - .waitToClick(selectors.globalItems.claimsButton) - .wait(selectors.claimsIndex.searchClaimInput) - .parsedUrl(); + await page.waitToClick(selectors.globalItems.applicationsMenuButton); + await page.wait(selectors.globalItems.applicationsMenuVisible); + await page.waitToClick(selectors.globalItems.claimsButton); + await page.wait(selectors.claimsIndex.searchClaimInput); + const url = await page.parsedUrl(); expect(url.hash).toEqual('#!/claim/index'); }); it('should search for the claim with id 4', async() => { - const result = await nightmare - .write(selectors.claimsIndex.searchClaimInput, 4) - .waitToClick(selectors.claimsIndex.searchButton) - .waitForNumberOfElements(selectors.claimsIndex.searchResult, 1) - .countElement(selectors.claimsIndex.searchResult); + await page.write(selectors.claimsIndex.searchClaimInput, 4); + await page.waitToClick(selectors.claimsIndex.searchButton); + await page.waitForNumberOfElements(selectors.claimsIndex.searchResult, 1); + const result = await page.countElement(selectors.claimsIndex.searchResult); expect(result).toEqual(1); }); it('should click the Tickets button of the top bar menu', async() => { - const url = await nightmare - .waitToClick(selectors.globalItems.applicationsMenuButton) - .wait(selectors.globalItems.applicationsMenuVisible) - .waitToClick(selectors.globalItems.ticketsButton) - .wait(selectors.ticketsIndex.topbarSearch) - .parsedUrl(); + await page.waitToClick(selectors.globalItems.applicationsMenuButton); + await page.wait(selectors.globalItems.applicationsMenuVisible); + await page.waitToClick(selectors.globalItems.ticketsButton); + await page.wait(selectors.ticketsIndex.topbarSearch); + const url = await page.parsedUrl(); expect(url.hash).toEqual('#!/ticket/index'); }); it('should search for a ticket then access to the sales section', async() => { - const url = await nightmare - .accessToSearchResult(16) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.accessToSearchResult(16); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); it('should select the third sale and delete it', async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.thirdSaleCheckbox) - .waitToClick(selectors.ticketSales.deleteSaleButton) - .waitToClick(selectors.ticketSales.acceptDeleteLineButton) - .waitForSpinnerLoad() - .waitForLastSnackbar(); + await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketSales.deleteSaleButton); + await page.waitToClick(selectors.ticketSales.acceptDeleteLineButton); + await page.waitForSpinnerLoad(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the third sale was deleted`, async() => { - const result = await nightmare - .countElement(selectors.ticketSales.saleLine); + const result = await page.countElement(selectors.ticketSales.saleLine); expect(result).toEqual(3); }); @@ -265,67 +238,60 @@ xdescribe('Ticket Edit sale path', () => { it('should select the second sale and transfer it to a valid ticket', async() => { const targetTicketId = 12; - const result = await nightmare - .waitToClick(selectors.ticketSales.secondSaleCheckbox) - .waitToClick(selectors.ticketSales.transferSaleButton) - .focusElement(selectors.ticketSales.transferQuantityCell) - .write(selectors.ticketSales.transferQuantityInput, '10\u000d') - .write(selectors.ticketSales.moveToTicketInput, targetTicketId) - .waitToClick(selectors.ticketSales.moveToTicketButton) - .waitForURL(`ticket/${targetTicketId}/sale`) - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.secondSaleCheckbox); + await page.waitToClick(selectors.ticketSales.transferSaleButton); + await page.focusElement(selectors.ticketSales.transferQuantityCell); + await page.write(selectors.ticketSales.transferQuantityInput, '10\u000d'); + await page.write(selectors.ticketSales.moveToTicketInput, targetTicketId); + await page.waitToClick(selectors.ticketSales.moveToTicketButton); + await page.waitForURL(`ticket/${targetTicketId}/sale`); + const result = await page.parsedUrl(); expect(result.hash).toContain(`ticket/${targetTicketId}/sale`); }); it('should confirm the transfered line is the correct one', async() => { - const result = await nightmare - .wait(selectors.ticketSales.secondSaleText) - .waitToGetProperty(selectors.ticketSales.secondSaleText, 'innerText'); + await page.wait(selectors.ticketSales.secondSaleText); + const result = await page.waitToGetProperty(selectors.ticketSales.secondSaleText, 'innerText'); expect(result).toContain(`Melee weapon heavy shield`); }); it('should confirm the transfered quantity is the correct one', async() => { - const result = await nightmare - .waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); + const result = await page.waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); expect(result).toContain('10'); }); it('should go back to the original ticket sales section', async() => { - const url = await nightmare - .waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton) - .accessToSearchResult(16) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton); + await page.accessToSearchResult(16); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); it(`should confirm the original ticket has still three lines`, async() => { - const result = await nightmare - .wait(selectors.ticketSales.saleLine) - .countElement(selectors.ticketSales.saleLine); + await page.wait(selectors.ticketSales.saleLine); + const result = await page.countElement(selectors.ticketSales.saleLine); expect(result).toEqual(3); }); it(`should confirm the second sale quantity is now half of it's original value after the transfer`, async() => { - const result = await nightmare - .waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); + const result = await page.waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); expect(result).toContain('10'); }); it('should go back to the receiver ticket sales section', async() => { - const url = await nightmare - .waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton) - .accessToSearchResult(12) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton); + await page.accessToSearchResult(12); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); @@ -333,44 +299,40 @@ xdescribe('Ticket Edit sale path', () => { it('should transfer the sale back to the original ticket', async() => { const targetTicketId = 16; - const result = await nightmare - .waitToClick(selectors.ticketSales.secondSaleCheckbox) - .waitToClick(selectors.ticketSales.transferSaleButton) - .write(selectors.ticketSales.moveToTicketInput, targetTicketId) - .waitToClick(selectors.ticketSales.moveToTicketButton) - .waitForURL(`ticket/${targetTicketId}/sale`) - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.secondSaleCheckbox); + await page.waitToClick(selectors.ticketSales.transferSaleButton); + await page.write(selectors.ticketSales.moveToTicketInput, targetTicketId); + await page.waitToClick(selectors.ticketSales.moveToTicketButton); + await page.waitForURL(`ticket/${targetTicketId}/sale`); + const result = await page.parsedUrl(); expect(result.hash).toContain(`ticket/${targetTicketId}/sale`); }); it('should confirm the original ticket received the line', async() => { const expectedLines = 4; - const result = await nightmare - .waitForNumberOfElements(selectors.ticketSales.saleLine, expectedLines) - .countElement(selectors.ticketSales.saleLine); + await page.waitForNumberOfElements(selectors.ticketSales.saleLine, expectedLines); + const result = await page.countElement(selectors.ticketSales.saleLine); expect(result).toEqual(expectedLines); }); it(`should throw an error when attempting to create a ticket for an inactive client`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleCheckbox) - .waitToClick(selectors.ticketSales.transferSaleButton) - .waitToClick(selectors.ticketSales.moveToNewTicketButton) - .waitToClick(selectors.ticketSales.acceptDeleteTicketButton) - .waitForLastSnackbar(); + await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); + await page.waitToClick(selectors.ticketSales.transferSaleButton); + await page.waitToClick(selectors.ticketSales.moveToNewTicketButton); + await page.waitToClick(selectors.ticketSales.acceptDeleteTicketButton); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`You can't create a ticket for a inactive client`); + expect(message.text).toBe(`You can't create a ticket for a inactive client`); }); it('should go now to the ticket sales section of an active, not frozen client', async() => { - const url = await nightmare - .waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton) - .accessToSearchResult(13) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton); + await page.accessToSearchResult(13); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); @@ -378,118 +340,106 @@ xdescribe('Ticket Edit sale path', () => { it(`should select all sales, tranfer them to a new ticket and delete the sender ticket as it would've been left empty`, async() => { const senderTicketId = 13; - const url = await nightmare - .waitToClick(selectors.ticketSales.selectAllSalesCheckbox) - .waitToClick(selectors.ticketSales.transferSaleButton) - .waitToClick(selectors.ticketSales.moveToNewTicketButton) - .waitToClick(selectors.ticketSales.acceptDeleteTicketButton) - .wait((selector, ticketId) => { - return document.querySelector(selector).innerText.toLowerCase().indexOf(`${ticketId}`) == -1; - }, selectors.ticketDescriptor.idLabelValue, senderTicketId) - .parsedUrl(); + await page.waitToClick(selectors.ticketSales.selectAllSalesCheckbox); + await page.waitToClick(selectors.ticketSales.transferSaleButton); + await page.waitToClick(selectors.ticketSales.moveToNewTicketButton); + await page.waitToClick(selectors.ticketSales.acceptDeleteTicketButton); + await page.wait((selector, ticketId) => { + return document.querySelector(selector).innerText.toLowerCase().indexOf(`${ticketId}`) == -1; + }, selectors.ticketDescriptor.idLabelValue, senderTicketId); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); it('should confirm the new ticket received the line', async() => { - const result = await nightmare - .countElement(selectors.ticketSales.saleLine); + const result = await page.countElement(selectors.ticketSales.saleLine); expect(result).toEqual(1); }); it('should check the first sale reserved icon isnt visible', async() => { - const result = await nightmare - .isVisible(selectors.ticketSales.firstSaleReservedIcon); + const result = await page.isVisible(selectors.ticketSales.firstSaleReservedIcon); expect(result).toBeFalsy(); }); it('should mark the first sale as reserved', async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleCheckbox) - .waitToClick(selectors.ticketSales.moreMenu) - .waitToClick(selectors.ticketSales.moreMenuReserve) - .waitForClassNotPresent(selectors.ticketSales.firstSaleReservedIcon, 'ng-hide') - .isVisible(selectors.ticketSales.firstSaleReservedIcon); + await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); + await page.waitToClick(selectors.ticketSales.moreMenu); + await page.waitToClick(selectors.ticketSales.moreMenuReserve); + await page.waitForClassNotPresent(selectors.ticketSales.firstSaleReservedIcon, 'ng-hide'); + const result = await page.isVisible(selectors.ticketSales.firstSaleReservedIcon); expect(result).toBeTruthy(); }); it('should unmark the first sale as reserved', async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.moreMenu) - .waitToClick(selectors.ticketSales.moreMenuUnmarkReseved) - .waitForClassPresent(selectors.ticketSales.firstSaleReservedIcon, 'ng-hide') - .isVisible(selectors.ticketSales.firstSaleReservedIcon); + await page.waitToClick(selectors.ticketSales.moreMenu); + await page.waitToClick(selectors.ticketSales.moreMenuUnmarkReseved); + await page.waitForClassPresent(selectors.ticketSales.firstSaleReservedIcon, 'ng-hide'); + const result = await page.isVisible(selectors.ticketSales.firstSaleReservedIcon); expect(result).toBeFalsy(); }); it('should update all sales discount', async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.moreMenu) - .waitToClick(selectors.ticketSales.moreMenuUpdateDiscount) - // .write(selectors.ticketSales.moreMenuUpdateDiscountInput, 100) can't find the selector on app (deleted the selector), menu option was removed? - .write('body', '\u000d') - .waitForTextInElement(selectors.ticketSales.totalImport, '0.00') - .waitToGetProperty(selectors.ticketSales.totalImport, 'innerText'); + await page.waitToClick(selectors.ticketSales.moreMenu); + await page.waitToClick(selectors.ticketSales.moreMenuUpdateDiscount); + // .write(selectors.ticketSales.moreMenuUpdateDiscountInput, 100) can't find the selector on app (deleted the selector), menu option was removed? + await page.write('body', '\u000d'); + await page.waitForTextInElement(selectors.ticketSales.totalImport, '0.00'); + const result = await page.waitToGetProperty(selectors.ticketSales.totalImport, 'innerText'); expect(result).toContain('0.00'); }); it('should log in as Production role and go to a target ticket summary', async() => { - const url = await nightmare - .loginAndModule('production', 'ticket') - .accessToSearchResult(13) - .waitForURL('/summary') - .parsedUrl(); + await page.loginAndModule('production', 'ticket'); + await page.accessToSearchResult(13); + await page.waitForURL('/summary'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/summary'); }); it(`should check it's state is deleted`, async() => { - const result = await nightmare - .waitToGetProperty(selectors.ticketDescriptor.stateLabelValue, 'innerText'); + const result = await page.waitToGetProperty(selectors.ticketDescriptor.stateLabelValue, 'innerText'); expect(result).toEqual('State Eliminado'); }); describe('when state is preparation and loged as Production', () => { it(`should not be able to edit the sale price`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton) - .accessToSearchResult(8) - .accessToSection('ticket.card.sale') - .waitToClick(selectors.ticketSales.firstSalePrice) - .exists(selectors.ticketSales.firstSalePriceInput); + await page.waitToClick(selectors.ticketDescriptor.goBackToModuleIndexButton); + await page.accessToSearchResult(8); + await page.accessToSection('ticket.card.sale'); + await page.waitToClick(selectors.ticketSales.firstSalePrice); + const result = await page.exists(selectors.ticketSales.firstSalePriceInput); expect(result).toBeFalsy(); }); it(`should not be able to edit the sale discount`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleDiscount) - .exists(selectors.ticketSales.firstSaleDiscountInput); + await page.waitToClick(selectors.ticketSales.firstSaleDiscount); + const result = await page.exists(selectors.ticketSales.firstSaleDiscountInput); expect(result).toBeFalsy(); }); it(`should not be able to edit the sale state`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.stateMenuButton) - .exists(selectors.ticketSales.stateMenuOptions); + await page.waitToClick(selectors.ticketSales.stateMenuButton); + const result = await page.exists(selectors.ticketSales.stateMenuOptions); expect(result).toBeFalsy(); }); it('should log in as salesPerson then go to the sales of a target ticket', async() => { - const url = await nightmare - .loginAndModule('salesPerson', 'ticket') - .accessToSearchResult(8) - .accessToSection('ticket.card.sale') - .waitForURL('/sale') - .parsedUrl(); + await page.loginAndModule('salesPerson', 'ticket'); + await page.accessToSearchResult(8); + await page.accessToSection('ticket.card.sale'); + await page.waitForURL('/sale'); + const url = await page.parsedUrl(); expect(url.hash).toContain('/sale'); }); @@ -497,25 +447,22 @@ xdescribe('Ticket Edit sale path', () => { describe('when state is preparation and loged as salesPerson', () => { it(`shouldn't be able to edit the sale price`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.firstSalePrice) - .exists(selectors.ticketSales.firstSalePriceInput); + await page.waitToClick(selectors.ticketSales.firstSalePrice); + const result = await page.exists(selectors.ticketSales.firstSalePriceInput); expect(result).toBeFalsy(); }); it(`should be able to edit the sale discount`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleDiscount) - .exists(selectors.ticketSales.firstSaleDiscountInput); + await page.waitToClick(selectors.ticketSales.firstSaleDiscount); + const result = await page.exists(selectors.ticketSales.firstSaleDiscountInput); expect(result).toBeFalsy(); }); it(`should not be able to edit the sale state`, async() => { - const result = await nightmare - .waitToClick(selectors.ticketSales.stateMenuButton) - .exists(selectors.ticketSales.stateMenuOptions); + await page.waitToClick(selectors.ticketSales.stateMenuButton); + const result = await page.exists(selectors.ticketSales.stateMenuOptions); expect(result).toBeFalsy(); }); diff --git a/e2e/paths/05-ticket/01_observations.spec.js b/e2e/paths/05-ticket/01_observations.spec.js index cccfa8b67..d919b8ed3 100644 --- a/e2e/paths/05-ticket/01_observations.spec.js +++ b/e2e/paths/05-ticket/01_observations.spec.js @@ -22,9 +22,9 @@ describe('Ticket Create notes path', () => { await page.autocompleteSearch(selectors.ticketNotes.firstNoteType, 'observation one'); await page.write(selectors.ticketNotes.firstDescription, 'description'); await page.waitToClick(selectors.ticketNotes.submitNotesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the note is the expected one', async() => { @@ -43,8 +43,8 @@ describe('Ticket Create notes path', () => { it('should delete the note', async() => { await page.waitToClick(selectors.ticketNotes.firstNoteRemoveButton); await page.waitToClick(selectors.ticketNotes.submitNotesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index 94fad9b69..2d046e3a9 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -19,8 +19,9 @@ describe('Ticket expeditions and log path', () => { it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => { await page.waitToClick(selectors.ticketExpedition.secondExpeditionRemoveButton); - await page.waitToClick(selectors.ticketExpedition.acceptDeleteRowButton), + await page.waitToClick(selectors.ticketExpedition.acceptDeleteRowButton); await page.reloadSection('ticket.card.expedition'); + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); const result = await page .countElement(selectors.ticketExpedition.expeditionRow); @@ -29,7 +30,7 @@ describe('Ticket expeditions and log path', () => { }); it(`should confirm the expedition deleted is shown now in the ticket log`, async() => { - await page.waitToClick(selectors.ticketLog.logButton); + await page.accessToSection('ticket.card.log'); const changedBy = await page .waitToGetProperty(selectors.ticketLog.changedBy, 'innerText'); diff --git a/e2e/paths/05-ticket/04_packages.spec.js b/e2e/paths/05-ticket/04_packages.spec.js index fd2945877..3db53587c 100644 --- a/e2e/paths/05-ticket/04_packages.spec.js +++ b/e2e/paths/05-ticket/04_packages.spec.js @@ -22,18 +22,18 @@ describe('Ticket Create packages path', () => { await page.waitToClick(selectors.ticketPackages.addPackageButton); await page.write(selectors.ticketPackages.firstQuantity, '99'); await page.waitToClick(selectors.ticketPackages.savePackagesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Package cannot be blank'); + expect(message.text).toBe('Package cannot be blank'); }); it(`should delete the first package and receive and error to save a new one with blank quantity`, async() => { await page.clearInput(selectors.ticketPackages.firstQuantity); await page.autocompleteSearch(selectors.ticketPackages.firstPackage, 'Container medical box 1m'); await page.waitToClick(selectors.ticketPackages.savePackagesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Some fields are invalid'); + expect(message.text).toBe('Some fields are invalid'); }); it(`should confirm the quantity input isn't invalid yet`, async() => { @@ -49,9 +49,9 @@ describe('Ticket Create packages path', () => { await page.clearInput(selectors.ticketPackages.firstQuantity); await page.write(selectors.ticketPackages.firstQuantity, '-99'); await page.waitToClick(selectors.ticketPackages.savePackagesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the first select is the expected one`, async() => { diff --git a/e2e/paths/05-ticket/05_tracking_state.spec.js b/e2e/paths/05-ticket/05_tracking_state.spec.js index 108e8776f..34f3c4d44 100644 --- a/e2e/paths/05-ticket/05_tracking_state.spec.js +++ b/e2e/paths/05-ticket/05_tracking_state.spec.js @@ -21,24 +21,22 @@ describe('Ticket Create new tracking state path', () => { it('should access to the create state view by clicking the create floating button', async() => { await page.waitToClick(selectors.ticketTracking.createStateButton); await page.waitForSelector(selectors.createStateView.state, {visible: true}); - let url = await page.expectURL('tracking/edit'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.tracking.edit'); }); it(`should attempt create a new state but receive an error if state is empty`, async() => { await page.waitToClick(selectors.createStateView.saveStateButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('State cannot be blank'); + expect(message.text).toBe('State cannot be blank'); }); it(`should create a new state`, async() => { await page.autocompleteSearch(selectors.createStateView.state, '¿Fecha?'); await page.waitToClick(selectors.createStateView.saveStateButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); }); @@ -51,23 +49,21 @@ describe('Ticket Create new tracking state path', () => { it('should now access to the create state view by clicking the create floating button', async() => { await page.waitToClick(selectors.ticketTracking.createStateButton); - let url = await page.expectURL('tracking/edit'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.tracking.edit'); }); it(`should attemp to create an state for which salesPerson doesn't have permissions`, async() => { await page.waitFor(1500); await page.autocompleteSearch(selectors.createStateView.state, 'Encajado'); await page.waitToClick(selectors.createStateView.saveStateButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`You don't have enough privileges`); + expect(message.text).toBe(`You don't have enough privileges`); }); it(`should make sure the worker gets autocomplete uppon selecting the assigned state`, async() => { await page.autocompleteSearch(selectors.createStateView.state, 'asignado'); - let result = await page + const result = await page .waitToGetProperty(selectors.createStateView.worker, 'value'); expect(result).toEqual('salesPersonNick'); @@ -75,9 +71,9 @@ describe('Ticket Create new tracking state path', () => { it(`should succesfully create a valid state`, async() => { await page.waitToClick(selectors.createStateView.saveStateButton); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); }); }); diff --git a/e2e/paths/05-ticket/06_basic_data_steps.spec.js b/e2e/paths/05-ticket/06_basic_data_steps.spec.js index de78b9fa7..3191673a5 100644 --- a/e2e/paths/05-ticket/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket/06_basic_data_steps.spec.js @@ -68,9 +68,7 @@ describe('Ticket Edit basic data path', () => { it(`should click next`, async() => { await page.waitToClick(selectors.ticketBasicData.nextStepButton); - let url = await page.expectURL('data/step-two'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.basicData.stepTwo'); }); it(`should have a price diference`, async() => { @@ -83,8 +81,6 @@ describe('Ticket Edit basic data path', () => { it(`should select a new reason for the changes made then click on finalize`, async() => { await page.waitToClick(selectors.ticketBasicData.chargesReason); await page.waitToClick(selectors.ticketBasicData.finalizeButton); - let url = await page.expectURL('summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); }); diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index 3e791dc18..79722d2f7 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -17,7 +17,6 @@ describe('Ticket descriptor path', () => { }); it('should count the amount of tickets in the turns section', async() => { - await page.waitForNumberOfElements(selectors.ticketsIndex.weeklyTicket, 5); const result = await page.countElement(selectors.ticketsIndex.weeklyTicket); expect(result).toEqual(5); @@ -32,18 +31,16 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuAddToTurn); await page.waitToClick(selectors.ticketDescriptor.thursdayButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should again click on the Tickets button of the top bar menu', async() => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should confirm the ticket 11 was added to thursday', async() => { @@ -57,43 +54,28 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should now search for the ticket 11', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '11'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result to access to the ticket`, async() => { - await page.waitToClick(selectors.ticketsIndex.searchResult); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.accessToSearchResult('11'); + await page.waitForState('ticket.card.summary'); }); it('should add the ticket to saturday turn using the descriptor more menu', async() => { await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuAddToTurn); await page.waitToClick(selectors.ticketDescriptor.saturdayButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should click on the Tickets button of the top bar menu once again', async() => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should confirm the ticket 11 was added on saturday', async() => { @@ -104,29 +86,36 @@ describe('Ticket descriptor path', () => { }); it('should now search for the weekly ticket 11', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '11'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchWeeklyResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); + await page.doSearch('11'); + const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); - expect(result).toEqual(1); + expect(nResults).toEqual(1); }); it('should delete the weekly ticket 11', async() => { await page.waitToClick(selectors.ticketsIndex.firstWeeklyTicketDeleteIcon); await page.waitToClick(selectors.ticketsIndex.acceptDeleteTurn); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the sixth weekly ticket was deleted', async() => { - await page.waitForContentLoaded(); - await page.clearInput('vn-searchbar'); - await page.waitToClick(selectors.ticketsIndex.searchWeeklyButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchWeeklyResult, 5); - const result = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); + await page.doSearch(); + const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); - expect(result).toEqual(5); + expect(nResults).toEqual(5); + }); + + it('should update the agency then remove it afterwards', async() => { + await page.autocompleteSearch(selectors.ticketsIndex.firstWeeklyTicketAgency, 'Silla247'); + let message = await page.waitForSnackbar(); + + expect(message.type).toBe('success'); + + await page.clearInput(selectors.ticketsIndex.firstWeeklyTicketAgency); + message = await page.waitForSnackbar(); + + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/05-ticket/10_request.spec.js b/e2e/paths/05-ticket/10_request.spec.js index 737d69048..334b8ba5e 100644 --- a/e2e/paths/05-ticket/10_request.spec.js +++ b/e2e/paths/05-ticket/10_request.spec.js @@ -24,24 +24,21 @@ describe('Ticket purchase request path', () => { await page.autocompleteSearch(selectors.ticketRequests.atender, 'buyerNick'); await page.write(selectors.ticketRequests.price, '999'); await page.waitToClick(selectors.ticketRequests.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should have been redirected to the request index', async() => { - let url = await page.expectURL('/request'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.request.index'); }); it(`should edit the third request quantity as it's state is still new`, async() => { - await page.waitFor(2000); // looks like it needs more than a single second some times to load await page.write(selectors.ticketRequests.thirdRequestQuantity, '9'); await page.keyboard.press('Enter'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the new request was added', async() => { @@ -67,9 +64,9 @@ describe('Ticket purchase request path', () => { it('should delete the added request', async() => { await page.waitToClick(selectors.ticketRequests.thirdRemoveRequestButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the request was deleted', async() => { diff --git a/e2e/paths/05-ticket/11_diary.spec.js b/e2e/paths/05-ticket/11_diary.spec.js index b529ee1ff..a75e1ae24 100644 --- a/e2e/paths/05-ticket/11_diary.spec.js +++ b/e2e/paths/05-ticket/11_diary.spec.js @@ -1,66 +1,31 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -// #2026 Fallo en relocate de descriptor popover +// #2221 Local MySQL8 crashes when rest method Items/getDiary is called xdescribe('Ticket diary path', () => { - let browser; let page; beforeAll(async() => { - browser = await getBrowser(); - page = browser.page; + page = (await getBrowser()).page; await page.loginAndModule('employee', 'ticket'); }); afterAll(async() => { - await browser.close(); + await page.browser().close(); }); - it('should search for a specific ticket', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '1'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result to access to the ticket summary`, async() => { - await page.waitForTextInElement(selectors.ticketsIndex.searchResult, 'Bat cave'); - await page.waitToClick(selectors.ticketsIndex.searchResult); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); - }); - - it(`should navigate to the item diary from the 1st sale item id descriptor popover`, async() => { + it(`should navigate to item diary from ticket sale and check the lines`, async() => { + await page.accessToSearchResult('1'); await page.waitToClick(selectors.ticketSummary.firstSaleItemId); - await page.waitForTransitionEnd('.vn-popover'); await page.waitToClick(selectors.ticketSummary.popoverDiaryButton); - let url = await page.expectURL('/diary'); + await page.waitForState('item.card.diary'); - expect(url).toBe(true); - }); + const secondIdClass = await page.getClassName(selectors.itemDiary.secondTicketId); + const fourthBalanceClass = await page.getClassName(selectors.itemDiary.fourthBalance); + const firstBalanceClass = await page.getClassName(selectors.itemDiary.firstBalance); - it(`should check the second line id is marked as message`, async() => { - const result = await page - .waitToGetProperty(selectors.itemDiary.secondTicketId, 'className'); - - expect(result).toContain('message'); - }); - - it(`should check the third line balance is marked as message`, async() => { - const result = await page - .waitToGetProperty(`${selectors.itemDiary.fourthBalance} > span`, 'className'); - - expect(result).toContain('message'); - }); - - it(`should change to the warehouse two and check there are sales marked as negative balance`, async() => { - await page.autocompleteSearch(selectors.itemDiary.warehouse, 'Warehouse Two'); - const result = await page - .waitToGetProperty(selectors.itemDiary.firstBalance, 'className'); - - expect(result).toContain('balance'); + expect(secondIdClass).toContain('message'); + expect(fourthBalanceClass).toContain('message'); + expect(firstBalanceClass).toContain('balance'); }); }); diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index 59691d380..87990bcc5 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -18,9 +18,7 @@ describe('Ticket descriptor path', () => { describe('Delete ticket', () => { it('should search for an specific ticket', async() => { await page.accessToSearchResult('18'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should update the shipped hour using the descriptor menu`, async() => { @@ -28,9 +26,9 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.ticketDescriptor.moreMenuChangeShippedHour); await page.pickTime(selectors.ticketDescriptor.changeShippedHour, '08:15'); await page.waitToClick(selectors.ticketDescriptor.acceptChangeHourButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Shipped hour updated'); + expect(message.text).toBe('Shipped hour updated'); }); it(`should confirm the ticket descriptor shows the correct shipping hour`, async() => { @@ -44,22 +42,19 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); await page.waitToClick(selectors.ticketDescriptor.acceptDeleteButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Ticket deleted'); + expect(message.text).toBe('Ticket deleted'); }); it('should have been relocated to the ticket index', async() => { - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it(`should search for the deleted ticket and check it's date`, async() => { await page.write(selectors.ticketsIndex.topbarSearch, '18'); await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - await page.wait(selectors.ticketsIndex.searchResultDate); + await page.waitForState('ticket.card.summary'); const result = await page.waitToGetProperty(selectors.ticketsIndex.searchResultDate, 'innerText'); expect(result).toContain(2000); @@ -69,9 +64,7 @@ describe('Ticket descriptor path', () => { describe('add stowaway', () => { it('should search for a ticket', async() => { await page.accessToSearchResult('16'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should open the add stowaway dialog', async() => { @@ -89,9 +82,9 @@ describe('Ticket descriptor path', () => { it('should add a ticket as stowaway', async() => { await page.waitToClick(selectors.ticketDescriptor.addStowawayDialogFirstTicket); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should check the state of the stowaway ticket is embarked`, async() => { @@ -102,19 +95,17 @@ describe('Ticket descriptor path', () => { it(`should navigate back to the added ticket using the descriptors ship button`, async() => { await page.waitToClick(selectors.ticketDescriptor.shipButton); - let url = await page.expectURL('#!/ticket/17/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should delete the stowaway', async() => { - await page.waitForContentLoaded(); await page.waitToClick(selectors.ticketDescriptor.moreMenu); + await page.waitForContentLoaded(); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteStowawayButton); await page.waitToClick(selectors.ticketDescriptor.acceptDeleteStowawayButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the ship buton doesn't exisist any more`, async() => { @@ -128,9 +119,7 @@ describe('Ticket descriptor path', () => { await page.loginAndModule('adminBoss', 'ticket'); await page.accessToSearchResult(invoiceableTicketId); - let url = await page.expectURL(`ticket/${invoiceableTicketId}/summary`); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should make sure the ticket doesn't have an invoiceOutFk yet`, async() => { @@ -141,13 +130,13 @@ describe('Ticket descriptor path', () => { }); it('should invoice the ticket using the descriptor more menu', async() => { - await page.waitForContentLoaded(); await page.waitToClick(selectors.ticketDescriptor.moreMenu); + await page.waitForContentLoaded(); await page.waitToClick(selectors.ticketDescriptor.moreMenuMakeInvoice); await page.waitToClick(selectors.ticketDescriptor.acceptInvoiceOutButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Ticket invoiced'); + expect(message.text).toBe('Ticket invoiced'); }); it(`should make sure the ticket summary have an invoiceOutFk`, async() => { diff --git a/e2e/paths/05-ticket/13_services.spec.js b/e2e/paths/05-ticket/13_services.spec.js index 07a0a5768..08b9219a5 100644 --- a/e2e/paths/05-ticket/13_services.spec.js +++ b/e2e/paths/05-ticket/13_services.spec.js @@ -32,9 +32,9 @@ describe('Ticket services path', () => { await page.clearInput(selectors.ticketService.firstPrice); await page.write(selectors.ticketService.firstPrice, '999'); await page.waitToClick(selectors.ticketService.saveServiceButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`The current ticket can't be modified`); + expect(message.text).toBe(`The current ticket can't be modified`); }); }); @@ -44,9 +44,6 @@ describe('Ticket services path', () => { await page.loginAndModule('administrative', 'ticket'); await page.accessToSearchResult(editableTicketId); await page.accessToSection('ticket.card.service'); - let url = await page.expectURL('/service'); - - expect(url).toBe(true); }); it('should click on the add button to prepare the form to create a new service', async() => { @@ -59,9 +56,9 @@ describe('Ticket services path', () => { it('should receive an error if you attempt to save it with empty fields', async() => { await page.waitToClick(selectors.ticketService.saveServiceButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`can't be blank`); + expect(message.text).toBe(`can't be blank`); }); it('should click on the add new service type to open the dialog', async() => { @@ -74,9 +71,9 @@ describe('Ticket services path', () => { it('should receive an error if service type is empty on submit', async() => { await page.waitToClick(selectors.ticketService.saveServiceTypeButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`Name can't be empty`); + expect(message.text).toBe(`Name can't be empty`); }); it('should create a new service type then add price then create the service', async() => { @@ -84,11 +81,10 @@ describe('Ticket services path', () => { await page.autocompleteSearch(selectors.ticketService.newServiceTypeExpense, 'Retencion'); await page.waitToClick(selectors.ticketService.saveServiceTypeButton); await page.write(selectors.ticketService.firstPrice, '999'); - await page.waitFor(1000); // time needed for the button to be clickable await page.waitToClick(selectors.ticketService.saveServiceButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the service description was created correctly', async() => { @@ -123,19 +119,17 @@ describe('Ticket services path', () => { it('should delete the service', async() => { await page.waitToClick(selectors.ticketService.fistDeleteServiceButton); await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0); - await page.waitFor(1000); // without this wait it fails to click the save button await page.waitToClick(selectors.ticketService.saveServiceButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the service was removed`, async() => { await page.reloadSection('ticket.card.service'); - await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0); - const result = await page.countElement(selectors.ticketService.serviceLine); + const nResults = await page.countElement(selectors.ticketService.serviceLine); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); }); }); diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index e501ea0ef..4ce2e5156 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -17,26 +17,25 @@ describe('Ticket create path', () => { it('should open the new ticket form', async() => { await page.waitToClick(selectors.ticketsIndex.newTicketButton); - let url = await page.expectURL('#!/ticket/create'); - - expect(url).toBe(true); + await page.waitForState('ticket.create'); }); it('should succeed to create a ticket', async() => { + const nextMonth = new Date(); + nextMonth.setMonth(nextMonth.getMonth() + 1); + await page.autocompleteSearch(selectors.createTicketView.client, 'Tony Stark'); await page.autocompleteSearch(selectors.createTicketView.address, 'Tony Stark'); - await page.datePicker(selectors.createTicketView.deliveryDate, 1, null); + await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth); await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse One'); await page.autocompleteSearch(selectors.createTicketView.agency, 'Silla247'); await page.waitToClick(selectors.createTicketView.createButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should check the url is now the summary of the ticket', async() => { - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); }); diff --git a/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js b/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js index 28c11de3a..a68ce894e 100644 --- a/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js +++ b/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js @@ -19,9 +19,7 @@ describe('Ticket create from client path', () => { it('should click the create simple ticket on the descriptor menu', async() => { await page.waitToClick(selectors.clientDescriptor.moreMenu); await page.waitToClick(selectors.clientDescriptor.simpleTicketButton); - let url = await page.expectURL('clientFk=102'); - - expect(url).toBe(true); + await page.waitForState('ticket.create'); }); it('should check if the client details are the expected ones', async() => { @@ -31,7 +29,6 @@ describe('Ticket create from client path', () => { const address = await page .waitToGetProperty(selectors.createTicketView.address, 'value'); - expect(client).toContain('Petter Parker'); expect(address).toContain('20 Ingram Street'); }); diff --git a/e2e/paths/05-ticket/16_summary.spec.js b/e2e/paths/05-ticket/16_summary.spec.js index e7c6507d7..f6808651e 100644 --- a/e2e/paths/05-ticket/16_summary.spec.js +++ b/e2e/paths/05-ticket/16_summary.spec.js @@ -18,9 +18,7 @@ describe('Ticket Summary path', () => { it('should navigate to the target ticket summary section', async() => { await page.loginAndModule('employee', 'ticket'); await page.accessToSearchResult(ticketId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should display details from the ticket and it's client on the top of the header`, async() => { @@ -75,21 +73,19 @@ describe('Ticket Summary path', () => { it('should log in as production then navigate to the summary of the same ticket', async() => { await page.loginAndModule('production', 'ticket'); await page.accessToSearchResult(ticketId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should click on the SET OK button', async() => { await page.waitToClick(selectors.ticketSummary.setOk); - let result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the ticket state was updated', async() => { await page.waitForSpinnerLoad(); - let result = await page.waitToGetProperty(selectors.ticketSummary.state, 'innerText'); + const result = await page.waitToGetProperty(selectors.ticketSummary.state, 'innerText'); expect(result).toContain('OK'); }); diff --git a/e2e/paths/05-ticket/17_log.spec.js b/e2e/paths/05-ticket/17_log.spec.js index 2008d022e..97e121460 100644 --- a/e2e/paths/05-ticket/17_log.spec.js +++ b/e2e/paths/05-ticket/17_log.spec.js @@ -19,9 +19,7 @@ describe('Ticket log path', () => { await page.loginAndModule('employee', 'ticket'); await page.accessToSearchResult(ticketId); await page.accessToSection('ticket.card.observation'); - let url = await page.expectURL('/observation'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.observation'); }); it('should create a new note for the test', async() => { @@ -29,16 +27,13 @@ describe('Ticket log path', () => { await page.autocompleteSearch(selectors.ticketNotes.firstNoteType, 'observation one'); await page.write(selectors.ticketNotes.firstDescription, 'description'); await page.waitToClick(selectors.ticketNotes.submitNotesButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should navigate to the log section', async() => { await page.accessToSection('ticket.card.log'); - let url = await page.expectURL('/log'); - - expect(url).toBe(true); }); it('should set the viewport width to 1920 to see the table full width', async() => { diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js new file mode 100644 index 000000000..b1dc06e51 --- /dev/null +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -0,0 +1,58 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Ticket index payout path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should navigate to the ticket index', async() => { + await page.loginAndModule('administrative', 'ticket'); + await page.waitForState('ticket.index'); + }); + + it('should check three tickets 2 of a clinet and 1 of another', async() => { + await page.keyboard.press('Enter'); + await page.waitToClick(selectors.ticketsIndex.secondTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toBe('You cannot make a payment on account from multiple clients'); + }); + + it('should uncheck the sixth ticket result and check the third which is from the same client then open the payout form', async() => { + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.thirdTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + + await page.waitForSelector(selectors.ticketsIndex.payoutCompany); + }); + + it('should fill the company and bank to perform a payout', async() => { + await page.autocompleteSearch(selectors.ticketsIndex.payoutBank, 'cash'); + await page.waitToClick(selectors.ticketsIndex.submitPayout); + const message = await page.waitForSnackbar(); + + expect(message.type).toBe('success'); + }); + + it('should navigate to the client balance section and check a new balance line was entered', async() => { + await page.waitToClick(selectors.globalItems.homeButton); + await page.selectModule('client'); + await page.accessToSearchResult('101'); + await page.accessToSection('client.card.balance.index'); + await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + expect(result).toEqual(4); + }); +}); diff --git a/e2e/paths/06-claim/01_basic_data.spec.js b/e2e/paths/06-claim/01_basic_data.spec.js index 9718fb583..a255188e2 100644 --- a/e2e/paths/06-claim/01_basic_data.spec.js +++ b/e2e/paths/06-claim/01_basic_data.spec.js @@ -25,15 +25,13 @@ describe('Claim edit basic data path', () => { await page.clearTextarea(selectors.claimBasicData.observation); await page.write(selectors.claimBasicData.observation, 'edited observation'); await page.waitToClick(selectors.claimBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(message.type).toBe('success'); }); it(`should have been redirected to the next section of claims as the role is salesAssistant`, async() => { - let url = await page.expectURL('/detail'); - - expect(url).toBe(true); + await page.waitForState('claim.card.detail'); }); it('should confirm the claim state was edited', async() => { @@ -56,8 +54,8 @@ describe('Claim edit basic data path', () => { await page.clearTextarea(selectors.claimBasicData.observation); await page.write(selectors.claimBasicData.observation, 'Observation one'); await page.waitToClick(selectors.claimBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(message.type).toBe('success'); }); }); diff --git a/e2e/paths/06-claim/02_development.spec.js b/e2e/paths/06-claim/02_development.spec.js index 346f88581..8efae48d4 100644 --- a/e2e/paths/06-claim/02_development.spec.js +++ b/e2e/paths/06-claim/02_development.spec.js @@ -26,15 +26,13 @@ describe('Claim development', () => { await page.autocompleteSearch(selectors.claimDevelopment.secondClaimWorker, 'deliveryNick'); await page.autocompleteSearch(selectors.claimDevelopment.secondClaimRedelivery, 'Reparto'); await page.waitToClick(selectors.claimDevelopment.saveDevelopmentButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should redirect to the next section of claims as the role is salesAssistant`, async() => { - let url = await page.expectURL('/action'); - - expect(url).toBe(true); + await page.waitForState('claim.card.action'); }); it('should edit a development', async() => { @@ -45,9 +43,9 @@ describe('Claim development', () => { await page.autocompleteSearch(selectors.claimDevelopment.firstClaimWorker, 'adminAssistantNick'); await page.autocompleteSearch(selectors.claimDevelopment.firstClaimRedelivery, 'Cliente'); await page.waitToClick(selectors.claimDevelopment.saveDevelopmentButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the first development is the expected one', async() => { diff --git a/e2e/paths/06-claim/03_detail.spec.js b/e2e/paths/06-claim/03_detail.spec.js index cf758919e..9d1f6eee1 100644 --- a/e2e/paths/06-claim/03_detail.spec.js +++ b/e2e/paths/06-claim/03_detail.spec.js @@ -21,9 +21,9 @@ xdescribe('Claim detail', () => { it('should add the first claimable item from ticket to the claim', async() => { await page.waitToClick(selectors.claimDetail.addItemButton); await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the claim contains now two items', async() => { @@ -36,9 +36,9 @@ xdescribe('Claim detail', () => { await page.clearInput(selectors.claimDetail.firstItemQuantityInput); // selector deleted, find new upon fixes await page.write(selectors.claimDetail.firstItemQuantityInput, '4'); // selector deleted, find new upon fixes await page.keyboard.press('Enter'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the first item quantity, and the claimed total were correctly edited', async() => { @@ -56,7 +56,7 @@ xdescribe('Claim detail', () => { await page.loginAndModule('salesAssistant', 'claim'); await page.accessToSearchResult('1'); await page.accessToSection('claim.card.detail'); - let url = await page.expectURL('/detail'); + let url = await page.expectURL('/detail'); // replace with waitForState expect(url).toBe(true); }); @@ -65,9 +65,9 @@ xdescribe('Claim detail', () => { await page.waitToClick(selectors.claimDetail.secondItemDiscount); await page.write(selectors.claimDetail.discount, '100'); await page.keyboard.press('Enter'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should check the mana is the expected one', async() => { @@ -79,9 +79,9 @@ xdescribe('Claim detail', () => { it('should delete the second item from the claim', async() => { await page.waitToClick(selectors.claimDetail.secondItemDeleteButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the claim contains now one item', async() => { @@ -93,13 +93,13 @@ xdescribe('Claim detail', () => { it('should add the deleted ticket from to the claim', async() => { await page.waitToClick(selectors.claimDetail.addItemButton); await page.waitToClick(selectors.claimDetail.firstClaimableSaleFromTicket); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should have been redirected to the next section in claims`, async() => { - let url = await page.expectURL('development'); + let url = await page.expectURL('development'); // replace with waitForState expect(url).toBe(true); }); diff --git a/e2e/paths/06-claim/04_claim_action.spec.js b/e2e/paths/06-claim/04_claim_action.spec.js index 1db3938d5..9897a3ef3 100644 --- a/e2e/paths/06-claim/04_claim_action.spec.js +++ b/e2e/paths/06-claim/04_claim_action.spec.js @@ -19,33 +19,36 @@ describe('Claim action path', () => { it('should import the claim', async() => { await page.waitToClick(selectors.claimAction.importClaimButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should import the second importable ticket', async() => { - await page.waitFor(3000); // the animation adding the header element for the claimed total obscures somehow other elements for about 2 seconds + // the animation adding the header element for the claimed total + // obscures somehow other elements for about 2 seconds + await page.waitFor(3000); + await page.waitToClick(selectors.claimAction.importTicketButton); await page.waitToClick(selectors.claimAction.secondImportableTicket); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should edit the second line destination field', async() => { await page.waitForContentLoaded(); await page.autocompleteSearch(selectors.claimAction.secondLineDestination, 'Bueno'); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should delete the first line', async() => { await page.waitToClick(selectors.claimAction.firstDeleteLine); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toContain('Data saved!'); + expect(message.type).toBe('success'); }); it('should refresh the view to check the remaining line is the expected one', async() => { @@ -57,17 +60,17 @@ describe('Claim action path', () => { it('should delete the current first line', async() => { await page.waitToClick(selectors.claimAction.firstDeleteLine); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should check the "is paid with mana" checkbox', async() => { page.waitFor(3000); // can't use waitForNavigation here and needs more time than a single second to get the section ready... await page.waitToClick(selectors.claimAction.isPaidWithManaCheckbox); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(message.type).toBe('success'); }); it('should confirm the "is paid with mana" checkbox is checked', async() => { diff --git a/e2e/paths/06-claim/05_summary.spec.js b/e2e/paths/06-claim/05_summary.spec.js index 9dab65954..c63e686cb 100644 --- a/e2e/paths/06-claim/05_summary.spec.js +++ b/e2e/paths/06-claim/05_summary.spec.js @@ -18,9 +18,7 @@ describe('claim Summary path', () => { it('should navigate to the target claim summary section', async() => { await page.loginAndModule('employee', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should display details from the claim and it's client on the top of the header`, async() => { diff --git a/e2e/paths/06-claim/06_descriptor.spec.js b/e2e/paths/06-claim/06_descriptor.spec.js index 104f63945..43d046d62 100644 --- a/e2e/paths/06-claim/06_descriptor.spec.js +++ b/e2e/paths/06-claim/06_descriptor.spec.js @@ -18,9 +18,7 @@ describe('claim Descriptor path', () => { it('should now navigate to the target claim summary section', async() => { await page.loginAndModule('employee', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should not be able to see the delete claim button of the descriptor more menu`, async() => { @@ -31,9 +29,7 @@ describe('claim Descriptor path', () => { it(`should log in as salesAssistant and navigate to the target claim`, async() => { await page.loginAndModule('salesAssistant', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should be able to see the delete claim button of the descriptor more menu`, async() => { @@ -44,23 +40,19 @@ describe('claim Descriptor path', () => { it(`should delete the claim`, async() => { await page.waitToClick(selectors.claimDescriptor.moreMenuDeleteClaim); await page.waitToClick(selectors.claimDescriptor.acceptDeleteClaim); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Claim deleted!'); + expect(message.text).toBe('Claim deleted!'); }); it(`should have been relocated to the claim index`, async() => { - let url = await page.expectURL('/claim/index'); - - expect(url).toBe(true); + await page.waitForState('claim.index'); }); it(`should search for the deleted claim to find no results`, async() => { - await page.write(selectors.claimsIndex.searchClaimInput, claimId); - await page.waitToClick(selectors.claimsIndex.searchButton); - await page.waitForNumberOfElements(selectors.claimsIndex.searchResult, 0); - const result = await page.countElement(selectors.claimsIndex.searchResult); + await page.doSearch(claimId); + const nResults = await page.countElement(selectors.claimsIndex.searchResult); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); }); diff --git a/e2e/paths/07-order/01_summary.spec.js b/e2e/paths/07-order/01_summary.spec.js index cba56bf70..f4bc44827 100644 --- a/e2e/paths/07-order/01_summary.spec.js +++ b/e2e/paths/07-order/01_summary.spec.js @@ -16,9 +16,7 @@ describe('Order summary path', () => { }); it('should reach the order summary section', async() => { - const url = await page.expectURL('#!/order/16/summary'); - - expect(url).toBe(true); + await page.waitForState('order.card.summary'); }); it('should check the summary contains the order id', async() => { diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index 768985628..38d6619e0 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -4,7 +4,6 @@ import getBrowser from '../../helpers/puppeteer'; describe('Order edit basic data path', () => { let browser; let page; - const today = new Date().getDate(); beforeAll(async() => { browser = await getBrowser(); @@ -24,9 +23,9 @@ describe('Order edit basic data path', () => { await page.autocompleteSearch(selectors.orderBasicData.client, 'Tony Stark'); await page.autocompleteSearch(selectors.orderBasicData.address, 'Tony Stark'); await page.waitToClick(selectors.orderBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`You can't make changes on the basic data of an confirmed order or with rows`); + expect(message.text).toBe(`You can't make changes on the basic data of an confirmed order or with rows`); }); }); @@ -40,17 +39,15 @@ describe('Order edit basic data path', () => { await page.accessToSearchResult(orderId); await page.accessToSection('order.card.basicData'); await page.waitForSelector(selectors.orderBasicData.observation, {visible: true}); - let url = await page.expectURL(`#!/order/${orderId}/basic-data`); - - expect(url).toBe(true); + await page.waitForState('order.card.basicData'); }); it('should not be able to change anything', async() => { await page.write(selectors.orderBasicData.observation, 'observation'); await page.waitToClick(selectors.orderBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual(`You can't make changes on the basic data of an confirmed order or with rows`); + expect(message.text).toBe(`You can't make changes on the basic data of an confirmed order or with rows`); }); }); @@ -60,26 +57,20 @@ describe('Order edit basic data path', () => { await page.waitToClick(selectors.orderBasicData.acceptButton); await page.waitForContentLoaded(); await page.waitToClick(selectors.ordersIndex.createOrderButton); - let url = await page.expectURL('#!/order/create'); - - expect(url).toBe(true); + await page.waitForState('order.create'); }); it('should now create a new one', async() => { await page.autocompleteSearch(selectors.createOrderView.client, 'Jessica Jones'); - await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); + await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); - let url = await page.expectURL('/catalog'); - - expect(url).toBe(true); + await page.waitForState('order.card.catalog'); }); it('should navigate to the basic data section of the new order', async() => { await page.accessToSection('order.card.basicData'); - let url = await page.expectURL('/basic-data'); - - expect(url).toBe(true); + await page.waitForState('order.card.basicData'); }); it('should be able to modify all the properties', async() => { @@ -88,9 +79,9 @@ describe('Order edit basic data path', () => { await page.autocompleteSearch(selectors.orderBasicData.agency, 'Silla247'); await page.write(selectors.orderBasicData.observation, 'my observation'); await page.waitToClick(selectors.orderBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should now confirm the client have been edited', async() => { diff --git a/e2e/paths/07-order/03_lines.spec.js b/e2e/paths/07-order/03_lines.spec.js index 21fceac44..6f87b45f0 100644 --- a/e2e/paths/07-order/03_lines.spec.js +++ b/e2e/paths/07-order/03_lines.spec.js @@ -26,9 +26,9 @@ describe('Order lines', () => { it('should delete the first line in the order', async() => { await page.waitToClick(selectors.orderLine.firstLineDeleteButton); await page.waitToClick(selectors.orderLine.confirmButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the order subtotal has changed', async() => { @@ -41,10 +41,7 @@ describe('Order lines', () => { it('should confirm the whole order and redirect to ticket index filtered by clientFk', async() => { await page.waitToClick(selectors.orderLine.confirmOrder); - let hashPartOne = await page.expectURL('ticket/index'); - let hashPartTwo = await page.expectURL('clientFk'); - - expect(hashPartOne).toBe(true); - expect(hashPartTwo).toBe(true); + await page.expectURL('ticket/index'); + await page.expectURL('clientFk'); }); }); diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index ca6489779..34fdbbec0 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -17,21 +17,15 @@ describe('Order catalog', () => { it('should open the create new order form', async() => { await page.waitToClick(selectors.ordersIndex.createOrderButton); - let url = await page.expectURL('order/create'); - - expect(url).toBe(true); + await page.waitForState('order.create'); }); it('should create a new order', async() => { - let today = new Date().getDate(); - await page.autocompleteSearch(selectors.createOrderView.client, 'Tony Stark'); - await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); + await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); - let url = await page.expectURL('/catalog'); - - expect(url).toBe(true); + await page.waitForState('order.card.catalog'); }); it('should add the realm and type filters and obtain results', async() => { @@ -75,8 +69,7 @@ describe('Order catalog', () => { }); it('should search for an item by id', async() => { - await page.write(selectors.orderCatalog.itemId, '2'); - await page.keyboard.press('Enter'); + await page.accessToSearchResult('2'); await page.waitForNumberOfElements('section.product', 1); const result = await page.countElement('section.product'); diff --git a/e2e/paths/08-route/01_summary.spec.js b/e2e/paths/08-route/01_summary.spec.js index c062b9b08..02cc71f2f 100644 --- a/e2e/paths/08-route/01_summary.spec.js +++ b/e2e/paths/08-route/01_summary.spec.js @@ -17,9 +17,7 @@ describe('Route summary path', () => { }); it('should reach the first route summary section', async() => { - let url = await page.expectURL('#!/route/1/summary'); - - expect(url).toBe(true); + await page.waitForState('route.card.summary'); }); it(`should display details from the route on the header`, async() => { diff --git a/e2e/paths/08-route/02_basic_data.spec.js b/e2e/paths/08-route/02_basic_data.spec.js index 91688b3ff..10edbcd8a 100644 --- a/e2e/paths/08-route/02_basic_data.spec.js +++ b/e2e/paths/08-route/02_basic_data.spec.js @@ -18,9 +18,12 @@ describe('Route basic Data path', () => { }); it('should edit the route basic data', async() => { + const nextMonth = new Date(); + nextMonth.setMonth(nextMonth.getMonth() + 1); + await page.autocompleteSearch(selectors.routeBasicData.worker, 'adminBossNick'); await page.autocompleteSearch(selectors.routeBasicData.vehicle, '1111-IMK'); - await page.datePicker(selectors.routeBasicData.createdDate, 1, null); + await page.pickDate(selectors.routeBasicData.createdDate, nextMonth); await page.clearInput(selectors.routeBasicData.kmStart); await page.write(selectors.routeBasicData.kmStart, '1'); await page.clearInput(selectors.routeBasicData.kmEnd); @@ -28,16 +31,15 @@ describe('Route basic Data path', () => { await page.type(`${selectors.routeBasicData.startedHour} input`, '0800'); await page.type(`${selectors.routeBasicData.finishedHour} input`, '1230'); await page.waitToClick(selectors.routeBasicData.saveButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the worker was edited', async() => { await page.reloadSection('route.card.basicData'); const worker = await page.waitToGetProperty(selectors.routeBasicData.worker, 'value'); - expect(worker).toEqual('adminBoss - adminBossNick'); }); diff --git a/e2e/paths/08-route/03_create.spec.js b/e2e/paths/08-route/03_create.spec.js index 11ffd500b..80c0071b6 100644 --- a/e2e/paths/08-route/03_create.spec.js +++ b/e2e/paths/08-route/03_create.spec.js @@ -17,19 +17,16 @@ describe('Route create path', () => { describe('as employee', () => { it('should click on the add new route button and open the creation form', async() => { - await page.waitForContentLoaded(); await page.waitToClick(selectors.routeIndex.addNewRouteButton); - let url = await page.expectURL('#!/route/create'); - - expect(url).toBe(true); + await page.waitForState('route.create'); }); it(`should attempt to create a new route but fail since employee has no access rights`, async() => { await page.write(selectors.createRouteView.description, 'faster faster!!'); await page.waitToClick(selectors.createRouteView.submitButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Access denied'); + expect(message.text).toBe('Access denied'); }); }); @@ -41,27 +38,23 @@ describe('Route create path', () => { it('should again click on the add new route button and open the creation form', async() => { await page.waitToClick(selectors.routeIndex.addNewRouteButton); - let url = await page.expectURL('#!/route/create'); - - expect(url).toBe(true); + await page.waitForState('route.create'); }); it(`should create a new route`, async() => { await page.autocompleteSearch(selectors.createRouteView.worker, 'teamManagerNick'); - await page.datePicker(selectors.createRouteView.createdDatePicker, 0, null); + await page.pickDate(selectors.createRouteView.createdDatePicker); await page.autocompleteSearch(selectors.createRouteView.vehicleAuto, '4444-IMK'); await page.autocompleteSearch(selectors.createRouteView.agency, 'Teleportation device'); await page.write(selectors.createRouteView.description, 'faster faster!!'); await page.waitToClick(selectors.createRouteView.submitButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it(`should confirm the redirection to the created route summary`, async() => { - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('route.card.summary'); }); }); }); diff --git a/e2e/paths/08-route/04_tickets.spec.js b/e2e/paths/08-route/04_tickets.spec.js index 53b8f56c8..938c98574 100644 --- a/e2e/paths/08-route/04_tickets.spec.js +++ b/e2e/paths/08-route/04_tickets.spec.js @@ -19,17 +19,15 @@ xdescribe('Route basic Data path', () => { }); it('should modify the first ticket priority', async() => { - const result = await nightmare; await page.write(selectors.routeTickets.firstTicketPriority, '2'); await page.keyboard.press('Enter'); - await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should confirm the buscamanButton is disabled', async() => { - const result = await nightmare; - await page.evaluate(selector => { + const result = await page.evaluate(selector => { return document.querySelector(selector); }, `${selectors.routeTickets.buscamanButton} :disabled`); @@ -37,9 +35,8 @@ xdescribe('Route basic Data path', () => { }); it('should check the first ticket checkbox and confirm the buscamanButton button is no longer disabled', async() => { - const result = await nightmare; await page.waitToClick(selectors.routeTickets.firstTicketCheckbox); - await page.evaluate(selector => { + const result = await page.evaluate(selector => { return document.querySelector(selector); }, `${selectors.routeTickets.buscamanButton} :disabled`); @@ -47,47 +44,41 @@ xdescribe('Route basic Data path', () => { }); it('should check the route volume on the descriptor', async() => { - const result = await nightmare; - await page.waitToGetProperty(selectors.routeDescriptor.volume, 'innerText'); + const result = await page.waitToGetProperty(selectors.routeDescriptor.volume, 'innerText'); expect(result).toEqual('1.1 / 18 m³'); }); it('should count how many tickets are in route', async() => { - const result = await nightmare; - await page.countElement('vn-route-tickets vn-textfield[ng-model="ticket.priority"]'); + const result = await page.countElement('vn-route-tickets vn-textfield[ng-model="ticket.priority"]'); expect(result).toEqual(11); }); it('should delete the first ticket in route', async() => { - const result = await nightmare; await page.waitToClick(selectors.routeTickets.firstTicketDeleteButton); await page.waitToClick(selectors.routeTickets.confirmButton); - await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Ticket removed from route'); + expect(message.text).toBe('Ticket removed from route'); }); it('should again delete the first ticket in route', async() => { - const result = await nightmare; await page.waitToClick(selectors.routeTickets.firstTicketDeleteButton); await page.waitToClick(selectors.routeTickets.confirmButton); - await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Ticket removed from route'); + expect(message.text).toBe('Ticket removed from route'); }); it('should now count how many tickets are in route to find one less', async() => { - const result = await nightmare; - await page.countElement('vn-route-tickets vn-textfield[ng-model="ticket.priority"]'); + const result = await page.countElement('vn-route-tickets vn-textfield[ng-model="ticket.priority"]'); expect(result).toEqual(9); }); it('should confirm the route volume on the descriptor has been updated by the changes made', async() => { - const result = await nightmare; - await page.waitToGetProperty(selectors.routeDescriptor.volume, 'innerText'); + const result = await page.waitToGetProperty(selectors.routeDescriptor.volume, 'innerText'); expect(result).toEqual('0.9 / 18 m³'); }); diff --git a/e2e/paths/09-invoice-out/01_summary.spec.js b/e2e/paths/09-invoice-out/01_summary.spec.js index 126c745d3..728f0130a 100644 --- a/e2e/paths/09-invoice-out/01_summary.spec.js +++ b/e2e/paths/09-invoice-out/01_summary.spec.js @@ -17,9 +17,7 @@ describe('InvoiceOut summary path', () => { }); it('should reach the summary section', async() => { - const result = await page.expectURL('/summary'); - - expect(result).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it('should contain the company from which the invoice is emited', async() => { diff --git a/e2e/paths/09-invoice-out/02_descriptor.spec.js b/e2e/paths/09-invoice-out/02_descriptor.spec.js index e70c39ded..ade121a8b 100644 --- a/e2e/paths/09-invoice-out/02_descriptor.spec.js +++ b/e2e/paths/09-invoice-out/02_descriptor.spec.js @@ -20,10 +20,7 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.ticketsIndex.openAdvancedSearchButton); await page.write(selectors.ticketsIndex.advancedSearchInvoiceOut, 'T2222222'); await page.waitToClick(selectors.ticketsIndex.advancedSearchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); + await page.waitForState('ticket.card.summary'); }); it('should navigate to the invoiceOut index', async() => { @@ -31,86 +28,58 @@ describe('InvoiceOut descriptor path', () => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.invoiceOutButton); await page.wait(selectors.invoiceOutIndex.topbarSearch); - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); - }); - - it('should search for the target invoiceOut', async() => { - await page.write(selectors.invoiceOutIndex.topbarSearch, 'T2222222'); - await page.waitToClick(selectors.invoiceOutIndex.searchButton); - await page.waitForNumberOfElements(selectors.invoiceOutIndex.searchResult, 1); - const result = await page.countElement(selectors.invoiceOutIndex.searchResult); - - expect(result).toEqual(1); + await page.waitForState('invoiceOut.index'); }); it(`should click on the search result to access to the invoiceOut summary`, async() => { await page.accessToSearchResult('T2222222'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it('should delete the invoiceOut using the descriptor more menu', async() => { await page.waitToClick(selectors.invoiceOutDescriptor.moreMenu); await page.waitToClick(selectors.invoiceOutDescriptor.moreMenuDeleteInvoiceOut); await page.waitToClick(selectors.invoiceOutDescriptor.acceptDeleteButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('InvoiceOut deleted'); + expect(message.text).toBe('InvoiceOut deleted'); }); it('should have been relocated to the invoiceOut index', async() => { - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.index'); }); it(`should search for the deleted invouceOut to find no results`, async() => { - await page.write(selectors.invoiceOutIndex.topbarSearch, 'T2222222'); - await page.waitToClick(selectors.invoiceOutIndex.searchButton); - await page.waitForNumberOfElements(selectors.invoiceOutIndex.searchResult, 0); - const result = await page.countElement(selectors.invoiceOutIndex.searchResult); + await page.doSearch('T2222222'); + const nResults = await page.countElement(selectors.invoiceOutIndex.searchResult); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); it('should navigate to the ticket index', async() => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should search for tickets with an specific invoiceOut to find no results', async() => { - await page.waitFor(2000); - await page.waitToClick(selectors.ticketsIndex.openAdvancedSearchButton); - await page.write(selectors.ticketsIndex.advancedSearchInvoiceOut, 'T2222222'); - await page.waitToClick(selectors.ticketsIndex.advancedSearchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 0); - const result = await page.countElement(selectors.ticketsIndex.searchResult); + await page.doSearch('T2222222'); + const nResults = await page.countElement(selectors.ticketsIndex.searchResult); - expect(result).toEqual(0); + expect(nResults).toEqual(0); }); it('should now navigate to the invoiceOut index', async() => { - await page.waitForContentLoaded(); await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.invoiceOutButton); - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.index'); }); it(`should search and access to the invoiceOut summary`, async() => { await page.accessToSearchResult('T1111111'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it(`should check the invoiceOut is booked in the summary data`, async() => { @@ -124,9 +93,9 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.invoiceOutDescriptor.moreMenu); await page.waitToClick(selectors.invoiceOutDescriptor.moreMenuBookInvoiceOut); await page.waitToClick(selectors.invoiceOutDescriptor.acceptBookingButton); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('InvoiceOut booked'); + expect(message.text).toBe('InvoiceOut booked'); }); it(`should check the invoiceOut booked in the summary data`, async() => { diff --git a/e2e/paths/10-travel/01_thermograph.spec.js b/e2e/paths/10-travel/01_thermograph.spec.js index efa2295a6..67a62381a 100644 --- a/e2e/paths/10-travel/01_thermograph.spec.js +++ b/e2e/paths/10-travel/01_thermograph.spec.js @@ -18,16 +18,12 @@ describe('Travel thermograph path', () => { }); it('should reach the thermograph section', async() => { - const result = await page.expectURL('/thermograph/index'); - - expect(result).toBe(true); + await page.waitForState('travel.card.thermograph.index'); }); it('should click the add thermograph floating button', async() => { await page.waitToClick(selectors.travelThermograph.add); - const result = await page.expectURL('/thermograph/create'); - - expect(result).toBe(true); + await page.waitForState('travel.card.thermograph.create'); }); it('should select the thermograph and then the file to upload', async() => { diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index a835df2a2..c631e7131 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -18,25 +18,26 @@ describe('Travel basic data path', () => { }); it('should reach the thermograph section', async() => { - const result = await page.expectURL('/basic-data'); - - expect(result).toBe(true); + await page.waitForState('travel.card.basicData'); }); it('should set a wrong delivery date then receive an error on submit', async() => { - await page.datePicker(selectors.travelBasicDada.deliveryDate, -1, null); - await page.waitToClick(selectors.travelBasicDada.save); - const result = await page.waitForLastSnackbar(); + const lastMonth = new Date(); + lastMonth.setMonth(lastMonth.getMonth() - 1); - expect(result).toEqual('Landing cannot be lesser than shipment'); + await page.pickDate(selectors.travelBasicDada.deliveryDate, lastMonth); + await page.waitToClick(selectors.travelBasicDada.save); + const message = await page.waitForSnackbar(); + + expect(message.text).toBe('Landing cannot be lesser than shipment'); }); it('should undo the changes', async() => { await page.waitToClick(selectors.travelBasicDada.undoChanges); await page.waitToClick(selectors.travelBasicDada.save); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('No changes to save'); + expect(message.text).toBe('No changes to save'); }); it('should now edit the whole form then save', async() => { @@ -49,9 +50,9 @@ describe('Travel basic data path', () => { await page.waitToClick(selectors.travelBasicDada.delivered); await page.waitToClick(selectors.travelBasicDada.received); await page.waitToClick(selectors.travelBasicDada.save); - const result = await page.waitForLastSnackbar(); + const message = await page.waitForSnackbar(); - expect(result).toEqual('Data saved!'); + expect(message.type).toBe('success'); }); it('should reload the section and check the reference was saved', async() => { @@ -89,9 +90,7 @@ describe('Travel basic data path', () => { it('should navigate to the travel logs', async() => { await page.accessToSection('travel.card.log'); - const result = await page.expectURL('/log'); - - expect(result).toBe(true); + await page.waitForState('travel.card.log'); }); it('should check the 1st log contains details from the changes made', async() => { diff --git a/e2e/paths/11-zone/01_basic-data.spec.js b/e2e/paths/11-zone/01_basic-data.spec.js index c63bb8321..f28be5194 100644 --- a/e2e/paths/11-zone/01_basic-data.spec.js +++ b/e2e/paths/11-zone/01_basic-data.spec.js @@ -18,9 +18,7 @@ describe('Zone basic data path', () => { }); it('should reach the basic data section', async() => { - let url = await page.expectURL('#!/zone/10/basic-data'); - - expect(url).toBe(true); + await page.waitForState('zone.card.basicData'); }); it('should edit de form and then save', async() => { @@ -31,7 +29,7 @@ describe('Zone basic data path', () => { await page.clearInput(selectors.zoneBasicData.travelingDays); await page.write(selectors.zoneBasicData.travelingDays, '1'); await page.clearInput(selectors.zoneBasicData.closing); - await page.type(selectors.zoneBasicData.closing, '2100'); + await page.pickTime(selectors.zoneBasicData.closing, '21:00'); await page.clearInput(selectors.zoneBasicData.price); await page.write(selectors.zoneBasicData.price, '999'); await page.clearInput(selectors.zoneBasicData.bonus); @@ -40,14 +38,13 @@ describe('Zone basic data path', () => { await page.write(selectors.zoneBasicData.inflation, '200'); await page.waitToClick(selectors.zoneBasicData.volumetric); await page.waitToClick(selectors.zoneBasicData.saveButton); - await page.waitForContentLoaded(); + const message = await page.waitForSnackbar(); + + expect(message.type).toBe('success'); }); it('should now reload the section', async() => { await page.reloadSection('zone.card.basicData'); - let url = await page.expectURL('#!/zone/10/basic-data'); - - expect(url).toBe(true); }); it('should confirm the name was updated', async() => { diff --git a/e2e/paths/12-entry/01_summary.spec.js b/e2e/paths/12-entry/01_summary.spec.js index 39b12b840..e57654f94 100644 --- a/e2e/paths/12-entry/01_summary.spec.js +++ b/e2e/paths/12-entry/01_summary.spec.js @@ -17,9 +17,7 @@ describe('Entry summary path', () => { }); it('should reach the second entry summary section', async() => { - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it(`should display details from the entry on the header`, async() => { diff --git a/e2e/paths/12-entry/02_descriptor.spec.js b/e2e/paths/12-entry/02_descriptor.spec.js index 8fa0d2a4f..699d00517 100644 --- a/e2e/paths/12-entry/02_descriptor.spec.js +++ b/e2e/paths/12-entry/02_descriptor.spec.js @@ -17,9 +17,7 @@ describe('Entry descriptor path', () => { }); it('should reach the second entry summary section', async() => { - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it('should show some entry information', async() => { @@ -30,32 +28,22 @@ describe('Entry descriptor path', () => { it('should click the travels button to be redirected to the travels index filtered by the current agency', async() => { await page.waitToClick(selectors.entryDescriptor.travelsQuicklink); - const url = await page.expectURL('/travel/index'); - const filter = await page.expectURL('agencyFk'); - - expect(url).toBe(true); - expect(filter).toBe(true); + await page.expectURL('/travel/index'); + await page.expectURL('agencyFk'); }); it('should go back to the entry summary', async() => { await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('entry'); await page.accessToSearchResult('2'); - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it('should click the entries button to be redirected to the entries index filtered by the current supplier', async() => { await page.waitToClick(selectors.entryDescriptor.entriesQuicklink); - const url = await page.expectURL('/entry/index'); - const supplierFilter = await page.expectURL('supplierFk'); - const toFilter = await page.expectURL('to'); - const fromFilter = await page.expectURL('from'); - - expect(url).toBe(true); - expect(supplierFilter).toBe(true); - expect(toFilter).toBe(true); - expect(fromFilter).toBe(true); + await page.expectURL('/entry/index'); + await page.expectURL('supplierFk'); + await page.expectURL('to'); + await page.expectURL('from'); }); }); diff --git a/front/core/components/autocomplete/index.html b/front/core/components/autocomplete/index.html index 725d38977..feaa47bdb 100755 --- a/front/core/components/autocomplete/index.html +++ b/front/core/components/autocomplete/index.html @@ -1,5 +1,6 @@
vn-icon { vertical-align: middle; color: inherit; - font-size: 1.7em; } } &.colored { color: white; background-color: $color-button; - box-shadow: 0 .15em .15em 0 rgba(0, 0, 0, .3); + box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .3); transition: background 200ms ease-in-out; &:not(.disabled) { @@ -80,27 +79,27 @@ } &.round { border-radius: 50%; - height: 3.8em; - width: 3.8em; + height: 54px; + width: 54px; & > button > span { display: none; } &.xs { - font-size: 0.5em; + font-size: .5rem; } &.sm { - font-size: 0.7em; + font-size: .7rem; } &.md { - font-size: 0.9em; + font-size: .875rem; } &.lg { - font-size: 1.2em; + font-size: 1.2rem; } } &.disabled { diff --git a/front/core/components/calendar/style.scss b/front/core/components/calendar/style.scss index 8492d09f1..28c87793b 100644 --- a/front/core/components/calendar/style.scss +++ b/front/core/components/calendar/style.scss @@ -6,14 +6,14 @@ & > div { & > .header { display: flex; - margin-bottom: 0.5em; + margin-bottom: 8px; align-items: center; - height: 2.4em; + height: 38px; & > .title { flex: 1; text-align: center; - padding: 0.2em 0; + padding: 3px 0; } & > .vn-button { color: inherit; @@ -22,10 +22,10 @@ & > .weekdays { display: flex; color: $color-font-secondary; - margin-bottom: 0.5em; - padding: 0.5em 0; + margin-bottom: 8px; + padding: 8px 0; font-weight: bold; - font-size: 0.8em; + font-size: .8rem; text-align: center; & > section { @@ -62,9 +62,9 @@ justify-content: center; align-items: center; border-radius: 50%; - font-size: 14px; - width: 2.2em; - height: 2.2em; + font-size: .9rem; + width: 30px; + height: 30px; cursor: pointer; outline: 0; transition: background-color 300ms ease-in-out; diff --git a/front/core/components/chip/style.scss b/front/core/components/chip/style.scss index 974a55a82..34ee947ba 100644 --- a/front/core/components/chip/style.scss +++ b/front/core/components/chip/style.scss @@ -1,23 +1,23 @@ @import "variables"; vn-chip { - border-radius: 1em; + border-radius: 16px; background-color: $color-bg; color: $color-font; font-size: .9rem; - margin: .25em; + margin: 4px; display: inline-flex; align-items: center; - height: 2em; + height: 28px; max-width: 100%; box-sizing: border-box; &.small { - height: 1.5em; + height: 24px; & > div { - padding: 0.6em; - font-size: 0.8rem; + padding: 9px; + font-size: .8rem; } } @@ -46,22 +46,22 @@ vn-chip { display: flex; align-items: center; height: 100%; - padding: 0 .7em; + padding: 0 11px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; & > vn-avatar { - margin-left: -0.7em; - margin-right: .3em; + margin-left: -11px; + margin-right: 6px; vertical-align: middle; - height: 2em; - width: 2em; + height: 28px; + width: 28px; } } & > vn-icon { - margin-right: .12em; - margin-left: -.12em; + margin-right: 2px; + margin-left: -2px; vertical-align: middle; opacity: .6; cursor: pointer; @@ -76,6 +76,6 @@ vn-chip { vn-avatar { display: inline-block; - min-width: 2em; + min-width: 28px; border-radius: 50%; } \ No newline at end of file diff --git a/front/core/components/confirm/confirm.js b/front/core/components/confirm/confirm.js index f187a3cb4..c0a1cc0c5 100644 --- a/front/core/components/confirm/confirm.js +++ b/front/core/components/confirm/confirm.js @@ -6,10 +6,7 @@ import './style.scss'; export default class Confirm extends Dialog { constructor($element, $, $transclude) { super($element, $, $transclude); - - let $template = angular.element(template); - this.fillSlot('body', $template.find('tpl-body')); - this.fillSlot('buttons', $template.find('tpl-buttons')); + this.fillSlots(template); } } diff --git a/front/core/components/confirm/style.scss b/front/core/components/confirm/style.scss index d3cea6cb1..154e3b478 100644 --- a/front/core/components/confirm/style.scss +++ b/front/core/components/confirm/style.scss @@ -1,3 +1,3 @@ .vn-confirm .window { - max-width: 30em + max-width: 480px } \ No newline at end of file diff --git a/front/core/components/data-viewer/style.scss b/front/core/components/data-viewer/style.scss index d0b3c727d..bb2cc2a83 100644 --- a/front/core/components/data-viewer/style.scss +++ b/front/core/components/data-viewer/style.scss @@ -6,9 +6,9 @@ vn-data-viewer { & > .empty-rows { display: block; text-align: center; - padding: 1.5em; + padding: 24px; box-sizing: border-box; color: $color-font-secondary; - font-size: 1.4em; + font-size: 1.375rem; } } \ No newline at end of file diff --git a/front/core/components/debug-info/style.scss b/front/core/components/debug-info/style.scss index 95c024a6d..b6171d4da 100644 --- a/front/core/components/debug-info/style.scss +++ b/front/core/components/debug-info/style.scss @@ -2,10 +2,10 @@ vn-debug-info { position: fixed; - bottom: 1em; - left: 1em; - padding: 1em; - min-width: 8em; + bottom: 16px; + left: 16px; + padding: 16px; + min-width: 128px; background-color: #3f51b5; color: $color-font-dark; border-radius: 4px; @@ -19,7 +19,7 @@ vn-debug-info { & > h6 { font-weight: normal; color: rgba(255, 255, 255, .5); - font-size: 1em; + font-size: 1rem; } ul { list-style-type: none; @@ -27,11 +27,11 @@ vn-debug-info { margin: 0; & > li { - margin-top: .2em; - font-size: .95em; + margin-top: 3px; + font-size: .94rem; & > span { - padding: .05em .2em; + padding: 1px 3px; border-radius: 4px; transition: background-color 200ms ease-in-out; diff --git a/front/core/components/dialog/index.js b/front/core/components/dialog/index.js index 7a7cb5f9f..dfc1e5d3a 100644 --- a/front/core/components/dialog/index.js +++ b/front/core/components/dialog/index.js @@ -21,6 +21,17 @@ export default class Dialog extends Popup { this.fillDefaultSlot(template); } + /** + * Fills the dialog slots, it is intended to be used by child classes. + * + * @param {String} template The HTML template string + */ + fillSlots(template) { + let $template = angular.element(template); + this.fillSlot('body', $template.find('tpl-body')); + this.fillSlot('buttons', $template.find('tpl-buttons')); + } + /** * Shows the dialog and optionally registers a handler for the response. * @@ -68,7 +79,17 @@ export default class Dialog extends Popup { respond(response) { if (!this.shown) return this.$q.resolve(); + return this.responseHandler(response); + } + /** + * The default response handler, it can be overriden by child classes to + * add custom logic. + * + * @param {String} response The response code + * @return {Boolean} The response handler return + */ + responseHandler(response) { let handlerArgs = { $response: response, $data: this.data diff --git a/front/core/components/dialog/style.scss b/front/core/components/dialog/style.scss index 2f3d9a028..e4884c362 100644 --- a/front/core/components/dialog/style.scss +++ b/front/core/components/dialog/style.scss @@ -8,11 +8,11 @@ text-transform: uppercase; background-color: transparent; border: none; - border-radius: .1em; + border-radius: 1px; position: absolute; top: 0; right: 0; - padding: .3em; + padding: 4px; color: #666; } & > form { @@ -20,11 +20,11 @@ & > .body > tpl-body { display: block; - min-width: 16em; + min-width: 256px; } & > .buttons > tpl-buttons { display: block; - margin-top: 1.5em; + margin-top: 24px; text-align: right; button, @@ -35,12 +35,12 @@ text-transform: uppercase; background-color: transparent; border: none; - border-radius: .1em; + border-radius: 1px; color: $color-button; font-family: vn-font-bold; - padding: .7em; - margin: -0.7em; - margin-left: .7em; + padding: 11px; + margin: -11px; + margin-left: 11px; } } } diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index 9f2dfe424..ed7de7179 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -29,13 +29,16 @@ export default class DropDown extends Popover { } set search(value) { - let oldValue = this._search; + function nullify(value) { + return value == '' || value == undefined ? null : value; + } + + let oldValue = nullify(this._search); this._search = value; if (!this.shown) return; - value = value == '' || value == null ? null : value; - oldValue = oldValue == '' || oldValue == null ? null : oldValue; + value = nullify(value); if (value === oldValue && this.modelData != null) return; if (value != null) @@ -45,7 +48,8 @@ export default class DropDown extends Popover { if (this.model) { this.model.clear(); - if (!this.data) { + + if (this.model instanceof CrudModel) { this.searchTimeout = this.$timeout(() => { this.refreshModel(); this.searchTimeout = null; @@ -353,6 +357,7 @@ export default class DropDown extends Popover { set model(value) { this.linkEvents({_model: value}, {dataChange: this.onDataChange}); this.onDataChange(); + this.search = this.search; } get url() { @@ -362,10 +367,9 @@ export default class DropDown extends Popover { set url(value) { this._url = value; if (value) { - this.model = new CrudModel(this.$q, this.$http); - this.model.autoLoad = false; - this.model.url = value; - this.model.$onInit(); + let model = new CrudModel(this.$q, this.$http); + model.url = value; + this.initModel(model); } } @@ -376,13 +380,18 @@ export default class DropDown extends Popover { set data(value) { this._data = value; if (value) { - this.model = new ArrayModel(this.$q, this.$filter); - this.model.autoLoad = false; - this.model.orgData = value; - this.model.$onInit(); + let model = new ArrayModel(this.$q, this.$filter); + model.orgData = value; + this.initModel(model); } } + initModel(model) { + model.autoLoad = false; + model.$onInit(); + this.model = model; + } + refreshModel() { let model = this.model; diff --git a/front/core/components/drop-down/style.scss b/front/core/components/drop-down/style.scss index fb346135f..085f94c97 100755 --- a/front/core/components/drop-down/style.scss +++ b/front/core/components/drop-down/style.scss @@ -19,13 +19,13 @@ display: none; cursor: pointer; position: absolute; - right: .5em; - top: .6em; - height: 1em; + right: 8px; + top: 9px; + height: 16px; color: #888; border-radius: 50%; background-color: rgba(255, 255, 255, .8); - font-size: 18px; + font-size: 1.125rem; &:hover { color: $color-font; @@ -36,7 +36,7 @@ } } & > .list { - max-height: 20em; + max-height: 320px; overflow: auto; ul { @@ -46,13 +46,13 @@ } li, .status { @extend %clickable; - padding: .6em; + padding: 9px; white-space: nowrap; display: flex; & > input[type=checkbox] { margin: 0; - margin-right: .6em; + margin-right: 9px; } &.active { @extend %active; diff --git a/front/core/components/field/index.html b/front/core/components/field/index.html index d614d157f..c31fe2862 100644 --- a/front/core/components/field/index.html +++ b/front/core/components/field/index.html @@ -1,4 +1,4 @@ -
+
diff --git a/front/core/components/field/index.js b/front/core/components/field/index.js index 62adf3233..81fd4cc6a 100644 --- a/front/core/components/field/index.js +++ b/front/core/components/field/index.js @@ -9,20 +9,17 @@ export default class Field extends FormInput { this.prefix = null; this.suffix = null; - this.control = this.element.querySelector('.control'); - this.element.addEventListener('click', e => this.onClick(e)); - this.container = this.element.querySelector('.container'); - this.container.addEventListener('mousedown', e => this.onMouseDown(e)); + this.container.addEventListener('focusout', () => this.onFocus(false)); + this.container.addEventListener('focusin', () => this.onFocus(true)); + + this.control = this.element.querySelector('.control'); } $onInit() { super.$onInit(); if (this.info) this.classList.add('has-icons'); - - this.input.addEventListener('focus', () => this.onFocus(true)); - this.input.addEventListener('blur', () => this.onFocus(false)); this.input.addEventListener('change', () => this.onChange()); } @@ -160,19 +157,6 @@ export default class Field extends FormInput { fix.innerText = text || ''; } - onClick() { - // if (event.defaultPrevented) return; - - if (this.input !== document.activeElement) - this.focus(); - } - - onMouseDown(event) { - if (event.target == this.input) return; - event.preventDefault(); - this.focus(); - } - onFocus(hasFocus) { this.classList.toggle('focused', hasFocus); } diff --git a/front/core/components/field/style.scss b/front/core/components/field/style.scss index f3bc0ae04..5f77e904e 100644 --- a/front/core/components/field/style.scss +++ b/front/core/components/field/style.scss @@ -9,6 +9,7 @@ display: flex; align-items: stretch; position: relative; + outline: none; & > .infix { position: relative; @@ -30,7 +31,6 @@ & > .required { display: none; - color: $color-alert } } & > .fix { @@ -135,7 +135,7 @@ align-items: center; & > vn-icon { - font-size: 24px; + font-size: 1.5rem; } } & > .prepend > prepend { @@ -197,7 +197,7 @@ } } &.standout { - border-radius: .1em; + border-radius: 1px; background-color: rgba(255, 255, 255, .1); padding: 0 12px; transition-property: background-color, color; @@ -248,7 +248,7 @@ top: 5px; color: $color-primary; padding: 0; - font-size: 12px; + font-size: .75rem; } & > .control > * { &[type=time], @@ -298,7 +298,7 @@ padding: 4px 0; height: 12px; color: rgba(0, 0, 0, .4); - font-size: 12px; + font-size: .75rem; transform: translateY(-12px); transition-property: opacity, transform, color; transition-duration: 200ms; diff --git a/front/core/components/icon-button/style.scss b/front/core/components/icon-button/style.scss index d59980a62..2b52d48bd 100644 --- a/front/core/components/icon-button/style.scss +++ b/front/core/components/icon-button/style.scss @@ -5,7 +5,7 @@ color: $color-button; & > button { - padding: .2em !important; + padding: 3px !important; } &:focus { opacity: .6; diff --git a/front/core/components/icon/style.scss b/front/core/components/icon/style.scss index 07a1584e3..86345cbf4 100644 --- a/front/core/components/icon/style.scss +++ b/front/core/components/icon/style.scss @@ -1,6 +1,6 @@ vn-icon { display: inline-block; - font-size: 18pt; + font-size: 1.7em; text-align: center; outline: 0; diff --git a/front/core/components/input-number/index.html b/front/core/components/input-number/index.html index 2c6f7d824..acce849e2 100644 --- a/front/core/components/input-number/index.html +++ b/front/core/components/input-number/index.html @@ -1,4 +1,4 @@ -
+
diff --git a/front/core/components/label-value/style.scss b/front/core/components/label-value/style.scss index e4a2cca03..10f3c016c 100644 --- a/front/core/components/label-value/style.scss +++ b/front/core/components/label-value/style.scss @@ -4,6 +4,6 @@ vn-label-value > section { & > vn-icon { vertical-align: middle; color: $color-font-secondary; - font-size: 1.2em + font-size: 1.2rem } } \ No newline at end of file diff --git a/front/core/components/list/style.scss b/front/core/components/list/style.scss index 6f12ce7c6..fdadf460b 100644 --- a/front/core/components/list/style.scss +++ b/front/core/components/list/style.scss @@ -11,7 +11,7 @@ ul.menu { @extend %clickable; display: block; color: inherit; - padding: .6em 2em; + padding: 9px 32px; } } */ @@ -76,7 +76,7 @@ vn-item, margin-right: $spacing-md; & > .vn-icon { - font-size: 1.2em; + font-size: 1.2rem; } } &[side] { @@ -86,10 +86,10 @@ vn-item, & > .vn-button { opacity: .4; - margin-left: .5em; + margin-left: 8px; transition: opacity 250ms ease-out; padding: 0; - font-size: 1.05em; + font-size: 1rem; &:hover { opacity: 1; diff --git a/front/core/components/multi-check/style.scss b/front/core/components/multi-check/style.scss index bc6a0e8c5..79c2397bc 100644 --- a/front/core/components/multi-check/style.scss +++ b/front/core/components/multi-check/style.scss @@ -1,5 +1,5 @@ vn-multi-check { .vn-check { - margin-bottom: 0.8em + margin-bottom: 12px } } \ No newline at end of file diff --git a/front/core/components/pagination/style.scss b/front/core/components/pagination/style.scss index 2610bc502..413a6fb5f 100644 --- a/front/core/components/pagination/style.scss +++ b/front/core/components/pagination/style.scss @@ -4,7 +4,7 @@ vn-pagination { text-align: center; & > div > vn-icon-button { - font-size: 2em; + font-size: 2rem; padding: 0; } } \ No newline at end of file diff --git a/front/core/components/popover/style.scss b/front/core/components/popover/style.scss index decfc4733..e27ef6012 100644 --- a/front/core/components/popover/style.scss +++ b/front/core/components/popover/style.scss @@ -10,7 +10,7 @@ color: $color-font; opacity: 0; - transform: translateY(-.6em); + transform: translateY(-9px); transition-property: opacity, transform; transition-duration: 200ms; transition-timing-function: ease-in-out; @@ -21,21 +21,21 @@ } & > .window { position: absolute; - box-shadow: 0 .1em .4em $color-shadow; + box-shadow: 0 1px 6px $color-shadow; z-index: 0; & > .arrow { - width: 1em; - height: 1em; - margin: -.5em; + width: 16px; + height: 16px; + margin: -8px; background-color: $color-bg-panel; - box-shadow: 0 .1em .4em $color-shadow; + box-shadow: 0 1px 6px $color-shadow; position: absolute; transform: rotate(45deg); z-index: -1; } & > .content { - border-radius: .1em; + border-radius: 1px; background-color: $color-bg-panel; height: inherit; overflow: auto; diff --git a/front/core/components/popup/index.html b/front/core/components/popup/index.html index 3e542d51f..ad8fb2598 100644 --- a/front/core/components/popup/index.html +++ b/front/core/components/popup/index.html @@ -2,6 +2,7 @@
\ No newline at end of file diff --git a/front/core/components/popup/index.js b/front/core/components/popup/index.js index 994f4a0e7..0dea66254 100644 --- a/front/core/components/popup/index.js +++ b/front/core/components/popup/index.js @@ -51,6 +51,7 @@ export default class Popup extends Component { {parentBoundTranscludeFn: this.$transclude} )[0]; this.windowEl = this.popup.querySelector('.window'); + this.windowEl.focus(); let classList = this.popup.classList; classList.add(this.displayMode); diff --git a/front/core/components/popup/style.scss b/front/core/components/popup/style.scss index 42d69141d..c3e45ccf0 100644 --- a/front/core/components/popup/style.scss +++ b/front/core/components/popup/style.scss @@ -19,19 +19,20 @@ justify-content: center; align-items: center; background-color: rgba(0, 0, 0, .6); - padding: 1em; + padding: 16px; box-sizing: border-box; & > .window { position: relative; - box-shadow: 0 0 .4em $color-shadow; + box-shadow: 0 0 6px $color-shadow; background-color: $color-bg-panel; - border-radius: .2em; + border-radius: 3px; overflow: auto; box-sizing: border-box; max-height: 100%; transform: scale3d(.9, .9, .9); transition: transform 200ms ease-in-out; + outline: none; } &.shown > .window { transform: scale3d(1, 1, 1); diff --git a/front/core/components/range/style.scss b/front/core/components/range/style.scss index 6898f8cda..2a894492e 100644 --- a/front/core/components/range/style.scss +++ b/front/core/components/range/style.scss @@ -37,7 +37,7 @@ .vn-range { & > label { - font-size: 12px; + font-size: .75rem; &.main { color: $color-button; @@ -57,7 +57,7 @@ background: transparent; border-color: transparent; -webkit-appearance: none; - margin: .2em 0; + margin: 3px 0; &:focus { outline: none; diff --git a/front/core/components/scroll-up/style.scss b/front/core/components/scroll-up/style.scss index 1bf7ea982..44d12f14f 100644 --- a/front/core/components/scroll-up/style.scss +++ b/front/core/components/scroll-up/style.scss @@ -1,6 +1,6 @@ vn-scroll-up { - top: 5.5em; - right: 2em; + top: 88px; + right: 32px; display: none; position: fixed; } \ No newline at end of file diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 640ed48d6..21e72f60d 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -239,6 +239,8 @@ export default class Searchbar extends Component { this.filter = filter; + if (!filter && this.model) + this.model.clear(); if (source != 'state') this.transition = this.$state.go(state, params, opts).transition; if (source != 'bar') diff --git a/front/core/components/searchbar/style.scss b/front/core/components/searchbar/style.scss index 31907792c..c1d4be21c 100644 --- a/front/core/components/searchbar/style.scss +++ b/front/core/components/searchbar/style.scss @@ -2,24 +2,24 @@ vn-searchbar { display: block; - max-width: 35em; + max-width: 560px; margin: 0 auto; .search-params { flex: 1; - margin: .05em 0; + margin: 1px 0; overflow: visible; display: flex; - max-width: 24em; + max-width: 384px; & > .search-param { color: rgba(0, 0, 0, .6); background-color: rgba(0, 0, 0, .1); - padding: .1em .4em; - margin-left: .2em; + padding: 1px 6px; + margin-left: 3px; display: inline-block; - border-radius: .8em; - max-width: 12em; + border-radius: 12px; + max-width: 192px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; @@ -39,7 +39,7 @@ vn-searchbar { } .search-panel { - max-height: 48em; + max-height: 768px; & > form { padding: $spacing-lg; diff --git a/front/core/components/snackbar/snackbar.js b/front/core/components/snackbar/snackbar.js index eb75f9ab8..9439198f0 100644 --- a/front/core/components/snackbar/snackbar.js +++ b/front/core/components/snackbar/snackbar.js @@ -6,9 +6,8 @@ import './style.scss'; * A simple component to show non-obstructive notifications to the user. */ export default class Controller extends Component { - constructor($element, $translate) { - super($element); - this.$translate = $translate; + constructor($element, $) { + super($element, $); this.snackbar = $element[0].firstChild; this.$snackbar = angular.element(this.snackbar); } @@ -19,38 +18,54 @@ export default class Controller extends Component { * @return {Object} Created snackbar shape */ createShape(data) { - let shape = document.createElement('div'); - shape.className = 'shape'; + let shape = Object.assign({ + nMessages: 1 + }, data); + + let element = document.createElement('div'); + element.className = 'shape'; + setTimeout(() => element.classList.add('shown'), 30); + shape.element = element; + + if (shape.type) + element.classList.add(shape.type); let button = document.createElement('button'); + button.addEventListener('click', () => this.onButtonClick(shape)); + element.appendChild(button); - let buttonText = data.actionText || this.$translate.instant('Hide'); + let buttonText = shape.actionText || this.$t('Hide'); buttonText = document.createTextNode(buttonText); button.appendChild(buttonText); - button.addEventListener('click', () => { - this.onButtonClick(shape); - }); - - shape.appendChild(button); - let shapeText = document.createElement('div'); shapeText.setAttribute('class', 'text'); - shape.appendChild(shapeText); + element.appendChild(shapeText); - let text = document.createTextNode(data.message); + let text = document.createTextNode(shape.message); shapeText.appendChild(text); - if (data.shapeType) - shape.classList.add(data.shapeType); + let chip = document.createElement('vn-chip'); + chip.className = 'warning small'; + chip.style.visibility = 'hidden'; - let parent = this.snackbar.querySelectorAll('.shape')[0]; + let chipWrapper = document.createElement('div'); + chip.append(chipWrapper); + + let span = document.createElement('span'); + chipWrapper.append(span); + + let chipText = document.createTextNode(shape.nMessages); + span.append(chipText); + + shapeText.appendChild(chip); + + let parent = this.snackbar.querySelector('.shape'); if (parent) - this.snackbar.insertBefore(shape, parent); + this.snackbar.insertBefore(element, parent); else - this.snackbar.appendChild(shape); - + this.snackbar.appendChild(element); return shape; } @@ -61,58 +76,28 @@ export default class Controller extends Component { * @param {Object} data The message data */ show(data) { - this.actionHandler = data.actionHandler; + let shape = this.lastShape; - let shape; + const isEqual = shape + && shape.type == data.type + && shape.message == data.message; - const lastShape = this.lastShape; - const lastShapeData = lastShape && lastShape.data; - const isEqual = lastShape && (lastShapeData.shapeType == data.shapeType && lastShapeData.message == data.message); + if (isEqual) { + shape.nMessages++; - if (lastShape && isEqual) { - shape = lastShape.element; + const chip = shape.element.querySelector('.text vn-chip'); + chip.style.visibility = 'visible'; - const shapeText = shape.querySelector('.text'); - let chip = shapeText.querySelector('vn-chip'); - - if (chip) { - const text = chip.querySelector('span'); - const number = parseInt(text.innerHTML); - - text.innerHTML = number + 1; - } else { - chip = document.createElement('vn-chip'); - chip.setAttribute('class', 'warning small'); - let parent = document.createElement('div'); - let span = document.createElement('span'); - let text = document.createTextNode(1); - span.append(text); - parent.append(span); - chip.append(parent); - - shapeText.appendChild(chip); - } - - lastShape.element.classList.add('shown'); - - if (this.hideTimeout) - clearTimeout(this.hideTimeout); - } else { + const span = chip.querySelector('span'); + span.innerHTML = shape.nMessages; + } else shape = this.createShape(data); - setTimeout(() => - shape.classList.add('shown'), 30); - } + clearTimeout(shape.hideTimeout); + shape.hideTimeout = setTimeout( + () => this.hide(shape), shape.timeout || 3000); - this.hideTimeout = setTimeout(() => { - this.hide(shape); - this.lastShape = null; - }, data.timeout || 3000); - - this.lastShape = { - data: data, - element: shape - }; + this.lastShape = shape; } /** @@ -121,8 +106,7 @@ export default class Controller extends Component { * @param {Object} data The message data */ showError(data) { - data.shapeType = 'error'; - + data.type = 'error'; this.show(data); } @@ -132,8 +116,7 @@ export default class Controller extends Component { * @param {Object} data The message data */ showSuccess(data) { - data.shapeType = 'success'; - + data.type = 'success'; this.show(data); } @@ -142,8 +125,11 @@ export default class Controller extends Component { * @param {Object} shape Snackbar element */ hide(shape) { - setTimeout(() => shape.classList.remove('shown'), 30); - setTimeout(() => shape.remove(), 250); + if (this.lastShape == shape) + this.lastShape = null; + + shape.element.classList.remove('shown'); + setTimeout(() => shape.element.remove(), 250); } onSnackbarClick(event) { @@ -151,13 +137,12 @@ export default class Controller extends Component { } onButtonClick(shape) { - if (this.actionHandler) - this.actionHandler(); + if (shape.actionHandler) + shape.actionHandler(); else this.hide(shape); } } -Controller.$inject = ['$element', '$translate']; ngModule.component('vnSnackbar', { template: require('./snackbar.html'), diff --git a/front/core/components/snackbar/style.scss b/front/core/components/snackbar/style.scss index deaf010fc..465c53851 100644 --- a/front/core/components/snackbar/style.scss +++ b/front/core/components/snackbar/style.scss @@ -1,33 +1,33 @@ @import "variables"; vn-snackbar #shapes { - max-height: 20.625em; - margin-left: -12.5em; + max-height: 330px; + margin-left: -160px; position: fixed; z-index: 100; - width: 25em; + width: 320px; left: 50%; bottom: 0 } vn-snackbar .shape { - background-color: rgba(0, 0, 0, 0.8); - box-shadow: 0 0 .4em $color-shadow; + background-color: rgba(0, 0, 0, .8); + box-shadow: 0 0 6px $color-shadow; transition: transform 300ms ease-in-out; - transform: translateY(20em); + transform: translateY(320px); box-sizing: border-box; - border-radius: .2em; + border-radius: 3px; margin-bottom: 15px; color: white; - padding: 0.8em; + padding: 12px; & > .text { text-align: center; vn-chip { position: absolute; - left: -1em; - top: -1em; + left: -16px; + top: -16px; } } @@ -36,32 +36,32 @@ vn-snackbar .shape { } &.success { - background-color: rgba(163, 209, 49, 0.8); + background-color: rgba(163, 209, 49, .8); color: #445911; & > button { - color: rgba(1, 1, 1, 0.6); + color: rgba(1, 1, 1, .6); } } &.error { - background-color: rgba(198, 40, 40, 0.8); + background-color: rgba(198, 40, 40, .8); & > button { - color: rgba(1, 1, 1, 0.6); + color: rgba(1, 1, 1, .6); } } & > button { background-color: transparent; text-transform: uppercase; - margin-left: .5em; + margin-left: 8px; font-weight: bold; cursor: pointer; color: $color-main; float: right; border: none; - padding: .5em; - margin: -.5em + padding: 8px; + margin: -8px; } } \ No newline at end of file diff --git a/front/core/components/step-control/style.scss b/front/core/components/step-control/style.scss index 9acc1f314..b4d0d5afe 100644 --- a/front/core/components/step-control/style.scss +++ b/front/core/components/step-control/style.scss @@ -22,11 +22,11 @@ vn-step-control { border: 2px solid $color-main; background-color: white; align-content: center; - margin-top: -9.5px; + margin-top: -10px; border-radius: 50%; cursor: pointer; height: 15px; - width: 15px + width: 15px; } & > .steps > .step .circle.active { background-color: $color-main; @@ -36,7 +36,7 @@ vn-step-control { flex: auto; flex-direction: row; justify-content: space-between; - margin-top: 10px + margin-top: 10px; } & > .buttons > .step { display: flex diff --git a/front/core/components/table/style.scss b/front/core/components/table/style.scss index 41d1f6db8..7dd69d89f 100644 --- a/front/core/components/table/style.scss +++ b/front/core/components/table/style.scss @@ -14,7 +14,7 @@ vn-table { & > vn-thead, & > thead { display: table-header-group; - border-bottom: .15em solid $color-spacer; + border-bottom: 2px solid $color-spacer; & > * > th { font-weight: normal; @@ -52,14 +52,14 @@ vn-table { } & > vn-tfoot, & > tfoot { - border-top: .15em solid $color-spacer; + border-top: 2px solid $color-spacer; display: table-footer-group } & > * > vn-tr, & > * > a.vn-tr, & > * > tr { display: table-row; - height: 3em; + height: 48px; } vn-thead, vn-tbody, vn-tfoot, thead, tbody, tfoot { @@ -69,8 +69,8 @@ vn-table { & > vn-th, & > th { color: $color-font-light; - padding-top: 1em; - padding-bottom: .8em; + padding-top: 16px; + padding-bottom: 12px; } & > vn-th, & > vn-td, @@ -86,14 +86,14 @@ vn-table { vertical-align: middle; display: table-cell; text-align: left; - padding: .6em .5em; + padding: 9px 8px; white-space: nowrap; text-overflow: ellipsis; - max-width: 5em; + max-width: 80px; &[number] { text-align: right; - width: 6em; + width: 96px; } &[center] { text-align: center; @@ -103,7 +103,7 @@ vn-table { text-align: center; } &[expand] { - max-width: 25em; + max-width: 400px; min-width: 0; } vn-icon.bright, i.bright { @@ -111,10 +111,10 @@ vn-table { } } & > :last-child { - padding-right: 1.4em; + padding-right: 22px; } & > :first-child { - padding-left: 1.4em; + padding-left: 22px; } } & > a.vn-tr { @@ -123,7 +123,7 @@ vn-table { } vn-tbody > *, tbody > * { - border-bottom: .1em solid $color-spacer-light; + border-bottom: 1px solid $color-spacer-light; &:last-child { border-bottom: none; @@ -134,8 +134,8 @@ vn-table { & > vn-td, & > td { .chip { - padding: .3em; - border-radius: .3em; + padding: 4px; + border-radius: 4px; color: $color-font-bg; &.notice { @@ -158,7 +158,7 @@ vn-table { vn-icon-menu { display: inline-block; color: $color-main; - padding: .25em + padding: 4px } } & > [actions] { diff --git a/front/core/components/td-editable/style.scss b/front/core/components/td-editable/style.scss index e37e1086c..a1fe4664e 100644 --- a/front/core/components/td-editable/style.scss +++ b/front/core/components/td-editable/style.scss @@ -8,7 +8,7 @@ vn-td-editable { text { border: 1px dashed rgba(0, 0, 0, .15); - border-radius: 1em; + border-radius: 16px; padding: 5px 10px; min-height: 15px; display: block; @@ -36,16 +36,16 @@ vn-td-editable { left: 0; box-sizing: border-box; align-items: center; - padding: .6em; + padding: 9px; overflow: visible; & > field { flex: 1; background-color: $color-bg-panel; - padding: .5em; - box-shadow: 0 0 .4em rgba(0, 0, 0, .2); - border-radius: .1em; - min-width: 6em; + padding: 8px; + box-shadow: 0 0 6px rgba(0, 0, 0, .2); + border-radius: 1px; + min-width: 96px; & > * { width: 100%; diff --git a/front/core/components/toggle/style.scss b/front/core/components/toggle/style.scss index 31769d2a5..5213215d6 100644 --- a/front/core/components/toggle/style.scss +++ b/front/core/components/toggle/style.scss @@ -22,7 +22,7 @@ height: 20px; min-width: 20px; margin: 6px 0; - margin-right: .6em; + margin-right: 9px; border: 2px solid #666; } & > .btn > .focus-mark { diff --git a/front/core/components/tooltip/style.scss b/front/core/components/tooltip/style.scss index 926142582..926419c24 100644 --- a/front/core/components/tooltip/style.scss +++ b/front/core/components/tooltip/style.scss @@ -6,7 +6,7 @@ z-index: 150; background-color: $color-bg-dark; color: $color-active-font; - border-radius: .2em; + border-radius: 3px; &.show { display: inherit; diff --git a/front/core/components/treeview/style.scss b/front/core/components/treeview/style.scss index 7cd8c8bea..b8af114c1 100644 --- a/front/core/components/treeview/style.scss +++ b/front/core/components/treeview/style.scss @@ -11,7 +11,7 @@ vn-treeview-childs { list-style: none; ul { - padding-left: 2.2em; + padding-left: 35px; } } } @@ -37,7 +37,7 @@ vn-treeview-childs { vn-treeview-child { line-height: 38px; - font-size: 16px; + font-size: 1rem; display: block; .node { diff --git a/front/core/components/wday-picker/style.scss b/front/core/components/wday-picker/style.scss index be610c733..a8e3a65ab 100644 --- a/front/core/components/wday-picker/style.scss +++ b/front/core/components/wday-picker/style.scss @@ -9,11 +9,11 @@ & > span { @extend %clickable; border-radius: 50%; - padding: .4em; - margin: .2em; + padding: 6px; + margin: 3px; display: inline-flex; - width: 1.5em; - height: 1.5em; + width: 24px; + height: 24px; justify-content: center; align-items: center; outline: none; diff --git a/front/core/directives/droppable.scss b/front/core/directives/droppable.scss index f2e18a3ad..02261b5bc 100644 --- a/front/core/directives/droppable.scss +++ b/front/core/directives/droppable.scss @@ -5,8 +5,8 @@ .vn-draggable, [vn-droppable] { border: 2px dashed transparent; - border-radius: 0.5em; - transition: all 0.5s; + border-radius: 8px; + transition: all .5s; } .vn-droppable, diff --git a/front/core/directives/focus.js b/front/core/directives/focus.js index 869e9a7f0..8b75adcbc 100644 --- a/front/core/directives/focus.js +++ b/front/core/directives/focus.js @@ -1,11 +1,11 @@ import ngModule from '../module'; import isMobile from '../lib/is-mobile'; -export function focus($scope, input) { +export function focus($timeout, input) { if (isMobile) return; const element = input; - let selector = 'input, textarea, button, submit'; + const selector = 'input, textarea, button, submit'; if (!input.matches(selector)) input = input.querySelector(selector); @@ -20,26 +20,24 @@ export function focus($scope, input) { return; } - input.focus(); - - if (input.select) { - $scope.$applyAsync(() => { + $timeout(() => { + input.focus(); + if (input.select) input.select(); - }); - } + }); } -/** +/* * Sets the focus and selects the text on the input. - * - * @return {Object} The directive */ -export function directive() { +export function directive($timeout) { return { restrict: 'A', link: function($scope, $element) { - $scope.$watch('', () => focus($scope, $element[0])); + $scope.$watch('', () => focus($timeout, $element[0])); } }; } +directive.$inject = ['$timeout']; + ngModule.directive('vnFocus', directive); diff --git a/front/core/directives/specs/focus.spec.js b/front/core/directives/specs/focus.spec.js index 82cd7d84d..dd917dc29 100644 --- a/front/core/directives/specs/focus.spec.js +++ b/front/core/directives/specs/focus.spec.js @@ -6,7 +6,7 @@ describe('Directive focus', () => { beforeEach(ngModule('vnCore')); compile = (_element, _childElement) => { - inject(($compile, $rootScope) => { + inject(($compile, $rootScope, $flushPendingTasks) => { $scope = $rootScope.$new(); $element = angular.element(_element); if (_childElement) @@ -15,7 +15,7 @@ describe('Directive focus', () => { $element[0].focus = jasmine.createSpy('focus'); $element[0].select = jasmine.createSpy('select'); $compile($element)($scope); - $scope.$digest(); + $flushPendingTasks(); }); }; @@ -27,7 +27,6 @@ describe('Directive focus', () => { expect($element[0].firstChild.focus).toHaveBeenCalledWith(); }); - it('should call focus function on the element', () => { let html = ``; compile(html); diff --git a/front/core/directives/uvc.scss b/front/core/directives/uvc.scss index 5221b8bdd..0cdf0ba1a 100644 --- a/front/core/directives/uvc.scss +++ b/front/core/directives/uvc.scss @@ -1,6 +1,6 @@ vn-table vn-dialog[vn-id="uvc"]{ & > div { - min-width: 18em; + min-width: 288px; align-items: center; } diff --git a/front/core/directives/zoom-image.scss b/front/core/directives/zoom-image.scss index e075ff3a1..7debed995 100644 --- a/front/core/directives/zoom-image.scss +++ b/front/core/directives/zoom-image.scss @@ -5,7 +5,7 @@ position: fixed; top: 0; z-index: 25; - background-color: rgba(1, 1, 1, 0.6); + background-color: rgba(1, 1, 1, .6); & > div { display: flex; @@ -14,13 +14,13 @@ width: inherit; height: inherit; box-sizing: border-box; - padding: 1em; + padding: 16px; & > img { cursor: zoom-out; max-height: 100%; max-width: 100%; - border-radius: .2em; + border-radius: 3px; } } } diff --git a/front/core/services/auth.js b/front/core/services/auth.js index f59c4c0dd..a1dcfa395 100644 --- a/front/core/services/auth.js +++ b/front/core/services/auth.js @@ -45,8 +45,11 @@ export default class Auth { } login(user, password, remember) { - if (!user) - return this.$q.reject(new UserError('Please enter your username')); + if (!user) { + let err = new UserError('Please enter your username'); + err.code = 'EmptyLogin'; + return this.$q.reject(err); + } let params = { user, diff --git a/front/core/services/week-days.js b/front/core/services/week-days.js index 698d6df2c..cf5722520 100644 --- a/front/core/services/week-days.js +++ b/front/core/services/week-days.js @@ -1,12 +1,7 @@ import ngModule from '../module'; /** - * @property {Array} days Weekdays data array with the same indexes as Date.getDay() - * @property {Object} map Weekdays data map using weekday codes as key - * @property {Array} localeCodes Locale weekday codes indexes depend on current locale - * @property {Array} locale Weekday data array with indexes depending on current locale - * - * Weekday properties: + * Stores useful information about a weekday. * * @property {Number} index The weekday index acording to Date.getDay() * @property {String} code The weekday code @@ -17,33 +12,34 @@ import ngModule from '../module'; * @property {String} localeChar The first weekday letter in current locale * @property {String} localeAbr The abreviated 3 letters weekday name in current locale */ -class WeekDays { +export class WeekDay { + constructor(code, name) { + this.code = code; + this.name = name; + } +} + +/** + * Stores information about weekdays in many formats to be accessed in different + * ways depending on the context. + * + * @property {Array} days Weekdays array with the same indexes as Date.getDay() + * @property {Object} map Weekdays map using weekday codes as keys + * @property {Array} locale Weekday data array with indexes depending on current locale + * @property {Array} localeCodes Locale weekday codes with indexes depending on current locale + */ +export default class WeekDays { constructor($translate) { this.$translate = $translate; this.days = [ - { - code: 'sun', - name: 'Sunday' - }, { - code: 'mon', - name: 'Monday' - }, { - code: 'tue', - name: 'Tuesday' - }, { - code: 'wed', - name: 'Wednesday' - }, { - code: 'thu', - name: 'Thursday' - }, { - code: 'fri', - name: 'Friday' - }, { - code: 'sat', - name: 'Saturday' - } + new WeekDay('sun', 'Sunday'), + new WeekDay('mon', 'Monday'), + new WeekDay('tue', 'Tuesday'), + new WeekDay('wed', 'Wednesday'), + new WeekDay('thu', 'Thursday'), + new WeekDay('fri', 'Friday'), + new WeekDay('sat', 'Friday') ]; this.map = {}; @@ -83,6 +79,13 @@ class WeekDays { this.locales.push(this.map[code]); } + /** + * Transforms weekday set into an array whose indexes are weekday index + * with selected days set to %true. + * + * @param {String} weekDays Weekday codes separated by commas + * @return {Array} Array with selected days set to %true + */ fromSet(weekDays) { let wdays = []; @@ -97,6 +100,14 @@ class WeekDays { return wdays; } + /** + * Perform the inverse operation of fromSet() method. Transforms an + * array whose indexes are weekday index with selected days set to %true to + * weekday codes separated by commas. + * + * @param {Array} wdays Array with selected days set to %true + * @return {String} weekDays Weekday codes separated by commas + */ toSet(wdays) { let weekDays = []; diff --git a/front/core/styles/animations.scss b/front/core/styles/animations.scss index 039f79c77..8ae119fb4 100644 --- a/front/core/styles/animations.scss +++ b/front/core/styles/animations.scss @@ -2,7 +2,7 @@ @keyframes nothing {} @keyframes slideIn { from { - transform: translate3d(-2em, 0, 0); + transform: translate3d(-32px, 0, 0); opacity: 0; } to { diff --git a/front/core/styles/border.scss b/front/core/styles/border.scss index 7450b5857..757ab453f 100644 --- a/front/core/styles/border.scss +++ b/front/core/styles/border.scss @@ -19,5 +19,5 @@ /* Border Radius */ .border-radius { - border-radius: .3em; + border-radius: 4px; } \ No newline at end of file diff --git a/front/core/styles/font-family.scss b/front/core/styles/font-family.scss index b461917ce..db41ad750 100644 --- a/front/core/styles/font-family.scss +++ b/front/core/styles/font-family.scss @@ -21,7 +21,7 @@ font-family: 'Material Icons'; font-weight: normal; font-style: normal; - font-size: 24px; /* Preferred icon size */ + font-size: 1.5rem; /* Preferred icon size */ display: inline-block; line-height: 1; text-transform: none; diff --git a/front/core/styles/global.scss b/front/core/styles/global.scss index 8b3d465f1..555b54f9e 100644 --- a/front/core/styles/global.scss +++ b/front/core/styles/global.scss @@ -1,6 +1,7 @@ @import "variables"; html { + font-size: $font-size; background-color: $color-bg; overflow: auto; height: 100%; @@ -9,7 +10,6 @@ body { height: 100%; font-family: vn-font; color: $color-font; - font-size: $font-size; margin: 0; padding: 0; } @@ -44,4 +44,4 @@ a { .ng-leave, .ng-enter { transition: none; -} \ No newline at end of file +} diff --git a/front/core/styles/layout.scss b/front/core/styles/layout.scss index 925526dca..85088db6a 100644 --- a/front/core/styles/layout.scss +++ b/front/core/styles/layout.scss @@ -40,7 +40,7 @@ html [vn-nine], html [vn-ten], html [vn-eleven], html [vn-twelve]{ - flex-basis: 0.000000001px; + flex-basis: .1px; } html [vn-auto], vn-auto, .vn-auto { flex-basis: auto; diff --git a/front/core/styles/responsive.scss b/front/core/styles/responsive.scss index 9cc58dd12..3e16cf128 100644 --- a/front/core/styles/responsive.scss +++ b/front/core/styles/responsive.scss @@ -1,52 +1,53 @@ @import "variables"; - -/* Desktop - Laptop 1360x768 */ +/* +// Desktop - Laptop 1360x768 @media (max-resolution: 119dpi) and (min-device-width: 1340px) and (max-device-width: 1899px) { - body { font-size: 10pt; } + html { font-size: 10pt; } } -/* Mobile - Low DPI */ +// Mobile - Low DPI @media (min-resolution: 120dpi), (-webkit-min-device-pixel-ratio: 1.5) { - body { font-size: 9pt; } + html { font-size: 9pt; } } @media (min-resolution: 144dpi), (-webkit-min-device-pixel-ratio: 1.5) { - body { font-size: 11pt; } + html { font-size: 11pt; } } -/* Mobile - Normal DPI */ +// Mobile - Normal DPI @media (max-device-width: 383px) and (min-resolution: 192dpi), (max-device-width: 383px) and (-webkit-min-device-pixel-ratio: 2) { - body { font-size: 10pt; } + html { font-size: 10pt; } } @media (min-device-width: 384px) and (min-resolution: 192dpi), (min-device-width: 384px) and (-webkit-min-device-pixel-ratio: 2) { - body { font-size: 11pt; } + html { font-size: 11pt; } } -/* Mobile - High DPI */ +// Mobile - High DPI @media (max-device-width: 411px) and (min-resolution: 249dpi), (max-device-width: 411px) and (-webkit-min-device-pixel-ratio: 3) { - body { font-size: 10pt; } + html { font-size: 10pt; } } @media (min-device-width: 412px) and (min-resolution: 249dpi), (min-device-width: 412px) and (-webkit-min-device-pixel-ratio: 3) { - body { font-size: 11pt; } + html { font-size: 11pt; } } +*/ .vn-hide-narrow { @media (max-width: $mobile-width) { diff --git a/front/core/styles/text.scss b/front/core/styles/text.scss index b1624cd26..751a5594b 100644 --- a/front/core/styles/text.scss +++ b/front/core/styles/text.scss @@ -3,46 +3,46 @@ /* Headings */ .text-h1, h1 { - font-size: 32pt; + font-size: 2.3rem; } .text-h2, h2 { - font-size: 28pt; + font-size: 2.25rem; } .text-h3, h3 { - font-size: 24pt; + font-size: 2rem; } .text-h4, h4 { - font-size: 20pt; + font-size: 1.6rem; } .text-h5, h5 { - font-size: 16pt; + font-size: 1.3rem; } .text-h6, h6 { - font-size: 14pt; + font-size: 1.125rem; } .text-subtitle1 { - font-size: 13pt; + font-size: 1.06rem; } .text-subtitle2 { - font-size: 12pt; + font-size: 1rem; } .text-body1 { - font-size: 11pt; + font-size: .875rem; } .text-body2 { - font-size: 11pt; + font-size: .875rem; } .text-caption { - font-size: 11pt; + font-size: .875rem; } .text-overline { - font-size: 10pt; + font-size: .8rem; } h1, h2, h3, h4, h5, h6 { padding: 0; margin-top: 0; - margin-bottom: .3em; + margin-bottom: 4px; } /* Colors */ diff --git a/front/core/styles/variables.scss b/front/core/styles/variables.scss index 89e487ad7..0958c88b8 100644 --- a/front/core/styles/variables.scss +++ b/front/core/styles/variables.scss @@ -1,17 +1,17 @@ @import "./util"; -$menu-width: 16em; -$topbar-height: 4em; +$font-size: 12pt; +$menu-width: 256px; +$topbar-height: 56px; $mobile-width: 800px; -$font-size: 16px; // Width -$width-xs: 25em; -$width-sm: 34em; -$width-md: 50em; -$width-lg: 80em; -$width-xl: 100em; +$width-xs: 400px; +$width-sm: 544px; +$width-md: 800px; +$width-lg: 1280px; +$width-xl: 1600px; // Spacing @@ -115,6 +115,6 @@ $color-alert-light: darken($color-alert, 35%); // Border -$border-thin: .05em solid $color-spacer; -$border-thin-light: .05em solid $color-spacer-light; -$shadow: 0 .15em .15em 0 rgba(0, 0, 0, .3); +$border-thin: 1px solid $color-spacer; +$border-thin-light: 1px solid $color-spacer-light; +$shadow: 0 2px 2px 0 rgba(0, 0, 0, .3); diff --git a/front/salix/components/descriptor/style.scss b/front/salix/components/descriptor/style.scss index af719cc0d..a048c12b3 100644 --- a/front/salix/components/descriptor/style.scss +++ b/front/salix/components/descriptor/style.scss @@ -3,7 +3,7 @@ @import "./variables"; .vn-descriptor { - box-shadow: 0 .1em .2em $color-shadow; + box-shadow: 0 1px 3px $color-shadow; & > .header { display: flex; @@ -26,7 +26,7 @@ padding: 10px; } vn-icon { - font-size: 1.8em; + font-size: 1.75rem; } } } @@ -51,7 +51,7 @@ & > vn-icon { padding: $spacing-sm; color: $color-marginal; - font-size: 1.5em; + font-size: 1.5rem; &.bright { color: $color-main; @@ -70,7 +70,7 @@ margin: 0 $spacing-sm; & > vn-icon { - font-size: 1.8em; + font-size: 1.75rem; padding: 0; } } diff --git a/front/salix/components/home/style.scss b/front/salix/components/home/style.scss index 268260bbd..7524d2be3 100644 --- a/front/salix/components/home/style.scss +++ b/front/salix/components/home/style.scss @@ -2,7 +2,7 @@ vn-home { display: block; - padding: .5em; + padding: 8px; & > div { & > h6 { @@ -16,7 +16,7 @@ vn-home { flex-direction: row; justify-content: center; flex-wrap: wrap; - max-width: 44em; + max-width: 704px; margin: 0 auto; & > a { @@ -27,10 +27,10 @@ vn-home { color: $color-font-dark; display: flex; flex-direction: column; - height: 8em; - width: 8em; - margin: .5em; - padding: 1em; + height: 128px; + width: 128px; + margin: 8px; + padding: 16px; justify-content: center; & > div { @@ -41,21 +41,21 @@ vn-home { & > vn-icon { display: block; - font-size: 3.5em; + font-size: 3.5rem; } } & > span { - font-size: 0.9em; + font-size: .875rem; text-align: center; } & > h4 { max-width: 100%; text-align: center; - font-size: 12pt; + font-size: 1rem; overflow: hidden; color: inherit; margin: 0; - line-height: 1.5em; + line-height: 24px; /* & > .bind-letter { color: #FD0; diff --git a/front/salix/components/layout/style.scss b/front/salix/components/layout/style.scss index 1a483ab96..14af8ac23 100644 --- a/front/salix/components/layout/style.scss +++ b/front/salix/components/layout/style.scss @@ -7,42 +7,42 @@ vn-layout { right: 0; left: 0; z-index: 10; - box-shadow: 0 .1em .2em $color-shadow; + box-shadow: 0 1px 3px $color-shadow; height: $topbar-height; - padding: 0 1em; + padding: 0 16px; justify-content: space-between; & > .side { flex: auto; display: flex; align-items: center; - width: 5em; + width: 80px; transition: width 200ms; } & > .start { - padding-right: 1em; + padding-right: 16px; overflow: hidden; & > .logo > img { - height: 2em; + height: 32px; display: block; } & > .main-title { - font-size: 1.6em; + font-size: 1.56rem; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; - padding-left: .4em; + padding-left: 6px; } & > vn-spinner { - padding: 0 .4em; + padding: 0 6px; } } & > vn-slot { flex: auto; } & > .end { - padding-left: 1em; + padding-left: 16px; justify-content: flex-end; } .show-menu { @@ -50,7 +50,7 @@ vn-layout { } .vn-button { color: inherit; - font-size: 1.05em; + font-size: 1.05rem; padding: 0; } } @@ -66,7 +66,7 @@ vn-layout { } &.left-menu { & > vn-topbar > .start { - width: 5em + $menu-width; + width: 80px + $menu-width; } & > .main-view { padding-left: $menu-width; @@ -74,11 +74,14 @@ vn-layout { } &.right-menu { & > vn-topbar > .end { - width: 5em + $menu-width; + width: 80px + $menu-width; } & > .main-view { padding-right: $menu-width; } + [fixed-bottom-right] { + right: 64px + $menu-width; + } } & > .main-view { padding-top: $topbar-height; @@ -89,6 +92,11 @@ vn-layout { padding: $spacing-md; box-sizing: border-box } + [fixed-bottom-right] { + position: fixed; + bottom: 32px; + right: 32px; + } &.ng-enter { vn-side-menu { opacity: 0; @@ -124,6 +132,9 @@ vn-layout { & > .main-view { padding-right: 0; } + [fixed-bottom-right] { + right: 32px; + } } ui-view > * { padding-left: 0; @@ -139,22 +150,22 @@ vn-layout { & > li { @extend %clickable-light; background-color: $color-main; - margin-bottom: .6em; - padding: .8em; - border-radius: .1em; - min-width: 8em; + margin-bottom: 9px; + padding: 12px; + border-radius: 1px; + min-width: 128px; white-space: nowrap; &:last-child { margin-bottom: 0; } & > vn-icon { - padding-right: .3em; + padding-right: 4px; vertical-align: middle; } } } #user { - font-size: 1.5em; + font-size: 1.5rem; height: auto; } diff --git a/front/salix/components/left-menu/left-menu.html b/front/salix/components/left-menu/left-menu.html index 73488a24b..7db36177b 100644 --- a/front/salix/components/left-menu/left-menu.html +++ b/front/salix/components/left-menu/left-menu.html @@ -1,10 +1,11 @@
\ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index a69f6ed8b..b813214bc 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -1,18 +1,22 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($scope, vnToken, vnApp, $state, $translate, $http, aclService) { - this.$scope = $scope; - this.accessToken = vnToken.token; - this.vnApp = vnApp; - this.$state = $state; - this.$translate = $translate; - this.$http = $http; - this.aclService = aclService; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ - {callback: this.showInvoiceOutPdf, name: 'Show invoice PDF'}, - {callback: this.showDeleteInvoiceOutDialog, name: 'Delete Invoice', acl: 'invoicing'}, - {callback: this.showBookInvoiceOutDialog, name: 'Book invoice', acl: 'invoicing'} + { + name: 'Show invoice PDF', + callback: this.showInvoiceOutPdf + }, { + name: 'Delete Invoice', + callback: this.showDeleteInvoiceOutDialog, + acl: 'invoicing' + }, { + name: 'Book invoice', + callback: this.showBookInvoiceOutDialog, + acl: 'invoicing' + } ]; } @@ -22,7 +26,7 @@ class Controller { return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); }); - this.$scope.moreButton.data = options; + this.$.moreButton.data = options; } onMoreChange(callback) { @@ -58,31 +62,25 @@ class Controller { } showDeleteInvoiceOutDialog() { - this.$scope.deleteConfirmation.show(); + this.$.deleteConfirmation.show(); } showBookInvoiceOutDialog() { - this.$scope.bookConfirmation.show(); + this.$.bookConfirmation.show(); } - deleteInvoiceOut(response) { - if (response === 'accept') { - const query = `InvoiceOuts/${this.invoiceOut.id}/delete`; - this.$http.post(query).then(() => { - this.vnApp.showSuccess(this.$translate.instant('InvoiceOut deleted')); - this.$state.go('invoiceOut.index'); - }); - } + deleteInvoiceOut() { + const query = `InvoiceOuts/${this.invoiceOut.id}/delete`; + return this.$http.post(query) + .then(() => this.$state.go('invoiceOut.index')) + .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted'))); } - bookInvoiceOut(response) { - if (response === 'accept') { - const query = `InvoiceOuts/${this.invoiceOut.ref}/book`; - this.$http.post(query).then(() => { - this.vnApp.showSuccess(this.$translate.instant('InvoiceOut booked')); - this.$state.reload(); - }); - } + bookInvoiceOut() { + const query = `InvoiceOuts/${this.invoiceOut.ref}/book`; + return this.$http.post(query) + .then(() => this.$state.reload()) + .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked'))); } set quicklinks(value = {}) { @@ -94,8 +92,6 @@ class Controller { } } -Controller.$inject = ['$scope', 'vnToken', 'vnApp', '$state', '$translate', '$http', 'aclService']; - ngModule.component('vnInvoiceOutDescriptor', { template: require('./index.html'), bindings: { diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index 46ad6bc3f..d5c0fde3a 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -1,12 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnToken) { - this.accessToken = vnToken.token; - this.$ = $scope; - this.selectedInvoiceOut = null; - } - +export default class Controller extends Section { showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; @@ -27,15 +22,13 @@ export default class Controller { } openPdf(id, event) { - let url = `api/InvoiceOuts/${id}/download?access_token=${this.accessToken}`; + let url = `api/InvoiceOuts/${id}/download?access_token=${this.vnToken.token}`; window.open(url, '_blank'); event.preventDefault(); event.stopImmediatePropagation(); } } -Controller.$inject = ['$scope', 'vnToken']; - ngModule.component('vnInvoiceOutIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/invoiceOut/front/summary/index.js b/modules/invoiceOut/front/summary/index.js index 0596c616f..7b9bb9efd 100644 --- a/modules/invoiceOut/front/summary/index.js +++ b/modules/invoiceOut/front/summary/index.js @@ -1,13 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, vnToken) { - this.accessToken = vnToken.token; - this.$http = $http; - this.$ = $scope; - } - +class Controller extends Section { set invoiceOut(value) { this._invoiceOut = value; if (value && value.id) @@ -45,8 +40,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', 'vnToken']; - ngModule.component('vnInvoiceOutSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/invoiceOut/front/summary/index.spec.js b/modules/invoiceOut/front/summary/index.spec.js index f6ab4cb91..ac6c40bcf 100644 --- a/modules/invoiceOut/front/summary/index.spec.js +++ b/modules/invoiceOut/front/summary/index.spec.js @@ -4,12 +4,15 @@ describe('InvoiceOut', () => { describe('Component summary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('invoiceOut')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnInvoiceOutSummary'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnInvoiceOutSummary', {$element, $scope}); controller.invoiceOut = {id: 1}; })); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index d8ec5914a..c085e075a 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -44,6 +44,9 @@ "ItemTypeTag": { "dataSource": "vn" }, + "ItemShelving": { + "dataSource": "vn" + }, "ItemShelvingSale": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-sale.json b/modules/item/back/models/item-shelving-sale.json index 547c882a0..04f505ddd 100644 --- a/modules/item/back/models/item-shelving-sale.json +++ b/modules/item/back/models/item-shelving-sale.json @@ -25,6 +25,11 @@ "model": "Sale", "foreignKey": "saleFk" }, + "itemShelving": { + "type": "belongsTo", + "model": "ItemShelving", + "foreignKey": "itemShelvingFk" + }, "user": { "type": "belongsTo", "model": "Account", diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json new file mode 100644 index 000000000..0fcc00f7e --- /dev/null +++ b/modules/item/back/models/item-shelving.json @@ -0,0 +1,40 @@ +{ + "name": "ItemShelving", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelving" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "shelve": { + "type": "string" + }, + "deep": { + "type": "number" + }, + "quantity": { + "type": "number" + }, + "created": { + "type": "Date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + } +} diff --git a/modules/item/front/barcode/index.html b/modules/item/front/barcode/index.html index dba745d28..ade4c2f7d 100644 --- a/modules/item/front/barcode/index.html +++ b/modules/item/front/barcode/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemBarcodes" fields="['id', 'itemFk', 'code']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" data="barcodes" auto-load="true"> diff --git a/modules/item/front/barcode/index.js b/modules/item/front/barcode/index.js index 4096ab7eb..d9e17a42a 100644 --- a/modules/item/front/barcode/index.js +++ b/modules/item/front/barcode/index.js @@ -1,22 +1,16 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); }); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemBarcode', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/basic-data/index.js b/modules/item/front/basic-data/index.js index 33a60b32d..fb80c5178 100644 --- a/modules/item/front/basic-data/index.js +++ b/modules/item/front/basic-data/index.js @@ -1,6 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -class Controller extends Component { +import Section from 'salix/components/section'; + +class Controller extends Section { showIntrastat(event) { if (event.defaultPrevented) return; event.preventDefault(); diff --git a/modules/item/front/basic-data/index.spec.js b/modules/item/front/basic-data/index.spec.js index 178fac278..fd7be5d93 100644 --- a/modules/item/front/basic-data/index.spec.js +++ b/modules/item/front/basic-data/index.spec.js @@ -5,14 +5,13 @@ describe('vnItemBasicData', () => { let $httpBackend; let $scope; let controller; - let $element; beforeEach(ngModule('item')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnItemBasicData', {$element, $scope}); controller.$.watcher = {}; controller.$params.id = 1; diff --git a/modules/item/front/botanical/index.js b/modules/item/front/botanical/index.js index 51161d53a..03c62a0e3 100644 --- a/modules/item/front/botanical/index.js +++ b/modules/item/front/botanical/index.js @@ -1,17 +1,17 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($http, $state) { - this.$http = $http; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.botanical = { - itemFk: this.$state.params.id + itemFk: this.$params.id }; } _getBotanical() { let filter = { - where: {itemFk: this.$state.params.id}, + where: {itemFk: this.$params.id}, include: [{relation: 'genus'}, {relation: 'specie'}] }; this.$http.get(`ItemBotanicals?filter=${JSON.stringify(filter)}`) @@ -26,8 +26,6 @@ class Controller { } } -Controller.$inject = ['$http', '$state']; - ngModule.component('vnItemBotanical', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index f4b6fa3c2..1cf79bbb3 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -3,19 +3,17 @@ import './index.js'; describe('ItemBotanical', () => { describe('Component vnItemBotanical', () => { let $httpBackend; - let $state; + let $scope; let controller; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - $state = { - params: { - id: 123 - } - }; - controller = $componentController('vnItemBotanical', {$state}); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemBotanical', {$element, $scope}); + controller.$params = {id: 123}; })); describe('_getBotanical()', () => { diff --git a/modules/item/front/create/index.js b/modules/item/front/create/index.js index 646baa8cd..ab51b0734 100644 --- a/modules/item/front/create/index.js +++ b/modules/item/front/create/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$ = $scope; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.item = { relevancy: 0 }; @@ -16,7 +16,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$state']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemCreate', { template: require('./index.html'), diff --git a/modules/item/front/create/index.spec.js b/modules/item/front/create/index.spec.js index cd5197305..518d5f78b 100644 --- a/modules/item/front/create/index.spec.js +++ b/modules/item/front/create/index.spec.js @@ -2,15 +2,13 @@ import './index.js'; describe('Item', () => { describe('Component vnItemCreate', () => { - let $componentController; let $scope; let $state; let controller; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { - $componentController = _$componentController_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_) => { $scope = $rootScope.$new(); $state = _$state_; $scope.watcher = { @@ -22,7 +20,8 @@ describe('Item', () => { }; } }; - controller = $componentController('vnItemCreate', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnItemCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/item/front/descriptor-popover/index.js b/modules/item/front/descriptor-popover/index.js index 42886fd58..c7a62baae 100644 --- a/modules/item/front/descriptor-popover/index.js +++ b/modules/item/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.item = null; this._quicklinks = {}; } @@ -68,7 +65,7 @@ class Controller extends Component { ); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemDescriptorPopover', { template: require('./index.html'), diff --git a/modules/item/front/descriptor-popover/index.spec.js b/modules/item/front/descriptor-popover/index.spec.js index eb09bf7d9..dfc673b0b 100644 --- a/modules/item/front/descriptor-popover/index.spec.js +++ b/modules/item/front/descriptor-popover/index.spec.js @@ -5,7 +5,6 @@ describe('Item', () => { let $httpBackend; let $scope; let controller; - let $element; let $timeout; beforeEach(ngModule('item')); @@ -13,10 +12,10 @@ describe('Item', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { $httpBackend = _$httpBackend_; $timeout = _$timeout_; - $element = angular.element(`
`); $scope = $rootScope.$new(); $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnItemDescriptorPopover', {$scope, $element}); + const $element = angular.element(''); + controller = $componentController('vnItemDescriptorPopover', {$element, $scope}); })); describe('itemFk()', () => { diff --git a/modules/item/front/descriptor-popover/style.scss b/modules/item/front/descriptor-popover/style.scss index 6c03a004e..219e68bae 100644 --- a/modules/item/front/descriptor-popover/style.scss +++ b/modules/item/front/descriptor-popover/style.scss @@ -1,5 +1,5 @@ body > .vn-popover vn-item-descriptor { display: block; - width: 16em; - min-height: 28em; + width: 256px; + min-height: 448px; } \ No newline at end of file diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index c4e66dfe3..e04fdb595 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -1,14 +1,10 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($state, $scope, $http, vnApp, $translate, vnConfig) { - this.$state = $state; - this.$scope = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; - this.vnConfig = vnConfig; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ {callback: this.showRegularizeDialog, name: 'Regularize stock'} ]; @@ -64,7 +60,7 @@ class Controller { } showRegularizeDialog() { - this.$scope.regularize.show(); + this.$.regularize.show(); } set quicklinks(value = {}) { @@ -94,7 +90,7 @@ class Controller { } } -Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemDescriptor', { template: require('./index.html'), diff --git a/modules/item/front/descriptor/style.scss b/modules/item/front/descriptor/style.scss index c4847bead..336bfdf53 100644 --- a/modules/item/front/descriptor/style.scss +++ b/modules/item/front/descriptor/style.scss @@ -3,6 +3,7 @@ vn-item-descriptor { display: block; img[ng-src] { + min-height: 16em; height: 100%; width: 100%; display: block; diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index 6d9f80641..e77ad1c2c 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -1,16 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $window, $translate, $stateParams) { - this.$scope = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $stateParams; - this.$window = $window; - this.$translate = $translate; - } - +class Controller extends Section { get item() { return this._item; } @@ -19,17 +11,17 @@ class Controller { this._item = value; this.filter = { - where: {itemFk: this.$stateParams.id} + where: {itemFk: this.$params.id} }; - this.$scope.$applyAsync(() => { - if (this.$stateParams.warehouseFk) - this.warehouseFk = this.$stateParams.warehouseFk; + this.$.$applyAsync(() => { + if (this.$params.warehouseFk) + this.warehouseFk = this.$params.warehouseFk; else if (value) this.warehouseFk = value.itemType.warehouseFk; - if (this.$stateParams.ticketFk) - this.ticketFk = this.$stateParams.ticketFk; + if (this.$params.ticketFk) + this.ticketFk = this.$params.ticketFk; }); } @@ -42,7 +34,7 @@ class Controller { }); this.filter.where.warehouseFk = value; - this.$scope.model.refresh(); + this.$.model.refresh(); } } @@ -51,27 +43,25 @@ class Controller { } get freeLineIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; let minDate = new Date(); minDate.setHours(0, 0, 0, 0); let maxDate = new Date(); maxDate.setHours(23, 59, 59, 59); - for (let i = 0; i < lines.length; i++) { const dated = new Date(lines[i].date); let isForFuture = dated > maxDate; let isForToday = (dated >= minDate && dated <= maxDate); - if (isForFuture || isForToday) return i; } } get onPreparationLineIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; for (let i = this.freeLineIndex; i >= 0; i--) { let line = lines[i]; @@ -87,7 +77,7 @@ class Controller { } get givenTicketIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; for (let i = lines.length - 1; i > 0; i--) { let line = lines[i]; @@ -102,15 +92,12 @@ class Controller { let selectedTicketLineIndex = this.givenTicketIndex; let lineIndex = this.onPreparationLineIndex; - let lines = body.querySelector('vn-tbody').children; if (lineIndex == undefined || !lines.length) return; - let onPreparationLine = lines[lineIndex]; - let balance = onPreparationLine.querySelector('.balanceSpan'); balance.classList.add('message'); balance.title = this.$translate.instant('Visible quantity'); @@ -150,9 +137,9 @@ class Controller { showDescriptor(event, sale) { if (!sale.isTicket) return; - this.$scope.descriptor.ticketFk = sale.origin; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.ticketFk = sale.origin; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); event.preventDefault(); } @@ -160,20 +147,18 @@ class Controller { showClientDescriptor(event, sale) { if (!sale.isTicket) return; - this.$scope.clientDescriptor.clientFk = sale.clientFk; - this.$scope.clientDescriptor.parent = event.target; - this.$scope.clientDescriptor.show(); + this.$.clientDescriptor.clientFk = sale.clientFk; + this.$.clientDescriptor.parent = event.target; + this.$.clientDescriptor.show(); event.preventDefault(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate', '$stateParams']; - ngModule.component('vnItemDiary', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/diary/index.spec.js b/modules/item/front/diary/index.spec.js index 9e7f0cf0c..94458a569 100644 --- a/modules/item/front/diary/index.spec.js +++ b/modules/item/front/diary/index.spec.js @@ -3,18 +3,17 @@ import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemDiary', () => { - let $stateParams; let $scope; let controller; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$stateParams_) => { - $stateParams = _$stateParams_; - $stateParams.id = 1; + beforeEach(angular.mock.inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); - controller = $componentController('vnItemDiary', {$scope, $stateParams}); - controller.$scope.model = crudModel; + const $element = angular.element(''); + controller = $componentController('vnItemDiary', {$element, $scope}); + controller.$.model = crudModel; + controller.$params = {id: 1}; })); describe('isToday()', () => { @@ -40,7 +39,7 @@ describe('Item', () => { let currentDate = new Date(); currentDate.setDate(currentDate.getDate() + 1); - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', alertLevel: 3, date: '2018-05-02'}, {name: 'My item 2', alertLevel: 1, date: '2018-05-03'}, {name: 'My item 3', alertLevel: 0, date: currentDate}] @@ -55,7 +54,7 @@ describe('Item', () => { it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => { let currentDate = new Date(); currentDate.setDate(currentDate.getDate() + 1); - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', alertLevel: 3, isPicked: true, date: currentDate}, {name: 'My item 3', alertLevel: 1, isPicked: true, date: currentDate}, {name: 'My item 4', alertLevel: 1, isPicked: false, date: currentDate}, @@ -69,10 +68,10 @@ describe('Item', () => { describe('set item()', () => { it('should set warehouseFk property based on itemType warehouseFk', () => { - jest.spyOn(controller.$scope, '$applyAsync'); + jest.spyOn(controller.$, '$applyAsync'); controller.item = {id: 1, itemType: {warehouseFk: 1}}; - expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); $scope.$apply(); expect(controller.warehouseFk).toEqual(1); @@ -80,11 +79,11 @@ describe('Item', () => { }); it(`should set warehouseFk property based on url query warehouseFk`, () => { - jest.spyOn(controller.$scope, '$applyAsync'); - controller.$stateParams.warehouseFk = 4; + jest.spyOn(controller.$, '$applyAsync'); + controller.$params.warehouseFk = 4; controller.item = {id: 1, itemType: {warehouseFk: 1}}; - expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); $scope.$apply(); expect(controller.warehouseFk).toEqual(4); @@ -94,7 +93,7 @@ describe('Item', () => { describe('givenTicketIndex() setter', () => { it(`should return the index position of the line of a given ticket fk`, () => { - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', origin: 1, alertLevel: 3, isPicked: true, date: '2018-05-02'}, {name: 'My item 3', origin: 2, alertLevel: 1, isPicked: true, date: '2018-05-03'}, {name: 'My item 4', origin: 3, alertLevel: 1, isPicked: false, date: '2018-05-03'}] @@ -103,7 +102,7 @@ describe('Item', () => { let index = controller.givenTicketIndex; - expect(controller.$scope.model.data[index].origin).toEqual(2); + expect(controller.$.model.data[index].origin).toEqual(2); }); }); }); diff --git a/modules/item/front/fetched-tags/index.js b/modules/item/front/fetched-tags/index.js index b88e853b4..9140abcf4 100644 --- a/modules/item/front/fetched-tags/index.js +++ b/modules/item/front/fetched-tags/index.js @@ -1,8 +1,10 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; import './style.scss'; ngModule.component('vnFetchedTags', { template: require('./index.html'), + controller: Component, bindings: { maxLength: '<', item: '<', diff --git a/modules/item/front/fetched-tags/style.scss b/modules/item/front/fetched-tags/style.scss index a15907232..393c17651 100644 --- a/modules/item/front/fetched-tags/style.scss +++ b/modules/item/front/fetched-tags/style.scss @@ -10,7 +10,7 @@ vn-fetched-tags { & > vn-one { overflow: hidden; text-overflow: ellipsis; - min-width: 5em; + min-width: 80px; } & > vn-one:nth-child(2) h3 { @@ -18,25 +18,25 @@ vn-fetched-tags { text-transform: uppercase; line-height: initial; text-align: center; - font-size: 1em + font-size: 1rem } & > vn-auto { display: flex; - padding-left: .4em; - min-width: 12em; + padding-left: 6px; + min-width: 192px; & > .inline-tag { display: inline-block; color: $color-font-secondary; - margin-left: .4em; + margin-left: 6px; text-align: center; - font-size: .8em; - height: 1.25em; - padding: .1em; - border-radius: .1em; - width: 4em; - min-width: 4em; + font-size: .75rem; + height: 20px; + padding: 1px; + border-radius: 1px; + width: 64px; + min-width: 64px; border: 1px solid $color-spacer; &.empty { @@ -48,7 +48,7 @@ vn-fetched-tags { flex-direction: column; & > vn-one { - padding-bottom: .2em + padding-bottom: 3px } & > vn-auto { white-space: initial; @@ -57,7 +57,7 @@ vn-fetched-tags { justify-content: center; & > .inline-tag { - margin: .1em; + margin: 1px; } } } diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 968c7b027..ad978e0aa 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -1,15 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http, $state, $scope, aclService) { - this.aclService = aclService; - this.$http = $http; - this.$state = $state; - this.$ = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.itemSelected = null; this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; - this.showFields = { id: false, actions: false @@ -33,7 +30,7 @@ class Controller { } showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; + if (event.defaltPrevented) return; event.preventDefault(); event.stopPropagation(); @@ -67,7 +64,8 @@ class Controller { this.$.preview.show(); } } -Controller.$inject = ['$http', '$state', '$scope', 'aclService']; + +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemIndex', { template: require('./index.html'), diff --git a/modules/item/front/index/index.spec.js b/modules/item/front/index/index.spec.js index aa8523b79..de07cd04d 100644 --- a/modules/item/front/index/index.spec.js +++ b/modules/item/front/index/index.spec.js @@ -2,16 +2,17 @@ import './index.js'; describe('Item', () => { describe('Component vnItemIndex', () => { - let $state; let controller; let $httpBackend; + let $scope; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { - $state = _$state_; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnItemIndex', {$state}); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemIndex', {$element, $scope}); })); describe('onCloneAccept()', () => { diff --git a/modules/item/front/index/style.scss b/modules/item/front/index/style.scss index 1cbc88124..c3d65349e 100644 --- a/modules/item/front/index/style.scss +++ b/modules/item/front/index/style.scss @@ -6,23 +6,23 @@ vn-item-product { .id { background-color: $color-main; color: $color-font-dark; - margin-bottom: 0em; + margin-bottom: 0; } .image { - height: 7em; - width: 7em; + height: 112px; + width: 112px; & > img { max-height: 100%; max-width: 100%; - border-radius: .2em; + border-radius: 3px; } } vn-label-value:first-of-type section{ - margin-top: 0.6em; + margin-top: 9px; } vn-fetched-tags vn-horizontal{ - margin-top: 0.9em; + margin-top: 14px; } } diff --git a/modules/item/front/last-entries/index.js b/modules/item/front/last-entries/index.js index 3ef89f086..752f1b035 100644 --- a/modules/item/front/last-entries/index.js +++ b/modules/item/front/last-entries/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); let defaultDate = new Date(); defaultDate.setDate(defaultDate.getDate() - 75); @@ -12,7 +12,7 @@ class Controller { this.filter = { where: { - itemFk: $stateParams.id, + itemFk: this.$params.id, date: defaultDate } }; @@ -25,7 +25,7 @@ class Controller { if (!value) return; this.filter.where.date = value; - this.$scope.model.refresh(); + this.$.model.refresh(); } get date() { @@ -33,7 +33,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemLastEntries', { template: require('./index.html'), diff --git a/modules/item/front/log/index.html b/modules/item/front/log/index.html index 3a6bb92ad..280a2b839 100644 --- a/modules/item/front/log/index.html +++ b/modules/item/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/item/front/log/index.js b/modules/item/front/log/index.js index 9253147c7..4433b2460 100644 --- a/modules/item/front/log/index.js +++ b/modules/item/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnItemLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/item/front/niche/index.html b/modules/item/front/niche/index.html index 70dabe671..572d81a2e 100644 --- a/modules/item/front/niche/index.html +++ b/modules/item/front/niche/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemNiches" fields="['id', 'itemFk', 'warehouseFk', 'code']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" data="niches" auto-load="true"> diff --git a/modules/item/front/niche/index.js b/modules/item/front/niche/index.js index 5d2442c58..f4e7cd0be 100644 --- a/modules/item/front/niche/index.js +++ b/modules/item/front/niche/index.js @@ -1,22 +1,16 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); }); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemNiche', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/request/index.html b/modules/item/front/request/index.html index 20da8946d..0516e7ff5 100644 --- a/modules/item/front/request/index.html +++ b/modules/item/front/request/index.html @@ -91,7 +91,7 @@ @@ -111,8 +111,9 @@ vn-id="itemDescriptor"> + vn-id="deny-dialog" + on-accept="$ctrl.onDenyAccept($data)" + on-close="$ctrl.onDenyClose()">
Specify the reasons to deny this request
diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 3684a1911..51035c468 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller extends Component { +export default class Controller extends Section { constructor($element, $) { super($element, $); @@ -33,7 +33,7 @@ export default class Controller extends Component { getState(isOk) { if (isOk === null) return 'Nueva'; - else if (isOk === -1 || isOk) + else if (isOk) return 'Aceptada'; else return 'Denegada'; @@ -102,25 +102,26 @@ export default class Controller extends Component { delete this.denyRequestId; } - denyRequest(response) { - if (response !== 'accept') return; - + onDenyAccept(request) { let params = { observation: this.denyObservation }; - let query = `TicketRequests/${this.selectedRequest.id}/deny`; - this.$http.post(query, params).then(res => { - const request = res.data; - this.selectedRequest.isOk = request.isOk; - this.selectedRequest.attenderFk = request.attenderFk; - this.selectedRequest.response = request.response; + let query = `TicketRequests/${request.id}/deny`; + return this.$http.post(query, params).then(res => { + const newRequest = res.data; + request.isOk = newRequest.isOk; + request.attenderFk = newRequest.attenderFk; + request.response = newRequest.response; this.vnApp.showSuccess(this.$t('Data saved!')); - this.denyObservation = null; }); } + onDenyClose() { + this.denyObservation = null; + } + showTicketDescriptor(event, ticketFk) { this.$.ticketDescriptor.ticketFk = ticketFk; this.$.ticketDescriptor.parent = event.target; diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index aaaade566..042b20996 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -4,7 +4,6 @@ import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemRequest', () => { let $scope; - let $element; let controller; let $httpBackend; @@ -15,7 +14,7 @@ describe('Item', () => { $scope = $rootScope.$new(); $scope.model = crudModel; $scope.denyReason = {hide: () => {}}; - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnItemRequest', {$element, $scope}); })); @@ -84,7 +83,6 @@ describe('Item', () => { let request = {saleFk: 1, saleQuantity: 1}; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond(); $httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond(); controller.changeQuantity(request); @@ -112,20 +110,20 @@ describe('Item', () => { }); }); - describe('denyRequest()', () => { - it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => { - jest.spyOn(controller.vnApp, 'showSuccess'); + describe('onDenyAccept()', () => { + it(`should deny the request`, () => { + const request = { + id: 1, + response: 'new' + }; - const request = {id: 1}; - const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'}; - controller.selectedRequest = request; + const url = `TicketRequests/:id/deny`; + $httpBackend.expectRoute('POST', url).respond({response: 'denied'}); - $httpBackend.when('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult); - $httpBackend.expect('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult); - controller.denyRequest('accept'); + controller.onDenyAccept(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(request.response).toBe('denied'); }); }); }); diff --git a/modules/item/front/summary/index.js b/modules/item/front/summary/index.js index 7e12abda0..d38f1f29a 100644 --- a/modules/item/front/summary/index.js +++ b/modules/item/front/summary/index.js @@ -1,11 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http) { - this.$http = $http; - } - +class Controller extends Section { getSummary() { this.$http.get(`Items/${this.item.id}/getSummary`).then(response => { this.summary = response.data; @@ -18,8 +15,6 @@ class Controller { } } -Controller.$inject = ['$http']; - ngModule.component('vnItemSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/summary/index.spec.js b/modules/item/front/summary/index.spec.js index 8058ece10..069c24512 100644 --- a/modules/item/front/summary/index.spec.js +++ b/modules/item/front/summary/index.spec.js @@ -4,12 +4,15 @@ describe('Item', () => { describe('Component summary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnItemSummary'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemSummary', {$element, $scope}); controller.item = {id: 1}; })); diff --git a/modules/item/front/summary/style.scss b/modules/item/front/summary/style.scss index bb7e5d227..7d5e3b609 100644 --- a/modules/item/front/summary/style.scss +++ b/modules/item/front/summary/style.scss @@ -7,12 +7,12 @@ vn-item-summary { } .item-state { - padding: .4em; + padding: 6px; background-color: $color-main; color: $color-font-dark; p { - font-size: .8em; + font-size: .75rem; text-align: center; margin: 0; @@ -21,7 +21,7 @@ vn-item-summary { line-height: 1; } &:last-child { - font-size: 1.5em; + font-size: 1.5rem; font-weight: bold; } } @@ -29,7 +29,7 @@ vn-item-summary { padding: 0; &:nth-child(1) { - border-right: .1em solid white; + border-right: 1px solid white; } } } \ No newline at end of file diff --git a/modules/item/front/tags/index.html b/modules/item/front/tags/index.html index 834d4c977..888efd8d0 100644 --- a/modules/item/front/tags/index.html +++ b/modules/item/front/tags/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemTags" fields="['id', 'itemFk', 'tagFk', 'value', 'priority']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" include="$ctrl.include" order="priority ASC" data="$ctrl.itemTags" diff --git a/modules/item/front/tags/index.js b/modules/item/front/tags/index.js index c12e1b9b5..8737aeed4 100644 --- a/modules/item/front/tags/index.js +++ b/modules/item/front/tags/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.include = { relation: 'tag', scope: { @@ -47,15 +47,15 @@ class Controller { } add() { - this.$scope.model.insert({ - itemFk: this.$stateParams.id, + this.$.model.insert({ + itemFk: this.$params.id, priority: this.getHighestPriority() }); } getHighestPriority() { let max = 0; - this.$scope.model.data.forEach(tag => { + this.$.model.data.forEach(tag => { if (tag.priority > max) max = tag.priority; }); @@ -63,17 +63,15 @@ class Controller { } onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.watcher.updateOriginalData(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); this.card.reload(); }); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemTags', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/tags/index.spec.js b/modules/item/front/tags/index.spec.js index a59f0b6e0..10128e4f0 100644 --- a/modules/item/front/tags/index.spec.js +++ b/modules/item/front/tags/index.spec.js @@ -12,7 +12,8 @@ describe('Item', () => { $scope = $rootScope.$new(); $scope.model = crudModel; $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; - controller = $componentController('vnItemTags', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); })); describe('itemTags setter', () => { diff --git a/modules/item/front/tax/index.js b/modules/item/front/tax/index.js index e0c2428de..251e0802d 100644 --- a/modules/item/front/tax/index.js +++ b/modules/item/front/tax/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $http, $translate, $scope) { - this.$ = $scope; - this.$http = $http; - this.$stateParams = $stateParams; - this._ = $translate; - } - +export default class Controller extends Section { $onInit() { this.getTaxes(); } @@ -21,7 +15,7 @@ export default class Controller { }] }; - let url = `Items/${this.$stateParams.id}/taxes`; + let url = `Items/${this.$params.id}/taxes`; this.$http.get(url, {params: {filter}}).then(json => { this.taxes = json.data; }); @@ -41,8 +35,6 @@ export default class Controller { } } -Controller.$inject = ['$stateParams', '$http', '$translate', '$scope']; - ngModule.component('vnItemTax', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/waste/index.js b/modules/item/front/waste/index.js index 9344c2222..d1a10fbf4 100644 --- a/modules/item/front/waste/index.js +++ b/modules/item/front/waste/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; ngModule.component('vnItemWaste', { template: require('./index.html'), - controller: Component + controller: Section }); diff --git a/modules/item/front/waste/style.scss b/modules/item/front/waste/style.scss index 59e9a3b68..55a6eb2ef 100644 --- a/modules/item/front/waste/style.scss +++ b/modules/item/front/waste/style.scss @@ -4,14 +4,14 @@ vn-item-waste { .header { margin-bottom: 16px; text-transform: uppercase; - font-size: 15pt; + font-size: 1.25rem; line-height: 1; padding: 7px; padding-bottom: 7px; padding-bottom: 4px; font-weight: lighter; background-color: #fde6ca; - border-bottom: 0.1em solid #f7931e; + border-bottom: 1px solid #f7931e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; @@ -19,7 +19,7 @@ vn-item-waste { vn-table vn-th.waste-family, vn-table vn-td.waste-family { - max-width: 4em; - width: 4em + max-width: 64px; + width: 64px } } \ No newline at end of file diff --git a/modules/order/front/basic-data/index.js b/modules/order/front/basic-data/index.js index 81aef8304..d1f1fc225 100644 --- a/modules/order/front/basic-data/index.js +++ b/modules/order/front/basic-data/index.js @@ -1,18 +1,20 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope) { +class Controller extends Section { + constructor($element, $) { + super($element, $); let isDirty = false; - $scope.$watch('$ctrl.selection', newValue => { + this.$.$watch('$ctrl.selection', newValue => { if (newValue) { - $scope.addressModel.where = {clientFk: newValue.id}; - $scope.addressModel.refresh(); + this.$.addressModel.where = {clientFk: newValue.id}; + this.$.addressModel.refresh(); if (isDirty) this.order.addressFk = newValue.defaultAddressFk; isDirty = true; } else { - $scope.addressModel.clear(); + this.$.addressModel.clear(); if (isDirty) this.order.addressFk = null; } @@ -20,8 +22,6 @@ class Controller { } } -Controller.$inject = ['$scope']; - ngModule.component('vnOrderBasicData', { controller: Controller, template: require('./index.html'), diff --git a/modules/order/front/card/index.js b/modules/order/front/card/index.js index e79167761..80fa99d1d 100644 --- a/modules/order/front/card/index.js +++ b/modules/order/front/card/index.js @@ -47,7 +47,7 @@ class Controller extends ModuleCard { ] }; - this.$q.all([ + return this.$q.all([ this.$http.get(`Orders/${this.$params.id}`, {filter}) .then(res => this.order = res.data), this.$http.get(`Orders/${this.$params.id}/getTotal`) diff --git a/modules/order/front/catalog-view/index.js b/modules/order/front/catalog-view/index.js index fe1f1c712..838da05ea 100644 --- a/modules/order/front/catalog-view/index.js +++ b/modules/order/front/catalog-view/index.js @@ -2,7 +2,6 @@ import ngModule from '../module'; import Component from 'core/lib/component'; import './style.scss'; - class Controller extends Component { preview(event, item) { event.preventDefault(); diff --git a/modules/order/front/catalog-view/style.scss b/modules/order/front/catalog-view/style.scss index 18dc51bb0..aa4e301a9 100644 --- a/modules/order/front/catalog-view/style.scss +++ b/modules/order/front/catalog-view/style.scss @@ -15,7 +15,7 @@ vn-order-catalog { } } & > vn-auto { - width: 28em; + width: 448px; display: flex; overflow: hidden; diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 7131d6a6e..f9c2c40bd 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -7,10 +7,17 @@ + + + + @@ -77,14 +84,6 @@
- - - - - - Id: {{$ctrl.itemId}} + + Name + : {{$ctrl.itemName}} + { - if (this.$stateParams.itemId) - this.itemId = parseInt(this.$stateParams.itemId); + if (this.$params.categoryId) + this.categoryId = parseInt(this.$params.categoryId); - if (this.$stateParams.categoryId) - this.categoryId = parseInt(this.$stateParams.categoryId); + if (this.$params.typeId) + this.typeId = parseInt(this.$params.typeId); - if (this.$stateParams.typeId) - this.typeId = parseInt(this.$stateParams.typeId); - - if (this.$stateParams.tags) - this.tags = JSON.parse(this.$stateParams.tags); + if (this.$params.tags) + this.tags = JSON.parse(this.$params.tags); }); } @@ -115,17 +108,6 @@ class Controller { this.applyFilters(); } - get itemId() { - return this._itemId; - } - - set itemId(value) { - this._itemId = value; - - this.updateStateParams(); - this.applyFilters(); - } - get tags() { return this._tags; } @@ -199,18 +181,6 @@ class Controller { this.itemTypes = res.data); } - /** - * Search by item id filter - * @param {object} event - */ - onSearchById(event) { - const value = this.$.itemId.value; - if (event.key === 'Enter' && value) { - this.itemId = value; - this.$.itemId.value = null; - } - } - /** * Search by tag value * @param {object} event @@ -234,9 +204,19 @@ class Controller { this.applyFilters(); } - applyFilters() { + removeItemId() { + this.itemId = null; + this.applyFilters(); + } + + removeItemName() { + this.itemName = null; + this.applyFilters(); + } + + applyFilters(filter = {}) { let newParams = {}; - let newFilter = {}; + let newFilter = Object.assign({}, filter); const model = this.$.model; if (this.categoryId) @@ -245,16 +225,13 @@ class Controller { if (this.typeId) newFilter.typeFk = this.typeId; - if (this.itemId) - newFilter = {'i.id': this.itemId}; - newParams = { - orderFk: this.order.id, + orderFk: this.$params.id, orderBy: this.getOrderBy(), tags: this.tags, }; - model.applyFilter({where: newFilter}, newParams); + return model.applyFilter({where: newFilter}, newParams); } openPanel(event) { @@ -286,10 +263,6 @@ class Controller { if (this.typeId) params.typeId = this.typeId; - params.itemId = undefined; - if (this.itemId) - params.itemId = this.itemId; - params.tags = undefined; if (this.tags.length) { const tags = []; @@ -348,9 +321,28 @@ class Controller { newFilterList = newFilterList.concat(tags); this.orderFields = newFilterList; } -} -Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions']; + onSearch(params) { + if (!params) return; + + this.itemId = null; + this.itemName = null; + + if (params.search) { + if (/^\d+$/.test(params.search)) { + this.itemId = params.search; + return this.applyFilters({ + 'i.id': params.search + }); + } else { + this.itemName = params.search; + return this.applyFilters({ + 'i.name': {like: `%${params.search}%`} + }); + } + } else return this.applyFilters(); + } +} ngModule.component('vnOrderCatalog', { template: require('./index.html'), diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index e2d2d0aff..f7635665a 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -17,11 +17,15 @@ describe('Order', () => { $scope.search = {}; $scope.itemId = {}; $state = _$state_; - $state.params.categoryId = 1; - $state.params.typeId = 2; $state.current.name = 'my.current.state'; - controller = $componentController('vnOrderCatalog', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnOrderCatalog', {$element, $scope}); controller._order = {id: 4}; + controller.$params = { + categoryId: 1, + typeId: 2, + id: 4 + }; })); describe('order() setter', () => { @@ -111,18 +115,6 @@ describe('Order', () => { }); }); - describe('itemId() setter', () => { - it(`should set itemId property and then call updateStateParams() and applyFilters() methods`, () => { - jest.spyOn(controller, 'updateStateParams'); - jest.spyOn(controller, 'applyFilters'); - - controller.itemId = 1; - - expect(controller.updateStateParams).toHaveBeenCalledWith(); - expect(controller.applyFilters).toHaveBeenCalledWith(); - }); - }); - describe('tags() setter', () => { it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => { jest.spyOn(controller, 'updateStateParams'); @@ -157,23 +149,27 @@ describe('Order', () => { }); }); - describe('onSearchById()', () => { - it(`should not filter by id if the event key code doesn't equals to 'Enter'`, () => { + describe('onSearch()', () => { + it(`should apply a filter by item id an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Tab'}); + const itemId = 1; + controller.onSearch({search: itemId}); - expect(controller.applyFilters).not.toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.id': itemId + }); }); - it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => { + it(`should apply a filter by item name an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Enter'}); + const itemName = 'Bow'; + controller.onSearch({search: itemName}); - expect(controller.applyFilters).toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.name': {like: `%${itemName}%`} + }); }); }); @@ -223,7 +219,6 @@ describe('Order', () => { controller._categoryId = 2; controller._typeId = 4; - controller._itemId = 1; controller._tags = [ {tagFk: 11, value: 'Precission', tagSelection: {name: 'Category'}} ]; @@ -231,7 +226,7 @@ describe('Order', () => { value: 'Precission', tagFk: 11, tagSelection: {name: 'Category'}} ]); - let result = {categoryId: 2, typeId: 4, itemId: 1, tags: tags}; + let result = {categoryId: 2, typeId: 4, tags: tags}; controller.updateStateParams(); expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result); diff --git a/modules/order/front/catalog/locale/es.yml b/modules/order/front/catalog/locale/es.yml new file mode 100644 index 000000000..27d16fe2d --- /dev/null +++ b/modules/order/front/catalog/locale/es.yml @@ -0,0 +1,2 @@ +Name: Nombre +Search by item id or name: Buscar por id de artículo o nombre \ No newline at end of file diff --git a/modules/order/front/catalog/style.scss b/modules/order/front/catalog/style.scss index 308acb6b2..9ffe81dfb 100644 --- a/modules/order/front/catalog/style.scss +++ b/modules/order/front/catalog/style.scss @@ -34,9 +34,9 @@ vn-order-catalog vn-side-menu div { color: #FFF } & > i:before { - font-size: 32pt; - width: 1em; - height: 1em; + font-size: 2.6rem; + width: 16px; + height: 16px; } } } @@ -49,6 +49,6 @@ vn-order-catalog vn-side-menu div { max-width: 100%; } vn-autocomplete[vn-id="type"] .list { - max-height: 20em + max-height: 320px } } \ No newline at end of file diff --git a/modules/order/front/create/card.js b/modules/order/front/create/card.js index 7f1bb6133..158ad9a10 100644 --- a/modules/order/front/create/card.js +++ b/modules/order/front/create/card.js @@ -1,19 +1,16 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, vnApp, $translate, $state, $stateParams) { - this.$stateParams = $stateParams; - this.$http = $http; - this.translate = $translate; - this.vnApp = vnApp; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.order = {}; - this.$state = $state; - this.clientFk = $stateParams.clientFk; + this.clientFk = this.$params.clientFk; } $onInit() { - if (this.$stateParams && this.$stateParams.clientFk) - this.clientFk = this.$stateParams.clientFk; + if (this.$params && this.$params.clientFk) + this.clientFk = this.$params.clientFk; } set order(value) { @@ -102,14 +99,12 @@ class Controller { agencyModeId: this.order.agencyModeFk }; this.$http.post(`Orders/new`, params).then(res => { - this.vnApp.showSuccess(this.translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$state.go('order.card.catalog', {id: res.data}); }); } } -Controller.$inject = ['$http', 'vnApp', '$translate', '$state', '$stateParams']; - ngModule.component('vnOrderCreateCard', { template: require('./card.html'), controller: Controller, diff --git a/modules/order/front/create/card.spec.js b/modules/order/front/create/card.spec.js index ef2bba529..f8f0653a7 100644 --- a/modules/order/front/create/card.spec.js +++ b/modules/order/front/create/card.spec.js @@ -4,12 +4,15 @@ describe('Order', () => { describe('Component vnOrderCreateCard', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _vnApp_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _vnApp_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderCreateCard'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnOrderCreateCard', {$element, $scope}); controller.item = {id: 3}; })); diff --git a/modules/order/front/create/index.js b/modules/order/front/create/index.js index 9c8d7ce6b..5c02e8225 100644 --- a/modules/order/front/create/index.js +++ b/modules/order/front/create/index.js @@ -1,18 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - } - +class Controller extends Section { async onSubmit() { let newOrderID = await this.$.card.createOrder(); this.$state.go('order.card.summary', {id: newOrderID}); } } -Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnOrderCreate', { template: require('./index.html'), diff --git a/modules/order/front/create/index.spec.js b/modules/order/front/create/index.spec.js index 80a8341ec..82834a987 100644 --- a/modules/order/front/create/index.spec.js +++ b/modules/order/front/create/index.spec.js @@ -10,7 +10,8 @@ describe('Order', () => { beforeEach(angular.mock.inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); $scope.card = {createOrder: () => {}}; - controller = $componentController('vnOrderCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnOrderCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index 0d8a1e14a..b9d1e7973 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -1,12 +1,9 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($translate, $scope, vnApp, $http, $state) { - this.$state = $state; - this.$scope = $scope; - this.vnApp = vnApp; - this.$http = $http; - this.$translate = $translate; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ {name: 'Delete order', callback: () => this.showDeleteOrderDialog()} ]; @@ -55,12 +52,10 @@ class Controller { } showDeleteOrderDialog() { - this.$scope.deleteOrderConfirmation.show(); + this.$.deleteOrderConfirmation.show(); } } -Controller.$inject = ['$translate', '$scope', 'vnApp', '$http', '$state']; - ngModule.component('vnOrderDescriptor', { template: require('./index.html'), bindings: { diff --git a/modules/order/front/descriptor/index.spec.js b/modules/order/front/descriptor/index.spec.js index 924ea4a97..5bb2ac087 100644 --- a/modules/order/front/descriptor/index.spec.js +++ b/modules/order/front/descriptor/index.spec.js @@ -2,13 +2,16 @@ import './index.js'; describe('Order Component vnOrderDescriptor', () => { let $httpBackend; + let $scope; let controller; - beforeEach(ngModule('order')); + beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderDescriptor'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnOrderDescriptor', {$element, $scope}); controller.order = {id: 1}; })); diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index 10940eb27..99f00733e 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state, $stateParams) { - this.$stateParams = $stateParams; - this.$state = $state; - this.$ = $scope; - this.ticketSelected = null; - } - +export default class Controller extends Section { showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; @@ -36,8 +30,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$stateParams']; - ngModule.component('vnOrderIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/order/front/line/index.js b/modules/order/front/line/index.js index 149251c87..9351c5df8 100644 --- a/modules/order/front/line/index.js +++ b/modules/order/front/line/index.js @@ -43,10 +43,9 @@ class Controller extends Section { rows: [row.id], actualOrderId: this.$params.id }; - return this.$http.post(`OrderRows/removes`, params).then(() => { - this.card.reload(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + return this.$http.post(`OrderRows/removes`, params) + .then(() => this.card.reload()) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } showDescriptor(event, itemFk) { diff --git a/modules/order/front/prices-popover/index.js b/modules/order/front/prices-popover/index.js index b732f2090..307cbc8d6 100644 --- a/modules/order/front/prices-popover/index.js +++ b/modules/order/front/prices-popover/index.js @@ -103,7 +103,6 @@ class Controller extends Component { return; } - let params = { orderFk: this.order.id, items: filledLines diff --git a/modules/order/front/prices-popover/style.scss b/modules/order/front/prices-popover/style.scss index 150c2296a..edd2d1513 100644 --- a/modules/order/front/prices-popover/style.scss +++ b/modules/order/front/prices-popover/style.scss @@ -14,15 +14,15 @@ .prices { vn-table { .warehouse { - width: 3em; - max-width: 3em; + width: 48px; + max-width: 48px; } .price-kg { color: $color-font-secondary; - font-size: .8em + font-size: .75rem } .vn-input-number { - width: 3.5em; + width: 56px; } } .footer { diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index b607aef9d..eec628b89 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?categoryId&typeId&itemId&tags", + "url": "/catalog?q&categoryId&typeId&tags", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog", diff --git a/modules/order/front/summary/index.js b/modules/order/front/summary/index.js index 42b71d90e..ca6c29522 100644 --- a/modules/order/front/summary/index.js +++ b/modules/order/front/summary/index.js @@ -1,14 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state) { - this.$scope = $scope; - this.$http = $http; - this.$state = $state; - this.order = {}; - } - +class Controller extends Section { setSummary() { this.$http.get(`Orders/${this.order.id}/summary`).then(res => { if (res && res.data) @@ -17,7 +11,7 @@ class Controller { } get formattedAddress() { - if (!this.summary) return; + if (!this.summary) return null; let address = this.summary.address; let province = address.province ? `(${address.province.name})` : ''; @@ -31,18 +25,16 @@ class Controller { } showDescriptor(event, itemFk) { - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$state']; - ngModule.component('vnOrderSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/order/front/summary/index.spec.js b/modules/order/front/summary/index.spec.js index f693db35d..2fa7c1c93 100644 --- a/modules/order/front/summary/index.spec.js +++ b/modules/order/front/summary/index.spec.js @@ -9,7 +9,8 @@ describe('Order', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderSummary'); + const $element = angular.element(''); + controller = $componentController('vnOrderSummary', {$element}); controller.order = {id: 1}; })); diff --git a/modules/order/front/summary/style.scss b/modules/order/front/summary/style.scss index c225b4b49..a0ed56d42 100644 --- a/modules/order/front/summary/style.scss +++ b/modules/order/front/summary/style.scss @@ -4,16 +4,16 @@ vn-order-summary .summary{ max-width: $width-lg; & > div > vn-horizontal > vn-one { - min-width: 10em !important; + min-width: 160px !important; &.taxes { border: $border-thin-light; text-align: right; - padding: .5em !important; + padding: 8px !important; & > p { - font-size: 1.2em; - margin: .2em; + font-size: 1.2rem; + margin: 3px; } } } diff --git a/modules/order/front/volume/index.html b/modules/order/front/volume/index.html index 9dc1b811f..36451f517 100644 --- a/modules/order/front/volume/index.html +++ b/modules/order/front/volume/index.html @@ -3,12 +3,12 @@ vn-id="model" url="OrderRows" filter="::$ctrl.filter" - link="{orderFk: $ctrl.$stateParams.id}" + link="{orderFk: $ctrl.$params.id}" limit="20" data="rows" on-data-change="$ctrl.onDataChange()"> - + { - if (response.data) - this.$scope.model.data.forEach(order => { + if (response.data) { + this.$.model.data.forEach(order => { response.data.volumes.forEach(volume => { if (order.itemFk === volume.itemFk) order.volume = volume.volume; }); }); + } }); } showDescriptor(event, itemFk) { - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$stateParams']; - ngModule.component('vnOrderVolume', { template: require('./index.html'), controller: Controller, diff --git a/modules/order/front/volume/index.spec.js b/modules/order/front/volume/index.spec.js index c5fe0f2cf..194592406 100644 --- a/modules/order/front/volume/index.spec.js +++ b/modules/order/front/volume/index.spec.js @@ -21,7 +21,8 @@ describe('Order', () => { $scope.popover = {relocate: () => {}}; $state = _$state_; $state.params.id = 1; - controller = $componentController('vnOrderVolume', {$scope}, {$httpBackend}, {$state}); + const $element = angular.element(''); + controller = $componentController('vnOrderVolume', {$element, $scope}); })); it('should join the sale volumes to its respective sale', () => { @@ -31,29 +32,29 @@ describe('Order', () => { controller.onDataChange(); $httpBackend.flush(); - expect(controller.$scope.model.data[0].volume).toBe(0.008); - expect(controller.$scope.model.data[1].volume).toBe(0.003); + expect(controller.$.model.data[0].volume).toBe(0.008); + expect(controller.$.model.data[1].volume).toBe(0.003); }); describe('showDescriptor()', () => { it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => { let event = {target: 1}; let itemFk = 1; - jest.spyOn(controller.$scope.descriptor, 'show'); + jest.spyOn(controller.$.descriptor, 'show'); controller.showDescriptor(event, itemFk); - expect(controller.$scope.descriptor.itemFk).toBe(1); - expect(controller.$scope.descriptor.parent).toBe(1); - expect(controller.$scope.descriptor.show).toHaveBeenCalledWith(); + expect(controller.$.descriptor.itemFk).toBe(1); + expect(controller.$.descriptor.parent).toBe(1); + expect(controller.$.descriptor.show).toHaveBeenCalledWith(); }); }); describe('onDescriptorLoad()', () => { it('should call $scope.popover.relocate()', () => { - jest.spyOn(controller.$scope.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); controller.onDescriptorLoad(); - expect(controller.$scope.popover.relocate).toHaveBeenCalledWith(); + expect(controller.$.popover.relocate).toHaveBeenCalledWith(); }); }); }); diff --git a/modules/route/front/basic-data/index.js b/modules/route/front/basic-data/index.js index d4a481dc5..cced46f55 100644 --- a/modules/route/front/basic-data/index.js +++ b/modules/route/front/basic-data/index.js @@ -1,19 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, vnApp, $translate) { - this.$ = $scope; - this.vnApp = vnApp; - this.$translate = $translate; - } - +class Controller extends Section { onSubmit() { - this.$.watcher.submit().then(() => { - this.card.reload(); - }); + this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope', 'vnApp', '$translate']; ngModule.component('vnRouteBasicData', { template: require('./index.html'), diff --git a/modules/route/front/create/index.js b/modules/route/front/create/index.js index 03fe574fc..703ecb49a 100644 --- a/modules/route/front/create/index.js +++ b/modules/route/front/create/index.js @@ -1,18 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.submit().then( + this.$.watcher.submit().then( res => this.$state.go('route.card.summary', {id: res.data.id}) ); } } -Controller.$inject = ['$scope', '$state']; ngModule.component('vnRouteCreate', { template: require('./index.html'), diff --git a/modules/route/front/descriptor-popover/index.js b/modules/route/front/descriptor-popover/index.js index 7d5cd3d91..a0363839f 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.route = null; this._quicklinks = {}; } @@ -118,7 +115,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnRouteDescriptorPopover', { template: require('./index.html'), diff --git a/modules/route/front/descriptor-popover/style.scss b/modules/route/front/descriptor-popover/style.scss index 0c84ff2fe..163a032e3 100644 --- a/modules/route/front/descriptor-popover/style.scss +++ b/modules/route/front/descriptor-popover/style.scss @@ -1,7 +1,7 @@ vn-route-descriptor-popover { vn-route-descriptor { display: block; - width: 16em; + width: 256px; & > vn-card{ margin: 0!important; } diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index 51ca23a92..558d236b7 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -2,8 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $httpParamSerializer) { - super($element, $scope); + constructor($element, $, $httpParamSerializer) { + super($element, $); this.$httpParamSerializer = $httpParamSerializer; this.moreOptions = [ diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 735581265..0349af293 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnToken) { - this.$ = $scope; - this.accessToken = vnToken.token; - } - +export default class Controller extends Section { showWorkerDescriptor(event, workerFk) { if (event.defaultPrevented) return; event.preventDefault(); @@ -25,7 +21,6 @@ export default class Controller { this.$.summary.show(); } } -Controller.$inject = ['$scope', 'vnToken']; ngModule.component('vnRouteIndex', { template: require('./index.html'), diff --git a/modules/route/front/log/index.html b/modules/route/front/log/index.html index 6a6adf250..7df2e30ae 100644 --- a/modules/route/front/log/index.html +++ b/modules/route/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/log/index.js b/modules/route/front/log/index.js index ff0a2a9d1..b7d456b23 100644 --- a/modules/route/front/log/index.js +++ b/modules/route/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnRouteLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/route/front/summary/index.js b/modules/route/front/summary/index.js index b1d42e6f1..a922ad008 100644 --- a/modules/route/front/summary/index.js +++ b/modules/route/front/summary/index.js @@ -1,12 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http) { - this.$http = $http; - this.$ = $scope; - } - +class Controller extends Section { set route(value) { this._route = value; if (value && value.id) @@ -47,8 +43,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http']; - ngModule.component('vnRouteSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/route/front/summary/index.spec.js b/modules/route/front/summary/index.spec.js index 0dfc016b4..99c029394 100644 --- a/modules/route/front/summary/index.spec.js +++ b/modules/route/front/summary/index.spec.js @@ -9,7 +9,8 @@ describe('Route', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnRouteSummary'); + const $element = angular.element(''); + controller = $componentController('vnRouteSummary', {$element}); controller.route = {id: 1}; })); diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index f36330235..556ad0b6c 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -3,12 +3,6 @@ import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { - constructor($element, $scope, $filter) { - super($element, $scope); - - this.$filter = $filter; - } - get route() { return this._route; } @@ -200,8 +194,6 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', '$filter']; - ngModule.component('vnRouteTickets', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 4979f4819..c1cbda799 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -3,6 +3,10 @@ module.exports = Self => { Self.remoteMethodCtx('editableStates', { description: 'Gets the editable states according the user role ', accessType: 'READ', + accepts: { + arg: 'filter', + type: 'object' + }, returns: { type: ['Object'], root: true @@ -13,10 +17,10 @@ module.exports = Self => { } }); - Self.editableStates = async ctx => { + Self.editableStates = async(ctx, filter) => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let statesList = await models.State.find(); + let statesList = await models.State.find({where: filter.where}); let isProduction = await models.Account.hasRole(userId, 'production'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); diff --git a/modules/ticket/back/methods/state/specs/editableState.spec.js b/modules/ticket/back/methods/state/specs/editableState.spec.js index 54dbdfcae..03cb7616c 100644 --- a/modules/ticket/back/methods/state/specs/editableState.spec.js +++ b/modules/ticket/back/methods/state/specs/editableState.spec.js @@ -1,10 +1,12 @@ const app = require('vn-loopback/server/server'); describe('ticket editableStates()', () => { + const filter = {where: {name: {like: '%%'}}}; it('should return the expected state for the given role', async() => { const productionRole = 49; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); expect(deliveredState).toBeTruthy(); @@ -13,7 +15,7 @@ describe('ticket editableStates()', () => { it(`should returns the expected states by a specific role`, async() => { const productionRole = 18; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); @@ -24,7 +26,7 @@ describe('ticket editableStates()', () => { it(`should return again the expected state by a specific role`, async() => { const employeeRole = 1; const ctx = {req: {accessToken: {userId: employeeRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); expect(pickerDesignedState).toBeFalsy(); diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index 925dcdfac..77f8ecc57 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -51,16 +51,14 @@ module.exports = Self => { stmt = new ParameterizedSQL( `SELECT t.id AS ticketFk, c.id AS clientFk, c.name AS clientName, tw.weekDay, - wh.name AS warehouseName, w.id AS workerFk, u.nickName + wh.name AS warehouseName, u.id AS workerFk, u.nickName, tw.agencyModeFk FROM ticketWeekly tw JOIN ticket t ON t.id = tw.ticketFk JOIN client c ON c.id = t.clientFk - JOIN worker w ON w.id = c.salesPersonFk - JOIN account.user u ON u.id = w.userFk + JOIN account.user u ON u.id = c.salesPersonFk JOIN warehouse wh ON wh.id = t.warehouseFk` ); - stmt.merge(conn.makeSuffix(filter)); let itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/ticket/back/methods/ticket/deleteStowaway.js b/modules/ticket/back/methods/ticket/deleteStowaway.js index 6f3a1760f..cf9626c14 100644 --- a/modules/ticket/back/methods/ticket/deleteStowaway.js +++ b/modules/ticket/back/methods/ticket/deleteStowaway.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethod('deleteStowaway', { + Self.remoteMethodCtx('deleteStowaway', { description: 'Deletes an stowaway', accessType: 'WRITE', accepts: [{ @@ -19,21 +19,66 @@ module.exports = Self => { } }); - Self.deleteStowaway = async id => { + Self.deleteStowaway = async(ctx, id) => { + const models = Self.app.models; + const $t = ctx.req.__; // $translate const ticket = await Self.findById(id, { include: [{ relation: 'ship' }, { relation: 'stowaway' + }, { + relation: 'client', + scope: { + include: { + relation: 'salesPerson' + } + } }] }); - let params; - if (ticket.stowaway()) - params = [ticket.stowaway().shipFk, ticket.stowaway().id]; - else if (ticket.ship()) - params = [ticket.ship().shipFk, ticket.ship().id]; + let stowawayFk; + let shipFk; + if (ticket.stowaway()) { + shipFk = ticket.stowaway().shipFk; + stowawayFk = ticket.stowaway().id; + } else if (ticket.ship()) { + shipFk = ticket.ship().shipFk; + stowawayFk = ticket.ship().id; + } - return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params); + const stowaway = await models.Stowaway.findOne({ + where: { + id: stowawayFk, + shipFk: shipFk + } + }); + const result = await stowaway.destroy(); + + const state = await models.State.findOne({ + where: { + code: 'BOARDING' + } + }); + const ticketTracking = await models.TicketTracking.findOne({ + where: { + ticketFk: shipFk, + stateFk: state.id + } + }); + + await ticketTracking.destroy(); + + const salesPerson = ticket.client().salesPerson(); + if (salesPerson) { + const origin = ctx.req.headers.origin; + const message = $t('This ticket is not an stowaway anymore', { + ticketId: stowawayFk, + ticketUrl: `${origin}/#!/ticket/${stowawayFk}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + } + + return result; }; }; diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 6daad7c39..0f7e0b57f 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -23,6 +23,7 @@ module.exports = Self => { Self.setDeleted = async(ctx, id) => { const models = Self.app.models; + const userId = ctx.req.accessToken.userId; const isEditable = await Self.isEditable(ctx, id); const $t = ctx.req.__; // $translate @@ -30,16 +31,30 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); // Check if has sales with shelving + const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); const sales = await models.Sale.find({ - include: {relation: 'itemShelving'}, + include: {relation: 'itemShelvingSale'}, where: {ticketFk: id} }); const hasItemShelvingSales = sales.some(sale => { - return sale.itemShelving(); + return sale.itemShelvingSale(); }); - if (hasItemShelvingSales) + + if (hasItemShelvingSales && !isSalesAssistant) throw new UserError(`You cannot delete a ticket that part of it is being prepared`); + if (hasItemShelvingSales && isSalesAssistant) { + const promises = []; + for (let sale of sales) { + if (sale.itemShelvingSale()) { + const itemShelvingSale = sale.itemShelvingSale(); + const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id); + promises.push(destroyedShelving); + } + } + await Promise.all(promises); + } + // Check for existing claim const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}}); if (claimOfATicket) diff --git a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js index 3c8097e37..bd6fd327a 100644 --- a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js +++ b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js @@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server'); describe('ticket deleteStowaway()', () => { const shipId = 16; const stowawayId = 17; + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + afterAll(async() => { + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']); + }); it('should create an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) `, [stowawayId, shipId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(1); }); + it('should confirm that the ship ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('Embarcando'); + }); + it('should delete the stowaway from the ship ticket', async() => { - await app.models.Ticket.deleteStowaway(shipId); + await app.models.Ticket.deleteStowaway(ctx, shipId); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(0); }); + it('should confirm that the ship ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('OK'); + }); + it('should create again an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) - `, [stowawayId, shipId]); + `, [shipId, stowawayId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(1); }); - it('should delete the stowaway from the stowaway ticket', async() => { - await app.models.Ticket.deleteStowaway(stowawayId); + it('should confirm that the stowaway ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + expect(shipState.name).toEqual('Embarcando'); + }); + + it('should delete the stowaway from the stowaway ticket', async() => { + await app.models.Ticket.deleteStowaway(ctx, stowawayId); + + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(0); }); + + it('should confirm that the stowaway ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); + + expect(shipState.name).toEqual('OK'); + }); }); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 890fc6c45..2713bd700 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,29 +1,33 @@ const app = require('vn-loopback/server/server'); +const models = app.models; describe('ticket deleted()', () => { let ticket; - let ctx; + let sale; beforeAll(async done => { - let originalTicket = await app.models.Ticket.findOne({where: {id: 16}}); + let originalTicket = await models.Ticket.findOne({where: {id: 16}}); originalTicket.id = null; - ticket = await app.models.Ticket.create(originalTicket); + ticket = await models.Ticket.create(originalTicket); + sale = await models.Sale.create({ + ticketFk: ticket.id, + itemFk: 4, + concept: 'Melee weapon', + quantity: 10 + }); - ctx = { - req: { - accessToken: {userId: 106}, - headers: { - origin: 'http://localhost:5000' - }, - __: () => {} - } - }; + await models.ItemShelvingSale.create({ + itemShelvingFk: 1, + saleFk: sale.id, + quantity: 10, + userFk: 106 + }); done(); }); afterAll(async done => { - await app.models.Ticket.destroyById(ticket.id); + await models.Ticket.destroyById(ticket.id); done(); }); @@ -32,16 +36,62 @@ describe('ticket deleted()', () => { expect(ticket.isDeleted).toEqual(false); }); - it('should set a ticket to deleted', async() => { + it('should make sure the ticket sale has an item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(true); + }); + + it('should set a ticket to deleted and remove all item shelvings', async() => { + const salesAssistantId = 21; + const ctx = { + req: { + accessToken: {userId: salesAssistantId}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; await app.models.Ticket.setDeleted(ctx, ticket.id); - let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']}); + let deletedTicket = await app.models.Ticket.findOne({ + where: {id: ticket.id}, + fields: ['isDeleted'] + }); expect(deletedTicket.isDeleted).toEqual(true); }); + it('should not have any item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(false); + }); + it('should throw an error if the given ticket has a claim', async() => { - let ticketId = 16; + const ticketId = 16; + const ctx = { + req: { + accessToken: {userId: 106}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; let error; try { diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js index d1037f251..b0a612bf3 100644 --- a/modules/ticket/back/methods/ticket/summary.js +++ b/modules/ticket/back/methods/ticket/summary.js @@ -55,7 +55,7 @@ module.exports = Self => { { relation: 'client', scope: { - fields: ['salesPersonFk', 'name'], + fields: ['salesPersonFk', 'name', 'phone', 'mobile'], include: { relation: 'salesPerson', scope: { @@ -73,7 +73,7 @@ module.exports = Self => { { relation: 'address', scope: { - fields: ['street', 'city', 'provinceFk', 'phone'], + fields: ['street', 'city', 'provinceFk', 'phone', 'mobile'], include: { relation: 'province', scope: { diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 10c10b134..ac6f4f100 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -56,6 +56,9 @@ "TicketState":{ "dataSource": "vn" }, + "TicketLastState":{ + "dataSource": "vn" + }, "TicketService":{ "dataSource": "vn" }, diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 1f2ea4bbf..767a3e59e 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -73,7 +73,7 @@ "model": "SaleTracking", "foreignKey": "saleFk" }, - "itemShelving": { + "itemShelvingSale": { "type": "hasOne", "model": "ItemShelvingSale", "foreignKey": "saleFk" diff --git a/modules/ticket/back/models/ticket-last-state.json b/modules/ticket/back/models/ticket-last-state.json new file mode 100644 index 000000000..890d800af --- /dev/null +++ b/modules/ticket/back/models/ticket-last-state.json @@ -0,0 +1,34 @@ +{ + "name": "TicketLastState", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketLastState" + } + }, + "properties": { + "name": { + "type": "string" + }, + "ticketFk": { + "id": 1, + "type": "Number" + }, + "ticketTrackingFk": { + "id": 2, + "type": "Number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "ticketTracking": { + "type": "belongsTo", + "model": "TicketTracking", + "foreignKey": "ticketTrackingFk" + } + } +} diff --git a/modules/ticket/back/models/ticket-weekly.js b/modules/ticket/back/models/ticket-weekly.js index 733f1483a..8db53b283 100644 --- a/modules/ticket/back/models/ticket-weekly.js +++ b/modules/ticket/back/models/ticket-weekly.js @@ -3,14 +3,6 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { require('../methods/ticket-weekly/filter')(Self); - Self.validatesPresenceOf('ticketFk', { - message: `Ticket id cannot be blank` - }); - - Self.validatesPresenceOf('weekDay', { - message: `Weekday cannot be blank` - }); - Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(`This ticket is already on weekly tickets`); diff --git a/modules/ticket/back/models/ticket-weekly.json b/modules/ticket/back/models/ticket-weekly.json index c19e79bc1..6d432831f 100644 --- a/modules/ticket/back/models/ticket-weekly.json +++ b/modules/ticket/back/models/ticket-weekly.json @@ -25,6 +25,11 @@ "type": "belongsTo", "model": "Ticket", "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" } } } \ No newline at end of file diff --git a/modules/ticket/front/basic-data/index.js b/modules/ticket/front/basic-data/index.js index 4965ee61e..4deebff17 100644 --- a/modules/ticket/front/basic-data/index.js +++ b/modules/ticket/front/basic-data/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +class Controller extends Section { set ticket(data) { if (!data) return; @@ -25,8 +21,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state']; - ngModule.component('vnTicketBasicData', { template: require('./index.html'), bindings: { diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index b8fffd2c1..f6655a221 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -1,14 +1,8 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($scope, $http, $translate, vnApp) { - this.$scope = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Component { $onInit() { this.basicData.registerChild(this); } @@ -247,8 +241,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$translate', 'vnApp']; - ngModule.component('vnTicketBasicDataStepOne', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index b1931d0bb..a0673cbbe 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -13,7 +13,8 @@ describe('Ticket', () => { $state = _$state_; $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketBasicDataStepOne', {$state}); + const $element = angular.element(''); + controller = $componentController('vnTicketBasicDataStepOne', {$element}); controller.ticket = { addressFk: 121, agencyModeFk: 7, diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index f766f5726..00556350b 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -1,13 +1,7 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, $state, $translate, vnApp) { - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Component { $onInit() { this.data.registerChild(this); } @@ -92,13 +86,11 @@ class Controller { this.$translate.instant(`The ticket has been unrouted`) ); this.card.reload(); - this.$state.go('ticket.card.summary', {id: this.$state.params.id}); + this.$state.go('ticket.card.summary', {id: this.$params.id}); }); } } -Controller.$inject = ['$http', '$state', '$translate', 'vnApp']; - ngModule.component('vnTicketBasicDataStepTwo', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/basic-data/step-two/index.spec.js b/modules/ticket/front/basic-data/step-two/index.spec.js index 1ca89fd90..e67389f9d 100644 --- a/modules/ticket/front/basic-data/step-two/index.spec.js +++ b/modules/ticket/front/basic-data/step-two/index.spec.js @@ -7,7 +7,8 @@ describe('Ticket', () => { beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject($componentController => { - controller = $componentController('vnTicketBasicDataStepTwo'); + const $element = angular.element(''); + controller = $componentController('vnTicketBasicDataStepTwo', {$element}); })); describe('getTotalPrice()', () => { diff --git a/modules/ticket/front/card/index.js b/modules/ticket/front/card/index.js index 3872259a9..8dce23aa7 100644 --- a/modules/ticket/front/card/index.js +++ b/modules/ticket/front/card/index.js @@ -57,13 +57,13 @@ class Controller extends ModuleCard { ], }; - this.$http.get(`Tickets/${this.$params.id}`, {filter}) + return this.$http.get(`Tickets/${this.$params.id}`, {filter}) .then(res => this.onData(res.data)); } onData(data) { this.ticket = data; - this.$http.get(`Clients/${data.client.id}/getDebt`) + return this.$http.get(`Clients/${data.client.id}/getDebt`) .then(res => this.ticket.client.debt = res.data.debt); } } diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 16db43a2e..e555eb8d7 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -1,7 +1,7 @@ diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 027fdad77..d0b6ed880 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $stateParams) { - this.$stateParams = $stateParams; - this.$scope = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { order: 'concept ASC', include: [{ @@ -32,7 +32,7 @@ class Controller { } base() { - let sales = this.$scope.model.data; + let sales = this.$.model.data; let sum = 0; if (!sales) return; @@ -59,18 +59,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketComponents', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index 4dd361b27..3547a4905 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -75,7 +75,8 @@ describe('ticket', () => { ], quantity: 5 }]; - controller = $componentController('vnTicketComponents', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketComponents', {$element, $scope}); })); describe('base()', () => { diff --git a/modules/ticket/front/component/style.scss b/modules/ticket/front/component/style.scss index c20b8f720..d1a8ac9c4 100644 --- a/modules/ticket/front/component/style.scss +++ b/modules/ticket/front/component/style.scss @@ -3,23 +3,23 @@ vn-ticket-components { .vn-table > tbody { &:not(:last-child) { - border-bottom: .1em solid $color-spacer-light; + border-bottom: 1px solid $color-spacer-light; } & > tr { border-bottom: none; &.components { - height: 1em; + height: 16px; & > td { - padding-top: .1em; - padding-bottom: .1em; + padding-top: 1px; + padding-bottom: 1px; } &:nth-child(2) > td { - padding-top: 1em; + padding-top: 16px; } &:last-child > td { - padding-bottom: 1em; + padding-bottom: 16px; } } } diff --git a/modules/ticket/front/create/card.js b/modules/ticket/front/create/card.js index 54cc56c68..01c5da4c9 100644 --- a/modules/ticket/front/create/card.js +++ b/modules/ticket/front/create/card.js @@ -1,20 +1,16 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, vnApp, $translate, $state, $stateParams, vnConfig) { - this.$stateParams = $stateParams; - this.$http = $http; - this.translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.ticket = {}; - this.$state = $state; - this.clientFk = $stateParams.clientFk; + this.clientFk = this.$params.clientFk; } $onInit() { - if (this.$stateParams && this.$stateParams.clientFk) - this.clientId = parseInt(this.$stateParams.clientFk); + if (this.$params && this.$params.clientFk) + this.clientId = parseInt(this.$params.clientFk); this.warehouseId = this.vnConfig.warehouseFk; } @@ -124,14 +120,12 @@ class Controller { warehouseId: this.ticket.warehouseFk, }; this.$http.post(`Tickets/new`, params).then(res => { - this.vnApp.showSuccess(this.translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); } } -Controller.$inject = ['$http', 'vnApp', '$translate', '$state', '$stateParams', 'vnConfig']; - ngModule.component('vnTicketCreateCard', { template: require('./card.html'), controller: Controller, diff --git a/modules/ticket/front/create/index.js b/modules/ticket/front/create/index.js index bb9b4c76e..c93051d7a 100644 --- a/modules/ticket/front/create/index.js +++ b/modules/ticket/front/create/index.js @@ -1,18 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - } - +class Controller extends Section { async onSubmit() { let newTicketID = await this.$.card.createTicket(); this.$state.go('ticket.card.summary', {id: newTicketID}); } } -Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnTicketCreate', { template: require('./index.html'), diff --git a/modules/ticket/front/descriptor-popover/index.js b/modules/ticket/front/descriptor-popover/index.js index 5b94f3c14..822296c5b 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.ticket = null; this._quicklinks = {}; } @@ -106,7 +103,6 @@ class Controller extends Component { ); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnTicketDescriptorPopover', { template: require('./index.html'), diff --git a/modules/ticket/front/descriptor-popover/style.scss b/modules/ticket/front/descriptor-popover/style.scss index 58e65d320..f50481083 100644 --- a/modules/ticket/front/descriptor-popover/style.scss +++ b/modules/ticket/front/descriptor-popover/style.scss @@ -1,8 +1,8 @@ vn-ticket-descriptor-popover { vn-ticket-descriptor { display: block; - width: 16em; - max-height: 28em; + width: 256px; + max-height: 448px; & > vn-card { margin: 0!important; diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index ec7005e79..d15d7185d 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -1,5 +1,5 @@ + on-accept="$ctrl.changeShipped()"> -
-
- Change shipped hour -
- - -
+
Change shipped hour
+ +
diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 6ea2d1892..5dc7a3f70 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -9,38 +9,45 @@ class Controller extends Component { this.moreOptions = [ { name: 'Add turn', - acl: 'buyer', - callback: this.showAddTurnDialog - }, - {name: 'Show Delivery Note', callback: this.showDeliveryNote}, - {name: 'Send Delivery Note', callback: this.confirmDeliveryNote}, - {name: 'Delete ticket', callback: this.showDeleteTicketDialog}, - {name: 'Change shipped hour', callback: this.showChangeShipped}, - {name: 'SMS Pending payment', callback: this.sendPaymentSms}, - {name: 'SMS Minimum import', callback: this.sendImportSms}, - { + callback: this.showAddTurnDialog, + acl: 'buyer' + }, { + name: 'Show Delivery Note', + callback: this.showDeliveryNote + }, { + name: 'Send Delivery Note', + callback: this.confirmDeliveryNote + }, { + name: 'Delete ticket', + callback: this.showDeleteTicketDialog + }, { + name: 'Change shipped hour', + callback: this.showChangeShipped + }, { + name: 'SMS Pending payment', + callback: this.sendPaymentSms + }, { + name: 'SMS Minimum import', + callback: this.sendImportSms + }, { name: 'Add stowaway', callback: this.showAddStowaway, show: () => this.canShowStowaway - }, - { + }, { name: 'Delete stowaway', callback: this.showDeleteStowaway, show: () => this.shouldShowDeleteStowaway() - }, - { + }, { name: 'Make invoice', - acl: 'invoicing', callback: this.showMakeInvoiceDialog, - show: () => !this.hasInvoice() - }, - { + show: () => !this.hasInvoice(), + acl: 'invoicing' + }, { name: 'Regenerate invoice', - acl: 'invoicing', callback: this.showRegenerateInvoiceDialog, - show: () => this.hasInvoice() - }, - { + show: () => this.hasInvoice(), + acl: 'invoicing' + }, { name: 'Recalculate components', callback: this.comfirmRecalculateComponents, show: () => this.isEditable @@ -98,22 +105,20 @@ class Controller extends Component { showChangeShipped() { if (!this.isEditable) { - this.vnApp.showError(this.$translate.instant(`This ticket can't be modified`)); + this.vnApp.showError(this.$t(`This ticket can't be modified`)); return; } + this.newShipped = this.ticket.shipped; this.$.changeShippedDialog.show(); } - changeShipped(response) { - if (response === 'accept') { - let data = {shipped: this.newShipped}; - let query = `Tickets/${this.ticket.id}/updateEditableTicket`; - this.$http.post(query, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated')); - this.cardReload(); - }); - } + changeShipped() { + let data = {shipped: this.newShipped}; + let query = `Tickets/${this.ticket.id}/updateEditableTicket`; + this.$http.post(query, data) + .then(() => this.cardReload()) + .then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated'))); } isTicketModule() { @@ -158,16 +163,19 @@ class Controller extends Component { } addTurn(day) { - let params = {ticketFk: this.ticket.id, weekDay: day}; + let params = { + ticketFk: this.ticket.id, + weekDay: day, + agencyModeFk: this.ticket.agencyModeFk}; this.$http.patch(`TicketWeeklies`, params).then(() => { this.$.addTurn.hide(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }); } showDeleteTicketDialog() { if (!this.isEditable) { - this.vnApp.showError(this.$translate.instant('This ticket cant be deleted')); + this.vnApp.showError(this.$t('This ticket cant be deleted')); return; } @@ -179,7 +187,7 @@ class Controller extends Component { const query = `Tickets/${this.ticket.id}/setDeleted`; this.$http.post(query).then(() => { this.$state.go('ticket.index'); - this.vnApp.showSuccess(this.$translate.instant('Ticket deleted')); + this.vnApp.showSuccess(this.$t('Ticket deleted')); }); } } @@ -213,7 +221,7 @@ class Controller extends Component { deleteStowaway() { const query = `Tickets/${this.ticket.id}/deleteStowaway`; this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); this.cardReload(); }); } @@ -235,9 +243,8 @@ class Controller extends Component { clientId: this.ticket.client.id, ticketId: this.ticket.id }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`email/delivery-note?${serializedParams}`).then( - () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) + this.$http.get(`email/delivery-note`, {params}).then( + () => this.vnApp.showMessage(this.$t('Notification sent!')) ); } @@ -246,13 +253,13 @@ class Controller extends Component { ticketId: this.ticket.id, created: this.ticket.created }; - const message = this.$params.message || this.$translate.instant('Minimum is needed', params); + const message = this.$params.message || this.$t('Minimum is needed', params); this.newSMS = {message}; this.showSMSDialog(); } sendPaymentSms() { - const message = this.$params.message || this.$translate.instant('Make a payment'); + const message = this.$params.message || this.$t('Make a payment'); this.newSMS = {message}; this.showSMSDialog(); } @@ -285,7 +292,7 @@ class Controller extends Component { if (response === 'accept') { const query = `Tickets/${this.ticket.id}/makeInvoice`; this.$http.post(query).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Ticket invoiced')); + this.vnApp.showSuccess(this.$t('Ticket invoiced')); this.$state.reload(); }); } @@ -309,7 +316,7 @@ class Controller extends Component { const invoiceId = this.ticket.invoiceOut.id; const query = `InvoiceOuts/${invoiceId}/regenerate`; this.$http.post(query).then(() => { - const snackbarMessage = this.$translate.instant( + const snackbarMessage = this.$t( `Invoice sent for a regeneration, will be available in a few minutes`); this.vnApp.showSuccess(snackbarMessage); }); @@ -342,7 +349,7 @@ class Controller extends Component { recalculateComponents() { const query = `Tickets/${this.ticket.id}/recalculateComponents`; this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }); } } diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 3f4b87682..4f43ac010 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -157,8 +157,7 @@ describe('Ticket Component vnTicketDescriptor', () => { jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller, 'cardReload'); - $httpBackend.when('POST', 'Tickets/12/updateEditableTicket').respond(); - $httpBackend.expect('POST', 'Tickets/12/updateEditableTicket').respond(); + $httpBackend.expectRoute('POST', 'Tickets/:id/updateEditableTicket').respond(); controller.changeShipped('accept'); $httpBackend.flush(); diff --git a/modules/ticket/front/descriptor/style.scss b/modules/ticket/front/descriptor/style.scss index 4becf9789..1a69feeff 100644 --- a/modules/ticket/front/descriptor/style.scss +++ b/modules/ticket/front/descriptor/style.scss @@ -2,7 +2,7 @@ .add-stowaway { vn-data-viewer { - width: 40em + width: 640px } } diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index f1b59f6c0..e745d98b8 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -1,13 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.dms = { files: [], hasFile: false, @@ -103,8 +99,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; - ngModule.component('vnTicketDmsCreate', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/create/index.spec.js b/modules/ticket/front/dms/create/index.spec.js index f0d7ad7c5..c6cb1da5a 100644 --- a/modules/ticket/front/dms/create/index.spec.js +++ b/modules/ticket/front/dms/create/index.spec.js @@ -13,7 +13,8 @@ describe('Ticket', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketDmsCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsCreate', {$element}); controller._ticket = { id: 15, client: {id: 101, name: 'Bruce wayne'}, diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index 9ff967816..44e3890f8 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -1,15 +1,7 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $state.params; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Section { get ticket() { return this._ticket; } @@ -37,7 +29,7 @@ class Controller { } setDefaultParams() { - const path = `Dms/${this.$stateParams.dmsId}`; + const path = `Dms/${this.$params.dmsId}`; this.$http.get(path).then(res => { const dms = res.data && res.data; this.dms = { @@ -54,7 +46,7 @@ class Controller { } onSubmit() { - const query = `dms/${this.$stateParams.dmsId}/updateFile`; + const query = `dms/${this.$params.dmsId}/updateFile`; const options = { method: 'POST', url: query, @@ -92,8 +84,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; - ngModule.component('vnTicketDmsEdit', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js index 757ca24ef..20224a4b9 100644 --- a/modules/ticket/front/dms/edit/index.spec.js +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -5,16 +5,16 @@ describe('Ticket', () => { let controller; let $scope; let $httpBackend; - let $state; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $state = {params: {dmsId: 1}}; - controller = $componentController('vnTicketDmsEdit', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsEdit', {$element}); controller._ticket = {id: 1, ticketFk: 16}; + controller.$params = {dmsId: 1}; })); describe('ticket() setter', () => { diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 4e4834510..3b690cfd3 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -1,7 +1,7 @@
+ href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> {{::document.dms.file}} @@ -68,7 +68,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index c6ceb6b0d..a37d15426 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($stateParams, $scope, $http, $translate, vnToken, vnApp) { - this.$stateParams = $stateParams; - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.accessToken = vnToken.token; - this.vnApp = vnApp; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: { relation: 'dms', @@ -71,8 +67,6 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnToken', 'vnApp']; - ngModule.component('vnTicketDmsIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/index/index.spec.js b/modules/ticket/front/dms/index/index.spec.js index 8916a5c63..cd1fd0125 100644 --- a/modules/ticket/front/dms/index/index.spec.js +++ b/modules/ticket/front/dms/index/index.spec.js @@ -3,18 +3,15 @@ import crudModel from 'core/mocks/crud-model'; describe('Ticket', () => { describe('Component vnTicketDmsIndex', () => { - let $componentController; - let $scope; let $httpBackend; let controller; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { - $componentController = _$componentController_; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - controller = $componentController('vnTicketDmsIndex', {$: $scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsIndex', {$element}); controller.$.model = crudModel; })); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index b2e859970..a90d48670 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -1,7 +1,7 @@ { describe('Component vnTicketExpedition', () => { let controller; let $scope; - let $state; let $httpBackend; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_, _$httpBackend_) => { - $state = _$state_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = { refresh: () => {} }; - controller = $componentController('vnTicketExpedition', {$state, $scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketExpedition', {$element, $scope}); })); describe('returnDialog()', () => { diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index e9f522839..4803f40ff 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -1,17 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; import './style.scss'; -export default class Controller { - constructor($scope, $state, $stateParams, $translate, $http) { - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.$stateParams = $stateParams; - this.$state = $state; - this.selectedTicket = null; - } - +export default class Controller extends Section { openBalanceDialog() { const checkedTickets = this.checked; const description = []; @@ -37,7 +29,7 @@ export default class Controller { } get checked() { - const tickets = this.$.tickets || []; + const tickets = this.$.model.data || []; const checkedLines = []; for (let ticket of tickets) { if (ticket.checked) @@ -123,8 +115,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$stateParams', '$translate', '$http']; - ngModule.component('vnTicketIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 6b0b42ffd..10bd88d3d 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -23,7 +23,8 @@ describe('Component vnTicketIndex', () => { beforeEach(inject(($componentController, _$window_) => { $window = _$window_; - controller = $componentController('vnTicketIndex'); + const $element = angular.element(''); + controller = $componentController('vnTicketIndex', {$element}); })); describe('compareDate()', () => { @@ -87,7 +88,7 @@ describe('Component vnTicketIndex', () => { controller.$.balanceCreateDialog = {show: () => {}}; jest.spyOn(controller.$.balanceCreateDialog, 'show').mockReturnThis(); - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; controller.$.balanceCreateDialog.amountPaid = 0; controller.openBalanceDialog(); @@ -101,7 +102,7 @@ describe('Component vnTicketIndex', () => { describe('checked()', () => { it('should return an array of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; const firstRow = result[0]; const secondRow = result[1]; @@ -114,7 +115,7 @@ describe('Component vnTicketIndex', () => { describe('totalChecked()', () => { it('should return the total number of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; expect(result.length).toEqual(2); diff --git a/modules/ticket/front/log/index.html b/modules/ticket/front/log/index.html index 4fe26c871..91109d3eb 100644 --- a/modules/ticket/front/log/index.html +++ b/modules/ticket/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/log/index.js b/modules/ticket/front/log/index.js index 6a486d3d0..df2584481 100644 --- a/modules/ticket/front/log/index.js +++ b/modules/ticket/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnTicketLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/ticket/front/note/index.html b/modules/ticket/front/note/index.html index 617cf2f7d..32d93c630 100644 --- a/modules/ticket/front/note/index.html +++ b/modules/ticket/front/note/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketObservations" fields="['id', 'ticketFk', 'observationTypeFk', 'description']" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="observations" auto-load="true"> diff --git a/modules/ticket/front/note/index.js b/modules/ticket/front/note/index.js index 4a74b3b98..3eda4561b 100644 --- a/modules/ticket/front/note/index.js +++ b/modules/ticket/front/note/index.js @@ -1,22 +1,16 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); }); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnTicketObservation', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/package/index.html b/modules/ticket/front/package/index.html index 12ac13862..84d79fce3 100644 --- a/modules/ticket/front/package/index.html +++ b/modules/ticket/front/package/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketPackagings" fields="['id', 'ticketFk', 'packagingFk', 'quantity', 'created']" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="packages" auto-load="true"> diff --git a/modules/ticket/front/package/index.js b/modules/ticket/front/package/index.js index d73c000c7..df0b9a503 100644 --- a/modules/ticket/front/package/index.js +++ b/modules/ticket/front/package/index.js @@ -1,31 +1,25 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } - +class Controller extends Section { add() { - this.$scope.model.insert({ + this.$.model.insert({ packagingFk: null, quantity: null, created: new Date(), - ticketFk: this.$stateParams.id + ticketFk: this.$params.id }); } onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); }); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketPackage', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index 67ce5464e..58e13a451 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -1,7 +1,7 @@ this.$state.go('ticket.card.request.index', {id: this.$state.params.id}) + this.$.watcher.submit().then(() => + this.$state.go('ticket.card.request.index', {id: this.$params.id}) ); } } -Controller.$inject = ['$state', '$scope']; - ngModule.component('vnTicketRequestCreate', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 395338116..0acb661e3 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -3,7 +3,7 @@ url="TicketRequests" fields="['id', 'description', 'created', 'requesterFk', 'attenderFk', 'quantity', 'price', 'saleFk', 'isOk']" order="created ASC" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" filter="::$ctrl.filter" data="purchaseRequests" auto-load="true"> diff --git a/modules/ticket/front/request/index/index.js b/modules/ticket/front/request/index/index.js index e8cb54f22..c2e6dc123 100644 --- a/modules/ticket/front/request/index/index.js +++ b/modules/ticket/front/request/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$stateParams = $stateParams; - this.$ = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -50,7 +50,7 @@ class Controller { icon: 'icon-transaction', state: `item.card.diary({ id: ${itemFk}, - ticketFk: ${this.$stateParams.id} + ticketFk: ${this.$params.id} })`, tooltip: 'Item diary' } @@ -94,8 +94,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketRequestIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/request/index/index.spec.js b/modules/ticket/front/request/index/index.spec.js index 90d71f062..17f085010 100644 --- a/modules/ticket/front/request/index/index.spec.js +++ b/modules/ticket/front/request/index/index.spec.js @@ -3,14 +3,12 @@ import './index'; describe('Ticket', () => { describe('Component vnTicketRequestIndex', () => { let controller; - let $scope; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - - controller = $componentController('vnTicketRequestIndex', {$scope}); + beforeEach(angular.mock.inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnTicketRequestIndex', {$element}); })); describe('getRequestState()', () => { diff --git a/modules/ticket/front/sale-checked/index.html b/modules/ticket/front/sale-checked/index.html index c7e060e4e..a2afd3b8f 100644 --- a/modules/ticket/front/sale-checked/index.html +++ b/modules/ticket/front/sale-checked/index.html @@ -2,7 +2,7 @@ vn-id="model" url="sales" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" limit="20" data="sales" order="concept ASC" diff --git a/modules/ticket/front/sale-checked/index.js b/modules/ticket/front/sale-checked/index.js index 08157bc9d..1fd9b662b 100644 --- a/modules/ticket/front/sale-checked/index.js +++ b/modules/ticket/front/sale-checked/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [{ relation: 'item' @@ -29,18 +29,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketSaleChecked', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 0186fb935..b365ef1ca 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -1,7 +1,7 @@ { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.clearDiscount(); @@ -79,8 +72,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate']; - ngModule.component('vnTicketSaleEditDiscount', { template: require('./editDiscount.html'), controller: Controller, diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index b050d3579..e120ad942 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -1,6 +1,6 @@ { + if (!this.$params.id || !this.sales) return; + this.$http.get(`Tickets/${this.$params.id}/subtotal`).then(res => { this.subtotal = res.data || 0.0; }); } @@ -88,8 +84,8 @@ class Controller { loadVAT() { this.VAT = 0.0; - if (!this.$stateParams.id || !this.sales) return; - this.$http.get(`Tickets/${this.$stateParams.id}/getVAT`).then(res => { + if (!this.$params.id || !this.sales) return; + this.$http.get(`Tickets/${this.$params.id}/getVAT`).then(res => { this.VAT = res.data || 0.0; }); } @@ -106,7 +102,7 @@ class Controller { return (shouldShow && (option.always || this.isChecked)); }); - this.$scope.moreButton.data = options; + this.$.moreButton.data = options; } onMoreChange(callback) { @@ -191,7 +187,7 @@ class Controller { }); if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); this.refreshTotal(); } @@ -211,7 +207,7 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -234,13 +230,13 @@ class Controller { } showRemoveLinesDialog() { - this.$scope.deleteLines.show(); + this.$.deleteLines.show(); } showTransferPopover(event) { this.setTransferParams(); - this.$scope.transfer.parent = event.target; - this.$scope.transfer.show(); + this.$.transfer.parent = event.target; + this.$.transfer.show(); } setTransferParams() { @@ -264,7 +260,7 @@ class Controller { sales: this.transfer.sales }; - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); const query = `tickets/${this.ticket.id}/transferSales`; this.$http.post(query, params).then(res => { @@ -281,7 +277,7 @@ class Controller { const sales = this.checkedLines(); if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); this.$http.post(`Claims/createFromSales`, {claim: claim, sales: sales}).then(res => { this.$state.go('claim.card.basicData', {id: res.data.id}); @@ -312,13 +308,13 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } showEditPricePopover(event, sale) { @@ -330,8 +326,8 @@ class Controller { id: sale.id, quantity: sale.quantity }; - this.$scope.editPricePopover.parent = event.target; - this.$scope.editPricePopover.show(); + this.$.editPricePopover.parent = event.target; + this.$.editPricePopover.show(); } updatePrice() { @@ -342,11 +338,11 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } - this.$scope.editPricePopover.hide(); + this.$.editPricePopover.hide(); } updateNewPrice() { @@ -364,23 +360,23 @@ class Controller { price: sale.price, discount: sale.discount }]; - this.$scope.editPopover.parent = event.target; - this.$scope.editPopover.show(); + this.$.editPopover.parent = event.target; + this.$.editPopover.show(); } showEditDialog() { this.edit = this.checkedLines(); - this.$scope.editDialog.show(); + this.$.editDialog.show(); } hideEditDialog() { - this.$scope.model.refresh(); - this.$scope.editDialog.hide(); + this.$.model.refresh(); + this.$.editDialog.hide(); } hideEditPopover() { - this.$scope.model.refresh(); - this.$scope.editPopover.hide(); + this.$.model.refresh(); + this.$.editPopover.hide(); } /* @@ -416,7 +412,7 @@ class Controller { }); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -449,14 +445,14 @@ class Controller { destination: phone, message: this.$translate.instant('Product not available', params) }; - this.$scope.sms.open(); + this.$.sms.open(); } /** * Inserts a new instance */ add() { - this.$scope.model.insert({}); + this.$.model.insert({}); } /* @@ -481,11 +477,11 @@ class Controller { this.$http.post(query, data).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).catch(e => { - this.$scope.model.refresh(); + this.$.model.refresh(); throw e; }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -498,11 +494,11 @@ class Controller { this.$http.post(query, data).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).catch(e => { - this.$scope.model.refresh(); + this.$.model.refresh(); throw e; }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -532,7 +528,7 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -559,7 +555,7 @@ class Controller { const query = `Sales/${sale.id}/recalculatePrice`; this.$http.post(query).then(res => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$scope.model.refresh(); + this.$.model.refresh(); }); } @@ -570,8 +566,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; - ngModule.component('vnTicketSale', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sale/specs/editDiscount.spec.js b/modules/ticket/front/sale/specs/editDiscount.spec.js index 8937d25c6..8eccfe74f 100644 --- a/modules/ticket/front/sale/specs/editDiscount.spec.js +++ b/modules/ticket/front/sale/specs/editDiscount.spec.js @@ -19,7 +19,8 @@ describe('Ticket', () => { }}; $state = _$state_; $state.params.id = 11; - controller = $componentController('vnTicketSaleEditDiscount', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketSaleEditDiscount', {$element, $scope}); controller._edit = [{id: 3}]; controller.onHide = () => {}; })); diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 3b0f04a82..1c8fbda53 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -53,7 +53,8 @@ describe('Ticket', () => { writable: false } }); - controller = $componentController('vnTicketSale', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketSale', {$element, $scope}); controller.card = {reload: () => {}}; controller.ticket = ticket; controller.sales = sales; @@ -196,12 +197,12 @@ describe('Ticket', () => { describe('showSMSDialog()', () => { it('should open an SMS dialog with specified data', () => { - jest.spyOn(controller.$scope.sms, 'open'); + jest.spyOn(controller.$.sms, 'open'); controller.sales[0].checked = true; controller.showSMSDialog(); - expect(controller.$scope.sms.open).toHaveBeenCalledWith(); + expect(controller.$.sms.open).toHaveBeenCalledWith(); expect(controller.newSMS.destination).toEqual(111111111); expect(controller.newSMS.message).not.toEqual(''); }); @@ -242,7 +243,7 @@ describe('Ticket', () => { describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const data = {quantity: 10}; const sale = sales[0]; sale.quantity = 10; @@ -256,13 +257,13 @@ describe('Ticket', () => { controller.updateQuantity(sale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); describe('updateConcept()', () => { it('should make a POST query saving sale concept', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const data = {newConcept: 'My new weapon'}; const sale = sales[0]; sale.concept = 'My new weapon'; @@ -276,13 +277,13 @@ describe('Ticket', () => { controller.updateConcept(sale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); describe('addSale()', () => { it('should make a POST query adding a new sale', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const newSale = {itemFk: 4, quantity: 10}; const params = {itemId: 4, quantity: 10}; @@ -307,7 +308,7 @@ describe('Ticket', () => { controller.addSale(newSale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); diff --git a/modules/ticket/front/sale/style.scss b/modules/ticket/front/sale/style.scss index 1eb7556e9..142c72295 100644 --- a/modules/ticket/front/sale/style.scss +++ b/modules/ticket/front/sale/style.scss @@ -13,14 +13,14 @@ vn-ticket-sale { } } .taxes { - max-width: 10em; + max-width: 160px; border: $border-thin-light; text-align: right; - padding: .5em !important; + padding: 8px !important; & > p { - font-size: 1.2em; - margin: .2em; + font-size: 1.2rem; + margin: 3px; } } vn-dialog.edit { @@ -61,24 +61,24 @@ vn-ticket-sale { vn-horizontal { & > vn-one:nth-child(1) { border-right: 1px solid $color-bg; - padding-right: 1em; + padding-right: 16px; } & > vn-one:nth-child(2) { - margin-left: 1em + margin-left: 16px } } vn-table, table { - margin-bottom: 10px + margin-bottom: 10px; } vn-table { overflow-x: hidden; overflow-y: auto; - max-height: 25em; - width: 30em; + max-height: 400px; + width: 480px; } table { - width: 25em + width: 400px } } .edit-price { @@ -96,8 +96,8 @@ vn-ticket-sale { } p.simulatorTitle { - margin-bottom: 0px; - font-size: 12px; + margin-bottom: 0; + font-size: .75rem; color: $color-main; } vn-label-value { diff --git a/modules/ticket/front/services/index.html b/modules/ticket/front/services/index.html index 0cbcbe5df..57146661c 100644 --- a/modules/ticket/front/services/index.html +++ b/modules/ticket/front/services/index.html @@ -1,7 +1,7 @@ @@ -22,7 +22,7 @@ @@ -72,26 +72,28 @@ + vn-id="newServiceTypeDialog" + on-accept="$ctrl.onNewServiceTypeAccept($data)" + on-close="newServiceType = null">
New service type
- + ng-model="newServiceType.expenseFk">
diff --git a/modules/ticket/front/services/index.js b/modules/ticket/front/services/index.js index fca4cd070..efb62fe2e 100644 --- a/modules/ticket/front/services/index.js +++ b/modules/ticket/front/services/index.js @@ -1,18 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; -class Controller { - constructor($http, $scope, $stateParams, vnApp, $translate, $element) { - this.$http = $http; - this.$scope = $scope; - this.$stateParams = $stateParams; - this.vnApp = vnApp; - this.$translate = $translate; - this.$element = $element; - this.services = []; - } - +class Controller extends Section { $onInit() { + this.services = []; this.getDefaultTaxClass(); } @@ -25,48 +17,36 @@ class Controller { } add() { - if (this.defaultTaxClass) { - this.$scope.model.insert({ - taxClassFk: this.defaultTaxClass.id, - quantity: 1, - ticketFk: this.$stateParams.id - }); - } + this.$.model.insert({ + taxClassFk: this.defaultTaxClass.id, + quantity: 1, + ticketFk: this.$params.id + }); } - onNewServiceTypeOpen() { - this.newServiceType = {}; - } - - newServiceTypeDialog(elementIndex, event) { + onNewServiceTypeClick(service, event) { event.preventDefault(); - this.$scope.createServiceTypeDialog.show(); - this.currentServiceIndex = elementIndex; + this.$.newServiceType = {}; + this.$.newServiceTypeDialog.show(service); } - onNewServiceTypeResponse(response) { - if (response == 'accept') { - if (!this.newServiceType.name) - throw new UserError(`Name can't be empty`); + onNewServiceTypeAccept(service) { + if (!this.$.newServiceType.name) + throw new UserError(`Name can't be empty`); - this.$http.post(`TicketServiceTypes`, this.newServiceType).then(response => { - this.services[this.currentServiceIndex].ticketServiceTypeFk = response.data.id; - }); - } + return this.$http.post(`TicketServiceTypes`, this.$.newServiceType) + .then(res => service.ticketServiceTypeFk = res.data.id); } onSubmit() { - this.$scope.watcher.check(); + this.$.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.model.save() + .then(() => this.$.model.refresh()) + .then(() => this.$.watcher.notifySaved()); } } -Controller.$inject = ['$http', '$scope', '$stateParams', 'vnApp', '$translate', '$element']; - ngModule.component('vnTicketService', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/services/index.spec.js b/modules/ticket/front/services/index.spec.js index 30bcd821a..10e3ad47e 100644 --- a/modules/ticket/front/services/index.spec.js +++ b/modules/ticket/front/services/index.spec.js @@ -3,17 +3,16 @@ import './index.js'; describe('Ticket component vnTicketService', () => { let controller; let $httpBackend; - let $httpParamSerializer; let $scope; let $element; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_, $rootScope) => { - $element = angular.element(`
`); + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); + + $element = angular.element(`
`); controller = $componentController('vnTicketService', {$scope, $element}); })); @@ -32,13 +31,13 @@ describe('Ticket component vnTicketService', () => { }); }); - describe('onNewServiceTypeResponse', () => { - it(`should throw an error if the new service description is empty`, () => { - controller.newServiceType = {name: undefined}; + describe('onNewServiceTypeAccept', () => { + it(`should throw an error if the new service type name is empty`, () => { + $scope.newServiceType = {}; let error; try { - controller.onNewServiceTypeResponse('accept'); + controller.onNewServiceTypeAccept({}); } catch (e) { error = e.message; } @@ -47,18 +46,22 @@ describe('Ticket component vnTicketService', () => { }); it('should set the description of the selected service upon service type creation', () => { - controller.services = [ - {id: 1, description: 'not too great service'} - ]; + const service = { + id: 1, + quantity: 10 + }; + $scope.newServiceType = { + name: 'Totally new stuff' + }; - controller.newServiceType = {name: 'totally new stuff'}; - controller.currentServiceIndex = 0; - - $httpBackend.when('POST', 'TicketServiceTypes').respond({id: 4001, name: 'totally new stuff'}); - controller.onNewServiceTypeResponse('accept'); + $httpBackend.when('POST', 'TicketServiceTypes').respond({ + id: 4001, + name: 'Totally new stuff' + }); + controller.onNewServiceTypeAccept(service); $httpBackend.flush(); - expect(controller.services[0].ticketServiceTypeFk).toEqual(4001); + expect(service.ticketServiceTypeFk).toEqual(4001); }); }); }); diff --git a/modules/ticket/front/sms/index.js b/modules/ticket/front/sms/index.js index ac1131513..56959e3ee 100644 --- a/modules/ticket/front/sms/index.js +++ b/modules/ticket/front/sms/index.js @@ -3,21 +3,12 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $translate, vnApp) { - super($element, $scope); - - this.$scope = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - open() { - this.$scope.SMSDialog.show(); + this.$.SMSDialog.show(); } charactersRemaining() { - const element = this.$scope.message; + const element = this.$.message; const value = element.input.value; const maxLength = 160; @@ -49,8 +40,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp']; - ngModule.component('vnTicketSms', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js index cd397b9fa..45e7765d1 100644 --- a/modules/ticket/front/sms/index.spec.js +++ b/modules/ticket/front/sms/index.spec.js @@ -4,17 +4,16 @@ describe('Ticket', () => { describe('Component vnTicketSms', () => { let controller; let $httpBackend; - let $element; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; let $scope = $rootScope.$new(); - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnTicketSms', {$element, $scope}); controller.$params = {id: 11}; - controller.$scope.message = { + controller.$.message = { input: { value: 'My SMS' } @@ -58,7 +57,7 @@ describe('Ticket', () => { describe('charactersRemaining()', () => { it('should return the characters remaining in a element', () => { - controller.$scope.message = { + controller.$.message = { input: { value: 'My message 0€' } diff --git a/modules/ticket/front/sms/style.scss b/modules/ticket/front/sms/style.scss index 89723b196..84571a5f4 100644 --- a/modules/ticket/front/sms/style.scss +++ b/modules/ticket/front/sms/style.scss @@ -1,5 +1,5 @@ @import "variables"; .SMSDialog { - min-width: 25em + min-width: 400px } \ No newline at end of file diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index decb01023..be5ff6d92 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -30,6 +30,13 @@ + + + {{$ctrl.summary.routeFk}} + + @@ -41,22 +48,28 @@ - - - {{$ctrl.summary.routeFk}} - - - + + + + + + { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketSummary'); + const $element = angular.element(''); + controller = $componentController('vnTicketSummary', {$element}); controller.ticket = {id: 1}; })); diff --git a/modules/ticket/front/summary/locale/es.yml b/modules/ticket/front/summary/locale/es.yml new file mode 100644 index 000000000..3b409cc6d --- /dev/null +++ b/modules/ticket/front/summary/locale/es.yml @@ -0,0 +1,4 @@ +Address phone: Tel. consignatario +Address mobile: Móv. consignatario +Client phone: Tel. cliente +Client mobile: Móv. cliente \ No newline at end of file diff --git a/modules/ticket/front/summary/style.scss b/modules/ticket/front/summary/style.scss index 4502c5dca..d92121194 100644 --- a/modules/ticket/front/summary/style.scss +++ b/modules/ticket/front/summary/style.scss @@ -32,29 +32,29 @@ vn-ticket-summary .summary { } & > vn-horizontal > vn-one { - min-width: 10em; + min-width: 160px; &.taxes { border: $border-thin-light; text-align: right; - padding: .5em; + padding: 8px; & > p { - font-size: 1.2em; - margin: .2em; + font-size: 1.2rem; + margin: 3px; } } &.services { .vn-table > vn-thead .identifier, .vn-table > vn-tbody .identifier { - min-width: 3.5em + min-width: 56px } .vn-table > vn-thead .tax-class, .vn-table > vn-tbody .tax-class { - min-width: 11em; - width: 1px + min-width: 176px; + width: 1px; } .vn-table > vn-tbody vn-td:first-child { diff --git a/modules/ticket/front/tracking/edit/index.js b/modules/ticket/front/tracking/edit/index.js index 03c5c6c0f..f2de08389 100644 --- a/modules/ticket/front/tracking/edit/index.js +++ b/modules/ticket/front/tracking/edit/index.js @@ -1,16 +1,13 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state, vnApp, $translate, $http) { - this.$http = $http; - this.$ = $scope; - this.$state = $state; - this.vnApp = vnApp; - this.$translate = $translate; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.ticket = { - ticketFk: $state.params.id + ticketFk: this.$params.id }; - this.params = {ticketFk: $state.params.id}; + this.params = {ticketFk: this.$params.id}; } $onInit() { @@ -64,7 +61,6 @@ class Controller { }); } } -Controller.$inject = ['$scope', '$state', 'vnApp', '$translate', '$http']; ngModule.component('vnTicketTrackingEdit', { template: require('./index.html'), diff --git a/modules/ticket/front/tracking/edit/index.spec.js b/modules/ticket/front/tracking/edit/index.spec.js index 313a25b73..cf8036814 100644 --- a/modules/ticket/front/tracking/edit/index.spec.js +++ b/modules/ticket/front/tracking/edit/index.spec.js @@ -9,7 +9,8 @@ describe('Ticket', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $translate, vnApp) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketTrackingEdit'); + const $element = angular.element(''); + controller = $componentController('vnTicketTrackingEdit', {$element}); controller.ticket = {id: 1}; controller.$ = {watcher: {updateOriginalData: () => {}}}; controller.card = {reload: () => {}}; diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index 8398a0602..f66c62449 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketTrackings" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" limit="20" data="trackings" order="created DESC" diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index adc1ac5a2..e58dc4300 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$ = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -37,8 +37,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketTrackingIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/volume/index.html b/modules/ticket/front/volume/index.html index 0006b8854..977f76513 100644 --- a/modules/ticket/front/volume/index.html +++ b/modules/ticket/front/volume/index.html @@ -2,15 +2,15 @@ vn-id="model" url="sales" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="$ctrl.sales" limit="20">
- + diff --git a/modules/ticket/front/volume/index.js b/modules/ticket/front/volume/index.js index 914c9819d..bf616cb24 100644 --- a/modules/ticket/front/volume/index.js +++ b/modules/ticket/front/volume/index.js @@ -1,10 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $stateParams) { - this.$scope = $scope; - this.$http = $http; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [{ relation: 'item' @@ -34,7 +33,6 @@ class Controller { if (value) this.applyVolumes(); } - applyVolumes() { if (!this.sales || !this.volumes) return; @@ -58,18 +56,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$stateParams']; - ngModule.component('vnTicketVolume', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/volume/index.spec.js b/modules/ticket/front/volume/index.spec.js index 6c2a808eb..2f6efee21 100644 --- a/modules/ticket/front/volume/index.spec.js +++ b/modules/ticket/front/volume/index.spec.js @@ -19,7 +19,8 @@ describe('ticket', () => { }}; $state = _$state_; $state.params.id = 101; - controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketVolume', {$element, $scope}); })); describe('sales() setter', () => { diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index 40ae04106..e97d47eef 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -25,6 +25,7 @@ Ticket ID Client Weekday + Agency Warehouse Salesperson @@ -45,7 +46,7 @@ {{::weekly.clientName}}
- + + + + + {{::weekly.warehouseName}} @@ -89,7 +102,7 @@ diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index f15576e9f..a89dbbc2e 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -1,14 +1,11 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnApp, $translate, $http) { - this.$ = $scope; - this.vnApp = vnApp; - this.$translate = $translate; - this.$http = $http; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.ticketSelected = null; - this.weekdays = [ {id: 0, name: 'Monday'}, {id: 1, name: 'Tuesday'}, @@ -20,65 +17,47 @@ export default class Controller { ]; } - onWeekdayUpdate(ticketFk, weekDay) { - const params = {ticketFk, weekDay}; - this.$http.patch('TicketWeeklies/', params).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + onUpdate(ticketFk, field, value) { + const params = {ticketFk, [field]: value}; + this.$http.patch('TicketWeeklies', params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); }); } - deleteWeekly(index) { - this.ticketIndex = index; - this.$.deleteWeekly.show(); - event.stopImmediatePropagation(); - } - showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); + this.stopEvent(event); } showTicketDescriptor(event, ticketFk) { this.$.ticketDescriptor.ticketFk = ticketFk; this.$.ticketDescriptor.parent = event.target; this.$.ticketDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); + this.stopEvent(event); } showWorkerDescriptor(event, workerFk) { this.$.workerDescriptor.workerFk = workerFk; this.$.workerDescriptor.parent = event.target; this.$.workerDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); + this.stopEvent(event); } - onDescriptorLoad() { - this.$.popover.relocate(); + deleteWeekly(event, ticketFk) { + this.$.deleteWeekly.show(ticketFk); + this.stopEvent(event); } - - preventNavigation(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } - - returnDialog(response) { - const ticket = this.$.model.data[this.ticketIndex]; - if (response === 'accept') { - this.$http.delete(`TicketWeeklies/${ticket.ticketFk}`).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.model.remove(this.ticketIndex); - }); - } + onDeleteWeeklyAccept(ticketFk) { + return this.$http.delete(`TicketWeeklies/${ticketFk}`).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + const ticketIndex = this.$.model.data.findIndex(e => e.ticketFk == ticketFk); + this.$.model.remove(ticketIndex); + }); } } -Controller.$inject = ['$scope', 'vnApp', '$translate', '$http']; - ngModule.component('vnTicketWeeklyIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/weekly/index.spec.js b/modules/ticket/front/weekly/index.spec.js new file mode 100644 index 000000000..a66e5c637 --- /dev/null +++ b/modules/ticket/front/weekly/index.spec.js @@ -0,0 +1,46 @@ +import './index'; +import crudModel from 'core/mocks/crud-model'; + +describe('ticket weekly', () => { + describe('Component vnTicketWeeklyIndex', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('ticket')); + + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { + $httpBackend = _$httpBackend_; + const $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnTicketWeeklyIndex', {$element, $scope}); + })); + + describe('onUpdate()', () => { + it('should make a query a PATCH querye then call vnApp.showSuccess()', () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + + $httpBackend.expectPATCH(`TicketWeeklies`).respond(); + controller.onUpdate('ticketFk', 'field', 'value'); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + }); + }); + + describe('onDeleteWeeklyAccept()', () => { + it('should make a DELETE query then call showSuccess(), afterwards checks that remove returns value 0', () => { + controller.$.model = crudModel; + controller.$.model.data = [{ticketFk: 'ticketFk'}]; + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'remove'); + + $httpBackend.expectDELETE(`TicketWeeklies/ticketFk`).respond(); + controller.onDeleteWeeklyAccept('ticketFk'); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.$.model.remove).toHaveBeenCalledWith(0); + }); + }); + }); +}); diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 0eafe4010..aebf4e3cd 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -7,7 +7,7 @@ }, "options": { "mysql": { - "table": "travel" + "table": "travel" } }, "properties": { diff --git a/modules/travel/front/basic-data/index.js b/modules/travel/front/basic-data/index.js index 7406598b0..139ef46e8 100644 --- a/modules/travel/front/basic-data/index.js +++ b/modules/travel/front/basic-data/index.js @@ -1,17 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope) { - this.$ = $scope; - } - +class Controller extends Section { onSubmit() { - return this.$.watcher.submit().then(() => { - this.card.reload(); - }); + return this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope']; ngModule.component('vnTravelBasicData', { template: require('./index.html'), diff --git a/modules/travel/front/basic-data/index.spec.js b/modules/travel/front/basic-data/index.spec.js index ed874d7e8..aaad487ef 100644 --- a/modules/travel/front/basic-data/index.spec.js +++ b/modules/travel/front/basic-data/index.spec.js @@ -2,14 +2,14 @@ import './index.js'; describe('Travel Component vnTravelBasicData', () => { let controller; - let $scope; + beforeEach(angular.mock.module('travel', $translateProvider => { $translateProvider.translations('en', {}); })); - beforeEach(angular.mock.inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - controller = $componentController('vnTravelBasicData', $scope); + beforeEach(angular.mock.inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnTravelBasicData', {$element}); controller.card = {reload: () => {}}; controller.$.watcher = {submit: () => {}}; })); diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index 0d5a2cc01..286d508de 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -2,14 +2,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - constructor($element, $, $stateParams) { - super($element, $); - this.$stateParams = $stateParams; - } - $onChanges() { - if (this.$stateParams && this.$stateParams.q) - this.travel = JSON.parse(this.$stateParams.q); + if (this.$params && this.$params.q) + this.travel = JSON.parse(this.$params.q); } onSubmit() { @@ -19,8 +14,6 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', '$stateParams']; - ngModule.component('vnTravelCreate', { template: require('./index.html'), controller: Controller diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index a6fa5a9b1..e47f30bd3 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -2,7 +2,6 @@ import './index'; import watcher from 'core/mocks/watcher'; describe('Travel Component vnTravelCreate', () => { - let $element; let $scope; let $state; let controller; @@ -13,7 +12,7 @@ describe('Travel Component vnTravelCreate', () => { $scope = $rootScope.$new(); $state = _$state_; $scope.watcher = watcher; - $element = angular.element('
'); + const $element = angular.element(''); controller = $componentController('vnTravelCreate', {$element, $scope}); })); @@ -28,8 +27,8 @@ describe('Travel Component vnTravelCreate', () => { }); describe('$onChanges()', () => { - it('should update the travel data when stateParams.q is defined', () => { - controller.$stateParams = {q: '{"ref": 1,"agencyModeFk": 1}'}; + it('should update the travel data when $params.q is defined', () => { + controller.$params = {q: '{"ref": 1,"agencyModeFk": 1}'}; const params = {q: '{"ref": 1, "agencyModeFk": 1}'}; const json = JSON.parse(params.q); diff --git a/modules/travel/front/descriptor-popover/index.js b/modules/travel/front/descriptor-popover/index.js index cb13d7f06..cb7e29bda 100644 --- a/modules/travel/front/descriptor-popover/index.js +++ b/modules/travel/front/descriptor-popover/index.js @@ -2,11 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.travel = null; this._quicklinks = {}; } @@ -76,7 +73,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnTravelDescriptorPopover', { template: require('./index.html'), diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index 187a7ed8f..911cae010 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -1,20 +1,13 @@ import ngModule from '../module'; - -class Controller { - constructor($scope) { - this.$ = $scope; - } -} - -Controller.$inject = ['$scope']; +import Component from 'core/lib/component'; ngModule.component('vnTravelDescriptor', { template: require('./index.html'), + controller: Component, bindings: { travel: '<' }, require: { card: '^?vnTravelCard' }, - controller: Controller }); diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index e49100d67..4b018dea6 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -11,10 +11,9 @@ describe('Travel Component vnTravelIndex', () => { beforeEach(ngModule('travel')); - beforeEach(angular.mock.inject(($componentController, $rootScope) => { - let $scope = $rootScope.$new(); - let $element = angular.element('
'); - controller = $componentController('vnTravelIndex', {$element, $scope}); + beforeEach(angular.mock.inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnTravelIndex', {$element}); controller.$.summary = {show: jasmine.createSpy('show')}; })); diff --git a/modules/travel/front/log/index.html b/modules/travel/front/log/index.html index 8b442f671..fc4622e5a 100644 --- a/modules/travel/front/log/index.html +++ b/modules/travel/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/log/index.js b/modules/travel/front/log/index.js index a9a07aaf6..742488058 100644 --- a/modules/travel/front/log/index.js +++ b/modules/travel/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnTravelLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js index 2abcb0a33..27dfa0392 100644 --- a/modules/travel/front/main/index.spec.js +++ b/modules/travel/front/main/index.spec.js @@ -12,13 +12,29 @@ describe('Travel Component vnTravel', () => { describe('fetchParams()', () => { it('should return a range of dates with passed scope days', () => { + /** + * Calculates the difference in days between two dates, it also + * accounts for cases where the two dates in question span a + * daylight saving time (DST) change. + * + * @param {Date} a The start date + * @param {Date} b The end date + * @return {Number} The difference in days + */ + function diffInDays(a, b) { + const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); + const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); + const msInDay = 86400 * 1000; + return Math.floor((utc2 - utc1) / msInDay); + } + let params = controller.fetchParams({scopeDays: 2}); + const diff = diffInDays( + params.shippedFrom, + new Date(params.shippedTo.getTime() + 1) + ); - let from = params.shippedFrom.getTime(); - let to = params.shippedTo.getTime() + 1; - let msInDay = 86400 * 1000; - - expect(to - from).toEqual(3 * msInDay); + expect(diff).toEqual(3); }); }); }); diff --git a/modules/travel/front/summary/index.js b/modules/travel/front/summary/index.js index 8ee2da49d..af940aa6c 100644 --- a/modules/travel/front/summary/index.js +++ b/modules/travel/front/summary/index.js @@ -1,12 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -import Component from 'core/lib/component'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); +class Controller extends Section { + $onInit() { this.entries = []; - this.$httpParamSerializer = $httpParamSerializer; } get travel() { @@ -50,8 +48,7 @@ class Controller extends Component { } }; - const serializedParams = this.$httpParamSerializer(params); - return this.$http.get(`TravelThermographs?${serializedParams}`).then(res => { + return this.$http.get(`TravelThermographs`, {params}).then(res => { this.travelThermographs = res.data; }); } @@ -66,8 +63,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.component('vnTravelSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/travel/front/summary/index.spec.js b/modules/travel/front/summary/index.spec.js index 9b041f22b..7f5c68aec 100644 --- a/modules/travel/front/summary/index.spec.js +++ b/modules/travel/front/summary/index.spec.js @@ -4,7 +4,6 @@ describe('component vnTravelSummary', () => { let controller; let $httpBackend; let $scope; - let $element; let $httpParamSerializer; beforeEach(angular.mock.module('travel', $translateProvider => { @@ -15,7 +14,7 @@ describe('component vnTravelSummary', () => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); - $element = angular.element(``); + const $element = angular.element(``); controller = $componentController('vnTravelSummary', {$element, $scope}); })); diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index b35313fc8..6c0464991 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -1,13 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.dms = {files: [], state: 'Ok'}; } @@ -86,8 +82,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; - ngModule.component('vnTravelThermographCreate', { template: require('./index.html'), controller: Controller, diff --git a/modules/travel/front/thermograph/create/index.spec.js b/modules/travel/front/thermograph/create/index.spec.js index 625f5bb20..58fbe3991 100644 --- a/modules/travel/front/thermograph/create/index.spec.js +++ b/modules/travel/front/thermograph/create/index.spec.js @@ -3,7 +3,6 @@ import './index'; describe('Ticket', () => { describe('Component vnTravelThermographCreate', () => { let controller; - let $scope; let $httpBackend; let $httpParamSerializer; const travelId = 3; @@ -11,11 +10,11 @@ describe('Ticket', () => { beforeEach(ngModule('travel')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $scope = $rootScope.$new(); + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTravelThermographCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTravelThermographCreate', {$element}); controller._travel = { id: travelId }; diff --git a/modules/travel/front/thermograph/edit/index.js b/modules/travel/front/thermograph/edit/index.js index 018098312..90e0cc7b1 100644 --- a/modules/travel/front/thermograph/edit/index.js +++ b/modules/travel/front/thermograph/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { get travel() { return this._travel; } diff --git a/modules/travel/front/thermograph/edit/index.spec.js b/modules/travel/front/thermograph/edit/index.spec.js index eac92ba0f..180827134 100644 --- a/modules/travel/front/thermograph/edit/index.spec.js +++ b/modules/travel/front/thermograph/edit/index.spec.js @@ -5,7 +5,6 @@ describe('Worker', () => { describe('Component vnTravelThermographEdit', () => { let controller; let $scope; - let $element; let $httpBackend; let $httpParamSerializer; @@ -15,7 +14,7 @@ describe('Worker', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(`{{::thermograph.created | date: 'dd/MM/yyyy'}}
+ href="api/dms/{{::thermograph.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/travel/front/thermograph/index/index.js b/modules/travel/front/thermograph/index/index.js index 48487eb7c..40cae3917 100644 --- a/modules/travel/front/thermograph/index/index.js +++ b/modules/travel/front/thermograph/index/index.js @@ -1,11 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -import Component from 'core/lib/component'; -class Controller extends Component { - constructor($element, $, vnToken) { - super($element, $); - this.accessToken = vnToken.token; +class Controller extends Section { + $onInit() { this.filter = { include: {relation: 'warehouse', @@ -33,8 +31,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', 'vnToken']; - ngModule.component('vnTravelThermographIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/back/methods/worker-dms/downloadFile.js b/modules/worker/back/methods/worker-dms/downloadFile.js new file mode 100644 index 000000000..cc8653e0e --- /dev/null +++ b/modules/worker/back/methods/worker-dms/downloadFile.js @@ -0,0 +1,40 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + Self.remoteMethodCtx('downloadFile', { + description: 'Download a worker document', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'Number', + description: 'The document id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: `/:id/downloadFile`, + verb: 'GET' + } + }); + + Self.downloadFile = async function(ctx, id) { + if (!await Self.app.models.Dms.checkRole(ctx, id) && !await Self.isMine(ctx, id)) + throw new UserError(`You don't have enough privileges`); + return await Self.app.models.Dms.getFile(id); + }; +}; diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js new file mode 100644 index 000000000..553cf2a25 --- /dev/null +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -0,0 +1,53 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethodCtx('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'Object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + } + ], + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, filter) => { + const conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; + + const account = await Self.app.models.Account.findById(userId); + const stmt = new ParameterizedSQL( + `SELECT d.id dmsFk, d.reference, d.description, d.file, d.created + FROM workerDocument wd + JOIN dms d ON d.id = wd.document + JOIN dmsType dt ON dt.id = d.dmsTypeFk + LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk AND rr.role = ? + `, [account.roleFk] + ); + const oldWhere = filter.where; + const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]}; + + filter.where = { + and: [{ + or: [yourOwnDms, { + role: { + neq: null + } + }] + }, oldWhere]}; + stmt.merge(conn.makeSuffix(filter)); + + return await conn.executeStmt(stmt); + }; +}; diff --git a/modules/worker/back/methods/worker-dms/specs/downloadFile.spec.js b/modules/worker/back/methods/worker-dms/specs/downloadFile.spec.js new file mode 100644 index 000000000..27ed204ad --- /dev/null +++ b/modules/worker/back/methods/worker-dms/specs/downloadFile.spec.js @@ -0,0 +1,27 @@ +const app = require('vn-loopback/server/server'); + +describe('worker-dms downloadFile()', () => { + let dmsId = 4; + + it('should return a response for an employee with text content-type', async() => { + let workerId = 106; + let ctx = {req: {accessToken: {userId: workerId}}}; + const result = await app.models.WorkerDms.downloadFile(ctx, dmsId); + + expect(result[1]).toEqual('text/plain'); + }); + + it('should return an error for a user without enough privileges', async() => { + let clientId = 1; + let ctx = {req: {accessToken: {userId: clientId}}}; + + let error; + try { + await app.models.WorkerDms.downloadFile(ctx, dmsId); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + }); +}); diff --git a/modules/worker/back/methods/worker/filter.js b/modules/worker/back/methods/worker/filter.js index 21462eb42..d08b27a18 100644 --- a/modules/worker/back/methods/worker/filter.js +++ b/modules/worker/back/methods/worker/filter.js @@ -125,7 +125,6 @@ module.exports = Self => { LEFT JOIN account.emailUser mu ON mu.userFk = u.id` ); - stmt.merge(conn.makeSuffix(filter)); let itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 884759bc9..e91e8b0fc 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -52,5 +52,11 @@ }, "Device": { "dataSource": "vn" + }, + "WorkerLog": { + "dataSource": "vn" } } + + + diff --git a/modules/worker/back/models/worker-dms.js b/modules/worker/back/models/worker-dms.js index 4504b4ed4..4b862a81e 100644 --- a/modules/worker/back/models/worker-dms.js +++ b/modules/worker/back/models/worker-dms.js @@ -1,4 +1,17 @@ module.exports = Self => { + require('../methods/worker-dms/downloadFile')(Self); require('../methods/worker-dms/removeFile')(Self); require('../methods/worker-dms/allowedContentTypes')(Self); + require('../methods/worker-dms/filter')(Self); + + Self.isMine = async function(ctx, dmsId) { + const myUserId = ctx.req.accessToken.userId; + let workerDms = await Self.findOne({ + where: { + workerFk: myUserId, + dmsFk: dmsId + } + }); + return workerDms !== null; + }; }; diff --git a/modules/worker/back/models/worker-dms.json b/modules/worker/back/models/worker-dms.json index 56cad65a6..80634cfcc 100644 --- a/modules/worker/back/models/worker-dms.json +++ b/modules/worker/back/models/worker-dms.json @@ -29,6 +29,9 @@ "mysql": { "columnName": "worker" } + }, + "isReadableByWorker": { + "type": "Boolean" } }, "relations": { diff --git a/modules/worker/back/models/worker-log.json b/modules/worker/back/models/worker-log.json new file mode 100644 index 000000000..f100f3486 --- /dev/null +++ b/modules/worker/back/models/worker-log.json @@ -0,0 +1,58 @@ +{ + "name": "WorkerLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "String" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 7456a3caa..6af7e8608 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -1,7 +1,11 @@ { "name": "Worker", "description": "Company employees", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"WorkerLog", + "showField": "firstName" + }, "options": { "mysql": { "table": "worker" diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index 67439b350..bdc309c00 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -1,10 +1,9 @@ + + save="patch">
diff --git a/modules/worker/front/basic-data/index.js b/modules/worker/front/basic-data/index.js index 28107dc12..ebeb4716b 100644 --- a/modules/worker/front/basic-data/index.js +++ b/modules/worker/front/basic-data/index.js @@ -1,16 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($) { - Object.assign(this, {$}); - } - +class Controller extends Section { onSubmit() { - this.$.watcher.submit() + return this.$.watcher.submit() .then(() => this.card.reload()); } } -Controller.$inject = ['$scope']; ngModule.component('vnWorkerBasicData', { template: require('./index.html'), diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 1860f6bdd..6b849d19f 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($element, $http) { - this.element = $element[0]; - this.$http = $http; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.date = new Date(); this.events = {}; } @@ -103,7 +103,6 @@ class Controller { dayNumber.style.color = 'rgba(0, 0, 0, 0.7)'; } } -Controller.$inject = ['$element', '$http']; ngModule.component('vnWorkerCalendar', { template: require('./index.html'), diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 2f85e3a1a..da49b8f0f 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -4,7 +4,6 @@ describe('Worker', () => { describe('Component vnWorkerCalendar', () => { let $httpBackend; let $scope; - let $element; let controller; let year = new Date().getFullYear(); @@ -13,15 +12,10 @@ describe('Worker', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $element = angular.element('
'); + const $element = angular.element(''); controller = $componentController('vnWorkerCalendar', {$element, $scope}); })); - afterEach(() => { - $element.remove(); - $scope.$destroy(); - }); - describe('started property', () => { it(`should return first day and month of current year`, () => { let started = new Date(year, 0, 1); diff --git a/modules/worker/front/calendar/style.scss b/modules/worker/front/calendar/style.scss index e622dda64..9b3fc749b 100644 --- a/modules/worker/front/calendar/style.scss +++ b/modules/worker/front/calendar/style.scss @@ -13,7 +13,7 @@ vn-worker-calendar { border: 1px solid #ddd; margin: $spacing-md; padding: $spacing-xs; - max-width: 18em; + max-width: 288px; } } } diff --git a/modules/worker/front/department/index.js b/modules/worker/front/department/index.js index 28c2cfa99..35dc650f6 100644 --- a/modules/worker/front/department/index.js +++ b/modules/worker/front/department/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, vnApp, $translate) { - this.$ = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; - } - +class Controller extends Section { $postLink() { this.$.treeview.fetch(); } @@ -87,8 +81,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; - ngModule.component('vnWorkerDepartment', { template: require('./index.html'), controller: Controller diff --git a/modules/worker/front/descriptor-popover/index.js b/modules/worker/front/descriptor-popover/index.js index 55843a67d..6463853f9 100644 --- a/modules/worker/front/descriptor-popover/index.js +++ b/modules/worker/front/descriptor-popover/index.js @@ -2,11 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.worker = null; this._quicklinks = {}; } @@ -84,7 +81,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnWorkerDescriptorPopover', { template: require('./index.html'), diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor-popover/index.spec.js index dc524bc2d..0b2746475 100644 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ b/modules/worker/front/descriptor-popover/index.spec.js @@ -5,17 +5,16 @@ describe('worker Component vnWorkerDescriptorPopover', () => { let $httpParamSerializer; let $scope; let controller; - let $element; beforeEach(ngModule('worker')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(`
`); $scope = $rootScope.$new(); $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnWorkerDescriptorPopover', {$scope, $element}); + const $element = angular.element(``); + controller = $componentController('vnWorkerDescriptorPopover', {$element, $scope}); })); describe('workerFk()', () => { diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 6dab06958..82cfd0886 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, $state) { - this.$state = $state; - this.$http = $http; - } - +class Controller extends Component { get worker() { return this._worker; } @@ -33,9 +29,6 @@ class Controller { } } -Controller.$inject = ['$http', '$state']; - - ngModule.component('vnWorkerDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index e7bfe7bfd..388b9a333 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -1,11 +1,10 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { - constructor($element, $, vnConfig) { +class Controller extends Section { + constructor($element, $) { super($element, $); - this.vnConfig = vnConfig; this.dms = { files: [], hasFile: false, diff --git a/modules/worker/front/dms/edit/index.js b/modules/worker/front/dms/edit/index.js index 1a593414a..ac0104fa1 100644 --- a/modules/worker/front/dms/edit/index.js +++ b/modules/worker/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { get worker() { return this._worker; } diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 697d3d5aa..1bf1af61e 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -1,8 +1,7 @@ {{::document.dmsFk}} - - - {{::document.dms.reference}} + + + {{::document.reference}} - - {{::document.dms.description}} + + {{::document.description}} - +
{{::document.dms.file}} + href="api/workerDms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}">{{::document.file}} - {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} + {{::document.created | date:'dd/MM/yyyy HH:mm'}} + href="api/workerDms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> @@ -57,7 +56,7 @@ - @@ -78,7 +77,7 @@ - diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index ab3be3408..d322145a0 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -3,9 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $, vnToken) { + constructor($element, $) { super($element, $); - this.accessToken = vnToken.token; this.filter = { include: { relation: 'dms', @@ -68,8 +67,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', 'vnToken']; - ngModule.component('vnWorkerDmsIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/dms/index/index.spec.js b/modules/worker/front/dms/index/index.spec.js index 7378ef301..074f11524 100644 --- a/modules/worker/front/dms/index/index.spec.js +++ b/modules/worker/front/dms/index/index.spec.js @@ -3,7 +3,6 @@ import crudModel from 'core/mocks/crud-model'; describe('Worker', () => { describe('Component vnWorkerDmsIndex', () => { - let $componentController; let $scope; let $element; let $httpBackend; @@ -11,8 +10,7 @@ describe('Worker', () => { beforeEach(ngModule('worker')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { - $componentController = _$componentController_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $element = angular.element(` diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index a3fbb34f5..f6ee85a5b 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($, $http) { - Object.assign(this, { - $, - $http - }); - } - +class Controller extends Section { get worker() { return this._worker; } @@ -60,8 +54,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http']; - ngModule.component('vnWorkerSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 13829e0c5..14aeb541f 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -1,7 +1,8 @@ -import Component from 'core/lib/component'; import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { + +class Controller extends Section { constructor($element, $, vnWeekDays) { super($element, $); this.weekDays = []; diff --git a/modules/worker/front/time-control/style.scss b/modules/worker/front/time-control/style.scss index 8555e827b..99a21883f 100644 --- a/modules/worker/front/time-control/style.scss +++ b/modules/worker/front/time-control/style.scss @@ -13,11 +13,11 @@ vn-worker-time-control { display: flex; align-items: center; justify-content: center; - padding: .3em 0; + padding: 4px 0; & > vn-icon { color: $color-font-secondary; - padding-right: .1em; + padding-right: 1px; } } } diff --git a/modules/worker/front/worker-log/index.html b/modules/worker/front/worker-log/index.html new file mode 100644 index 000000000..090dbf2e3 --- /dev/null +++ b/modules/worker/front/worker-log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/worker/front/worker-log/index.js b/modules/worker/front/worker-log/index.js new file mode 100644 index 000000000..1f1a4f2f8 --- /dev/null +++ b/modules/worker/front/worker-log/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.component('vnWorkerLog', { + template: require('./index.html'), + controller: Section, +}); diff --git a/modules/zone/back/methods/zone/getEvents.js b/modules/zone/back/methods/zone/getEvents.js index abf3d7e19..406ef0103 100644 --- a/modules/zone/back/methods/zone/getEvents.js +++ b/modules/zone/back/methods/zone/getEvents.js @@ -4,19 +4,15 @@ module.exports = Self => { description: 'Returns delivery days for a postcode', accepts: [ { - arg: 'provinceFk', + arg: 'geoFk', type: 'Number', - description: 'The province id', - required: true - }, { - arg: 'postCode', - type: 'String', - description: 'The postcode' + description: 'The geo id' }, { arg: 'agencyModeFk', type: 'Number', description: 'The agency mode id' } + ], returns: { type: 'Object', @@ -28,10 +24,10 @@ module.exports = Self => { } }); - Self.getEvents = async(provinceFk, postCode, agencyModeFk) => { + Self.getEvents = async(geoFk, agencyModeFk) => { let [events, exclusions] = await Self.rawSql( - `CALL zone_getEvents(?, ?, ?)`, - [provinceFk, postCode, agencyModeFk] + `CALL zone_getEvents(?, ?)`, + [geoFk, agencyModeFk] ); return {events, exclusions}; }; diff --git a/modules/zone/front/basic-data/index.js b/modules/zone/front/basic-data/index.js index a730ed362..40e5b49dc 100644 --- a/modules/zone/front/basic-data/index.js +++ b/modules/zone/front/basic-data/index.js @@ -1,20 +1,14 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.submit().then(() => { - this.card.reload(); - }); + this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope', '$state']; - ngModule.component('vnZoneBasicData', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/calendar/style.scss b/modules/zone/front/calendar/style.scss index 3fe23278e..14d234c1b 100644 --- a/modules/zone/front/calendar/style.scss +++ b/modules/zone/front/calendar/style.scss @@ -24,7 +24,7 @@ vn-zone-calendar { justify-content: space-evenly; & > .vn-calendar { - max-width: 18em; + max-width: 288px; .day { &.event .day-number { diff --git a/modules/zone/front/create/index.js b/modules/zone/front/create/index.js index 98d377d0f..c0bce4f08 100644 --- a/modules/zone/front/create/index.js +++ b/modules/zone/front/create/index.js @@ -1,9 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; +export default class Controller extends Section { + $onInit() { this.zone = { travelingDays: 0, price: 0.20, @@ -13,12 +12,11 @@ export default class Controller { } onSubmit() { - return this.$scope.watcher.submit().then(res => { - this.$state.go('zone.card.location', {id: res.data.id}); - }); + return this.$.watcher.submit().then(res => + this.$state.go('zone.card.location', {id: res.data.id}) + ); } } -Controller.$inject = ['$scope', '$state']; ngModule.component('vnZoneCreate', { template: require('./index.html'), diff --git a/modules/zone/front/create/index.spec.js b/modules/zone/front/create/index.spec.js index c2956b6cf..79fe00ed8 100644 --- a/modules/zone/front/create/index.spec.js +++ b/modules/zone/front/create/index.spec.js @@ -19,7 +19,8 @@ describe('Zone Component vnZoneCreate', () => { } }; }; - controller = $componentController('vnZoneCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnZoneCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 589208caf..59ed5c944 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -6,37 +6,98 @@
+ + + + + vn-one + ng-if="$ctrl.deliveryMethodFk === 'delivery'" + vn-focus + label="Postcode" + ng-model="params.geoFk" + url="Postcodes/location" + fields="['code','townFk']" + order="code, townFk" + value-field="geoFk" + show-field="code" + > -
{{name}}
-
- {{country.country}} -
+ {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}})
- - + url="AgencyModes/isActive" + where="$ctrl.agencyFilter" + vn-id="agencymode">
+ + +
Zones
- + + + + + + Id + Name + Agency + Closing + Price + + + + + + {{::zone.id}} + {{::zone.name}} + {{::zone.agencyMode.name}} + {{::zone.hour | date: 'HH:mm'}} + {{::zone.price | currency: 'EUR':2}} + + + + + + + + + + +
-
\ No newline at end of file + + + + \ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 006252a69..cf7ef14da 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -7,6 +7,9 @@ class Controller extends Section { this.$.params = {}; } + $postLink() { + this.deliveryMethodFk = 'delivery'; + } onSubmit() { this.$.data = null; this.$http.get(`Zones/getEvents`, {params: this.$.params}) @@ -18,6 +21,26 @@ class Controller extends Section { }); } + get deliveryMethodFk() { + return this._deliveryMethodFk; + } + + set deliveryMethodFk(value) { + this._deliveryMethodFk = value; + this.$.params.agencyModeFk = null; + let filter; + if (value === 'pickUp') { + filter = {where: {code: 'PICKUP'}}; + this.$.agencymode.focus(); + } else + filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}}; + + this.$http.get(`DeliveryMethods`, {filter}).then(res => { + let deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id); + this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}}; + }); + } + onSelection($event, $events) { if (!$events.length) return; @@ -26,8 +49,7 @@ class Controller extends Section { zones.push(event.zoneFk); this.$.zoneEvents.show($event.target); - const zoneIndex = this.$.zoneIndex; - const zoneModel = zoneIndex.$scope.model; + const zoneModel = this.$.zoneModel; zoneModel.applyFilter({ include: { relation: 'agencyMode', @@ -38,6 +60,12 @@ class Controller extends Section { } }); } + + preview(event, zone) { + this.stopEvent(event); + this.selectedZone = zone; + this.$.summary.show(); + } } ngModule.component('vnZoneDeliveryDays', { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 35171ab94..8ad4af80e 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -3,26 +3,40 @@ import popover from 'core/mocks/popover'; import crudModel from 'core/mocks/crud-model'; describe('Zone Component vnZoneDeliveryDays', () => { - let $componentController; let $httpBackend; let controller; let $element; beforeEach(ngModule('zone')); - beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { - $componentController = _$componentController_; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; $element = angular.element(' { + it(`should set the deliveryMethodFk property and check just agencymode focus`, () => { + controller.$.agencymode = {focus: jasmine.createSpy('focus')}; + + controller.deliveryMethodFk = 'pickUp'; + + expect(controller.$.agencymode.focus).toHaveBeenCalledWith(); + }); + + it(`should set the deliveryMethodFk property, call method http and sets the agencyfilter`, () => { + $httpBackend.when('GET', 'DeliveryMethods').respond([{id: 'id'}]); + + controller.deliveryMethodFk = 'no pickUp'; + $httpBackend.flush(); + + expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: ['id']}}); + }); + }); + describe('onSubmit()', () => { it('should make an HTTP GET query and then call the showMessage() method', () => { jest.spyOn(controller.vnApp, 'showMessage'); @@ -48,7 +62,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); }); - describe('onSelection()', () => { + xdescribe('onSelection()', () => { it('should not call the show popover method if events array is empty', () => { jest.spyOn(controller.$.zoneEvents, 'show'); @@ -62,7 +76,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); it('should call the show() method and then call the applyFilter() method with the expected ids', () => { - const zoneModel = controller.$.zoneIndex.$scope.model; + const zoneModel = controller.$.zoneModel; jest.spyOn(controller.$.zoneEvents, 'show'); jest.spyOn(zoneModel, 'applyFilter'); diff --git a/modules/zone/front/delivery-days/style.scss b/modules/zone/front/delivery-days/style.scss index 531b51795..3dd4abb7c 100644 --- a/modules/zone/front/delivery-days/style.scss +++ b/modules/zone/front/delivery-days/style.scss @@ -7,7 +7,7 @@ vn-zone-delivery-days { flex-wrap: wrap; & > vn-calendar { - min-width: 16.5em; + min-width: 264px; } } form { @@ -19,11 +19,7 @@ vn-zone-delivery-days { .zoneEvents { width: 700px; max-height: 450px; - - vn-float-button { - display: none - } - + vn-data-viewer { margin-bottom: 0; vn-pagination { diff --git a/modules/zone/front/descriptor/index.js b/modules/zone/front/descriptor/index.js index 736d8dd31..b3808f256 100644 --- a/modules/zone/front/descriptor/index.js +++ b/modules/zone/front/descriptor/index.js @@ -1,10 +1,8 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($scope, $state, $http) { - this.$scope = $scope; - this.$state = $state; - this.$http = $http; +class Controller extends Component { + $onInit() { this.moreOptions = [ {callback: this.deleteZone, name: 'Delete'} ]; @@ -15,7 +13,7 @@ class Controller { } deleteZone() { - this.$scope.deleteZone.show(); + this.$.deleteZone.show(); } returnDialog(response) { @@ -27,8 +25,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state', '$http']; - ngModule.component('vnZoneDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/locale/es.yml b/modules/zone/front/locale/es.yml index 852703576..d525491e2 100644 --- a/modules/zone/front/locale/es.yml +++ b/modules/zone/front/locale/es.yml @@ -1,29 +1,31 @@ Agency: Agencia +Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona? +Clone: Clonar +Exceptions: Excepciones +Closing: Cierre +Delivery days: Días de entrega +Delivery: Entrega +Everyday: Todos los días +Exclusions: Exclusiones +From: Desde +Hour: Hora +Indefinitely: Indefinido +Inflation: Inflación +Locations: Localizaciones +Maximum m³: M³ máximo +New zone: Nueva zona +One day: Un día +Pick up: Recogida +Postcode: Código postal +Price: Precio +Query: Consultar +Province: Provincia +Range of dates: Rango de fechas +Search zone by id or name: Buscar zonas por identificador o nombre +This zone will be removed: La zona será eliminada +To: Hasta +Volumetric: Volumétrico +Warehouse: Almacén Warehouses: Almacenes Week days: Días de la semana -Exceptions: Excepciones -Exclusions: Exclusiones -Warehouse: Almacén -Hour: Hora -Price: Precio -Locations: Localizaciones -This zone will be removed: La zona será eliminada -Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona? -Zones: Zonas -New zone: Nueva zona -Volumetric: Volumétrico -Clone: Clonar -Search zone by id or name: Buscar zonas por identificador o nombre -From: Desde -To: Hasta -Closing: Cierre -One day: Un día -Range of dates: Rango de fechas -Indefinitely: Indefinido -Everyday: Todos los días -Delivery days: Días de entrega -Province: Provincia -Postcode: Código postal -Inflation: Inflación -Query: Consultar -Maximum m³: M³ máximo \ No newline at end of file +Zones: Zonas \ No newline at end of file diff --git a/modules/zone/front/location/index.js b/modules/zone/front/location/index.js index 9fcd055b3..c30ded3ad 100644 --- a/modules/zone/front/location/index.js +++ b/modules/zone/front/location/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { $postLink() { this.onSearch(); } diff --git a/modules/zone/front/main/index.spec.js b/modules/zone/front/main/index.spec.js index d8d283ad1..24b63a959 100644 --- a/modules/zone/front/main/index.spec.js +++ b/modules/zone/front/main/index.spec.js @@ -6,7 +6,7 @@ describe('Zone Component vnZone', () => { beforeEach(ngModule('zone')); beforeEach(angular.mock.inject($componentController => { - let $element = angular.element(`
`); + const $element = angular.element(''); controller = $componentController('vnZone', {$element}); })); diff --git a/modules/zone/front/summary/index.js b/modules/zone/front/summary/index.js index 636e528be..47a6ba32a 100644 --- a/modules/zone/front/summary/index.js +++ b/modules/zone/front/summary/index.js @@ -1,12 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - - this.$httpParamSerializer = $httpParamSerializer; - } +class Controller extends Section { get zone() { return this._zone; } @@ -32,8 +27,7 @@ class Controller extends Component { } } }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`Zones/findOne?${serializedParams}`).then(res => { + this.$http.get(`Zones/findOne`, {params}).then(res => { this.summary = res.data; }); } @@ -47,15 +41,12 @@ class Controller extends Component { } } }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`Zones/${this.zone.id}/warehouses?${serializedParams}`).then(res => { + this.$http.get(`Zones/${this.zone.id}/warehouses`, {params}).then(res => { this.zoneWarehouses = res.data; }); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.component('vnZoneSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/summary/index.spec.js b/modules/zone/front/summary/index.spec.js index 9025af766..0956fa8c6 100644 --- a/modules/zone/front/summary/index.spec.js +++ b/modules/zone/front/summary/index.spec.js @@ -1,7 +1,6 @@ import './index'; describe('component vnZoneSummary', () => { - let $element; let $scope; let controller; let $httpBackend; @@ -13,7 +12,7 @@ describe('component vnZoneSummary', () => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); - $element = angular.element(``); + const $element = angular.element(``); controller = $componentController('vnZoneSummary', {$element, $scope}); })); @@ -52,17 +51,4 @@ describe('component vnZoneSummary', () => { expect(controller.summary).toBeDefined(); }); }); - - xdescribe('getEntries()', () => { - it('should call the getEntries method to get the entries data', () => { - controller._travel = {id: 999}; - - const query = `/api/Travels/${controller._travel.id}/getEntries`; - $httpBackend.expectGET(query).respond('I am the entries'); - controller.getEntries(); - $httpBackend.flush(); - - expect(controller.entries).toEqual('I am the entries'); - }); - }); }); diff --git a/modules/zone/front/warehouses/index.js b/modules/zone/front/warehouses/index.js index 328f3a1b4..9191a1f49 100644 --- a/modules/zone/front/warehouses/index.js +++ b/modules/zone/front/warehouses/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -class Controller extends Component { +class Controller extends Section { constructor($element, $) { super($element, $); diff --git a/package-lock.json b/package-lock.json index 8648fe476..b46d40dcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2098,6 +2098,13 @@ "extend": "^3.0.1", "split-array-stream": "^2.0.0", "stream-events": "^1.0.4" + }, + "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + } } }, "@google-cloud/projectify": { @@ -2138,6 +2145,11 @@ "xdg-basedir": "^3.0.0" }, "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + }, "mime": { "version": "2.4.4", "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", @@ -2934,15 +2946,6 @@ "ansi-wrap": "^0.1.0" } }, - "ansi-cyan": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ansi-cyan/-/ansi-cyan-0.1.1.tgz", - "integrity": "sha1-U4rlKK+JgvKK4w2G8vF0VtJgmHM=", - "dev": true, - "requires": { - "ansi-wrap": "0.1.0" - } - }, "ansi-escapes": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", @@ -2964,15 +2967,6 @@ "integrity": "sha1-gTWEAhliqenm/QOflA0S9WynhZ4=", "dev": true }, - "ansi-red": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ansi-red/-/ansi-red-0.1.1.tgz", - "integrity": "sha1-jGOPnRCAgAo1PJwoyKgcpHBdlGw=", - "dev": true, - "requires": { - "ansi-wrap": "0.1.0" - } - }, "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", @@ -3210,7 +3204,8 @@ "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true }, "asn1": { "version": "0.2.4", @@ -7972,6 +7967,12 @@ "pinkie-promise": "^2.0.0" }, "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -8284,93 +8285,18 @@ } }, "gulp-jasmine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/gulp-jasmine/-/gulp-jasmine-3.0.0.tgz", - "integrity": "sha1-ATFIbwzVmv/toY4AxkOZKpGWljs=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/gulp-jasmine/-/gulp-jasmine-4.0.0.tgz", + "integrity": "sha512-0UqY2fA6RCdUDJDsVym3zXYSWmt0AV7YY/6PAeKb+oGTKEgS7zZOH5w/4gcSKs+2FXiWrucQwLDvtEKIDbpF4A==", "dev": true, "requires": { - "arrify": "^1.0.0", - "jasmine": "^2.8.0", + "arrify": "^1.0.1", + "jasmine": "^3.1.0", "jasmine-terminal-reporter": "^1.0.3", - "plugin-error": "^0.1.2", - "through2": "^2.0.0" + "plugin-error": "^1.0.1", + "through2": "^2.0.3" }, "dependencies": { - "arr-diff": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-1.1.0.tgz", - "integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=", - "dev": true, - "requires": { - "arr-flatten": "^1.0.1", - "array-slice": "^0.2.3" - } - }, - "arr-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", - "integrity": "sha1-IPnqtexw9cfSFbEHexw5Fh0pLH0=", - "dev": true - }, - "array-slice": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz", - "integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=", - "dev": true - }, - "extend-shallow": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", - "integrity": "sha1-Gda/lN/AnXa6cR85uHLSH/TdkHE=", - "dev": true, - "requires": { - "kind-of": "^1.1.0" - } - }, - "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "jasmine": { - "version": "2.99.0", - "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.99.0.tgz", - "integrity": "sha1-jKctEC5jm4Z8ZImFbg4YqceqQrc=", - "dev": true, - "requires": { - "exit": "^0.1.2", - "glob": "^7.0.6", - "jasmine-core": "~2.99.0" - } - }, - "kind-of": { - "version": "1.1.0", - "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", - "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", - "dev": true - }, - "plugin-error": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", - "integrity": "sha1-O5uzM1zPAPQl4HQ34ZJ2ln2kes4=", - "dev": true, - "requires": { - "ansi-cyan": "^0.1.1", - "ansi-red": "^0.1.1", - "arr-diff": "^1.0.1", - "arr-union": "^2.0.1", - "extend-shallow": "^1.1.2" - } - }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -8382,9 +8308,9 @@ } }, "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", "dev": true } } @@ -9988,12 +9914,6 @@ } } }, - "jasmine-core": { - "version": "2.99.1", - "resolved": "http://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", - "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=", - "dev": true - }, "jasmine-reporters": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/jasmine-reporters/-/jasmine-reporters-2.3.2.tgz", diff --git a/package.json b/package.json index 8077ba9a8..0195aaa9e 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "gulp-env": "^0.4.0", "gulp-file": "^0.4.0", "gulp-install": "^1.1.0", - "gulp-jasmine": "^3.0.0", + "gulp-jasmine": "^4.0.0", "gulp-merge-json": "^1.3.1", "gulp-nodemon": "^2.4.2", "gulp-print": "^2.0.1", diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index f22d7694a..cdf355f60 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -72,6 +72,7 @@ module.exports = { p.name province FROM ticket t JOIN address a ON a.clientFk = t.clientFk + AND a.id = t.addressFk LEFT JOIN province p ON p.id = a.provinceFk WHERE t.id = ?`, [ticketId]); },