From e557f614d58579e31308c34492e6e6780df325d9 Mon Sep 17 00:00:00 2001 From: Radek Jajko Date: Mon, 7 Dec 2020 13:47:56 +0100 Subject: [PATCH 1/7] Add new SystemSettings component Logging Type UI Add a new component that will allow user to change the default point creation property "logging type". By default all data are stored in database. Using this select user will be able to disable saving to database until he do not change that for specific datapoint. #1447 --- scadalts-ui/src/locales/en.json | 10 +- scadalts-ui/src/store/systemSettings/index.js | 35 +++++- .../DefaultLoggTypeComponent.vue | 110 ++++++++++++++++++ .../src/views/SystemSettings/index.vue | 3 + 4 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue diff --git a/scadalts-ui/src/locales/en.json b/scadalts-ui/src/locales/en.json index ab562b656f..7215322aec 100644 --- a/scadalts-ui/src/locales/en.json +++ b/scadalts-ui/src/locales/en.json @@ -132,6 +132,8 @@ "systemsettings.scadaconf.doNotCreateEventsForEmailError": "Do not create Events for email error", "systemsettings.scadaconf.httpRetriverSleepCheckToReactivationWhenStart": "HTTP Retriver - sleep check to reactivation when start", "systemsettings.scadaconf.httpRetriverDoNotAllowEnableReactivation": "HTTP Retriver - do not allow to enable reactivation", + "systemsettings.loggingtype.title": "Default Data Point logging type", + "systemsettings.loggingtype.value": "Logging type:", "systemsettings.notification.fail": "Something went wrong!", "systemsettings.notification.purgedata": "Successfully cleared data!", "systemsettings.notification.send.email": "Email has been sent to ", @@ -142,6 +144,7 @@ "systemsettings.notification.save.systemevent": "System Event Types settings saved!", "systemsettings.notification.save.auditevent": "Audit Event Types settings saved!", "systemsettings.notification.save.database": "Database changed!", + "systemsettings.notification.save.logging": "Default logging type saved!", "systemsettings.alert.purgedata.title": "Purge data?", "systemsettings.alert.purgedata": "This operation will permanently delete datapoint history content. Continue?", "systemsettings.tooltip.derbydatabase": "Derby database is unavailable in this ScadaLTS version!", @@ -181,5 +184,10 @@ "timeperiod.days": "day(s)", "timeperiod.weeks": "week(s)", "timeperiod.months": "month(s)", - "timeperiod.years": "year(s)" + "timeperiod.years": "year(s)", + "pointEdit.logging.type.change": "When point value changes", + "pointEdit.logging.type.all": "All data", + "pointEdit.logging.type.never": "Do not log", + "pointEdit.logging.type.interval": "Interval", + "pointEdit.logging.type.tsChange": "When point timestamp changes" } diff --git a/scadalts-ui/src/store/systemSettings/index.js b/scadalts-ui/src/store/systemSettings/index.js index f38423da6b..d03529f947 100644 --- a/scadalts-ui/src/store/systemSettings/index.js +++ b/scadalts-ui/src/store/systemSettings/index.js @@ -19,7 +19,8 @@ const storeSystemSettings = { miscSettings: undefined, systemStartupTime: undefined, schemaVersion: undefined, - scadaConfig: undefined + scadaConfig: undefined, + defaultLoggingType: undefined, }, mutations: { setDatabaseType(state, databaseType) { @@ -54,6 +55,9 @@ const storeSystemSettings = { }, setScadaConfig(state, scadaConfig) { state.scadaConfig = scadaConfig; + }, + setDefaultLoggingType(state, defaultLoggingType) { + state.defaultLoggingType = defaultLoggingType; } }, actions: { @@ -350,6 +354,35 @@ const storeSystemSettings = { }) }) }, + saveDefaultLoggingType(context) { + return new Promise((resolve, reject) => { + axios.post(`${context.state.systemSettingsApiUrl}/saveDefaultLoggingType/${context.state.defaultLoggingType}`, + { timeout: 5000, useCredentials: true, credentials: 'same-origin' }).then(response => { + if (response.status === 200) { + resolve(true) + } else { + reject(false) + } + }).catch(err => { + reject(err) + }) + }) + }, + getDefaultLoggingType(context) { + return new Promise((resolve, reject) => { + axios.get(`${context.state.systemSettingsApiUrl}/getDefaultLoggingType`, context.state.requestOptions).then(response => { + if (response.status === 200) { + console.debug(response.data); + context.commit('setDefaultLoggingType', response.data.defaultLoggingType) + resolve(response.data.defaultLoggingType) + } + reject(false) + }).catch(err => { + console.error(err); + reject(false) + }) + }) + }, configurationEqual(ctx, objects) { return new Promise((resolve, reject) => { const keys1 = Object.keys(objects.object1); diff --git a/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue b/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue new file mode 100644 index 0000000000..ac1e48176d --- /dev/null +++ b/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue @@ -0,0 +1,110 @@ + + + \ No newline at end of file diff --git a/scadalts-ui/src/views/SystemSettings/index.vue b/scadalts-ui/src/views/SystemSettings/index.vue index ce5778552a..9bdcf5d569 100644 --- a/scadalts-ui/src/views/SystemSettings/index.vue +++ b/scadalts-ui/src/views/SystemSettings/index.vue @@ -17,6 +17,7 @@ + @@ -274,6 +275,7 @@ import SystemEventTypesComponent from "./SystemEventTypesComponent"; import EmailSettingsComponent from "./EmailSettingsComponent"; import HttpSettingsComponent from "./HttpSettingsComponent"; import MiscSettingsComponent from "./MiscSettingsComponent"; +import DefaultLoggingTypeSettingsComponent from "./DefaultLoggTypeComponent"; import ScadaConfigurationComponent from "./ScadaConfigurationComponent"; import { keys } from "@amcharts/amcharts4/.internal/core/utils/Object"; @@ -287,6 +289,7 @@ export default { EmailSettingsComponent, HttpSettingsComponent, MiscSettingsComponent, + DefaultLoggingTypeSettingsComponent, ScadaConfigurationComponent }, filters: { From 63e7daee497035dd25e21d16acee98e49dd5250a Mon Sep 17 00:00:00 2001 From: Artur Wolak Date: Mon, 7 Dec 2020 09:33:30 +0100 Subject: [PATCH 2/7] added constructor in DataPointVO --- src/com/serotonin/mango/vo/DataPointVO.java | 43 ++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/com/serotonin/mango/vo/DataPointVO.java b/src/com/serotonin/mango/vo/DataPointVO.java index caa3465f19..838942fa8c 100644 --- a/src/com/serotonin/mango/vo/DataPointVO.java +++ b/src/com/serotonin/mango/vo/DataPointVO.java @@ -120,11 +120,12 @@ public boolean isNew() { return id == Common.NEW_ID; } + // // // Properties // - private int id = Common.NEW_ID; + private int id; private String xid; @JsonRemoteProperty private String name; @@ -134,16 +135,16 @@ public boolean isNew() { @JsonRemoteProperty private boolean enabled; private int pointFolderId; - private int loggingType = LoggingTypes.ON_CHANGE; - private int intervalLoggingPeriodType = Common.TimePeriods.MINUTES; + private int loggingType; + private int intervalLoggingPeriodType; @JsonRemoteProperty - private int intervalLoggingPeriod = 15; - private int intervalLoggingType = IntervalLoggingTypes.INSTANT; + private int intervalLoggingPeriod; + private int intervalLoggingType; @JsonRemoteProperty - private double tolerance = 0; - private int purgeType = Common.TimePeriods.YEARS; + private double tolerance; + private int purgeType; @JsonRemoteProperty - private int purgePeriod = 1; + private int purgePeriod; @JsonRemoteProperty(typeFactory = BaseTextRenderer.Factory.class) private TextRenderer textRenderer; @JsonRemoteProperty(typeFactory = BaseChartRenderer.Factory.class) @@ -151,17 +152,33 @@ public boolean isNew() { private List eventDetectors; private List comments; @JsonRemoteProperty - private int defaultCacheSize = 1; + private int defaultCacheSize; @JsonRemoteProperty - private boolean discardExtremeValues = false; + private boolean discardExtremeValues; @JsonRemoteProperty - private double discardLowLimit = -Double.MAX_VALUE; + private double discardLowLimit; @JsonRemoteProperty - private double discardHighLimit = Double.MAX_VALUE; - private int engineeringUnits = ENGINEERING_UNITS_DEFAULT; + private double discardHighLimit; + private int engineeringUnits; @JsonRemoteProperty private String chartColour; + public DataPointVO(){ + id = Common.NEW_ID; + loggingType = LoggingTypes.ON_CHANGE; + intervalLoggingPeriodType = Common.TimePeriods.MINUTES; + intervalLoggingPeriod = 15; + intervalLoggingType = IntervalLoggingTypes.INSTANT; + tolerance = 0; + purgeType = Common.TimePeriods.YEARS; + purgePeriod = 1; + defaultCacheSize = 1; + discardExtremeValues = false; + discardLowLimit = -Double.MAX_VALUE; + discardHighLimit = Double.MAX_VALUE; + engineeringUnits = ENGINEERING_UNITS_DEFAULT; + } + private PointLocatorVO pointLocator; // From b4178885eeb3a04b71f63291cf68e77f3bb757e7 Mon Sep 17 00:00:00 2001 From: Artur Wolak Date: Mon, 7 Dec 2020 12:42:25 +0100 Subject: [PATCH 3/7] added API for defaultLoggingType --- src/com/serotonin/mango/vo/DataPointVO.java | 4 +- src/org/scada_lts/dao/SystemSettingsDAO.java | 3 ++ .../mango/service/SystemSettingsService.java | 12 ++++++ .../web/mvc/api/SystemSettingsAPI.java | 42 ++++++++++++++++++- 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/com/serotonin/mango/vo/DataPointVO.java b/src/com/serotonin/mango/vo/DataPointVO.java index 838942fa8c..9b780aef14 100644 --- a/src/com/serotonin/mango/vo/DataPointVO.java +++ b/src/com/serotonin/mango/vo/DataPointVO.java @@ -43,6 +43,7 @@ import com.serotonin.util.StringUtils; import com.serotonin.web.dwr.DwrResponseI18n; import com.serotonin.web.i18n.LocalizableMessage; +import org.scada_lts.dao.SystemSettingsDAO; import org.scada_lts.utils.ColorUtils; import java.io.IOException; @@ -165,7 +166,8 @@ public boolean isNew() { public DataPointVO(){ id = Common.NEW_ID; - loggingType = LoggingTypes.ON_CHANGE; + loggingType = SystemSettingsDAO + .getIntValue(SystemSettingsDAO.DEFAULT_LOGGING_TYPE); intervalLoggingPeriodType = Common.TimePeriods.MINUTES; intervalLoggingPeriod = 15; intervalLoggingType = IntervalLoggingTypes.INSTANT; diff --git a/src/org/scada_lts/dao/SystemSettingsDAO.java b/src/org/scada_lts/dao/SystemSettingsDAO.java index c8cbafa44a..d0354b4098 100644 --- a/src/org/scada_lts/dao/SystemSettingsDAO.java +++ b/src/org/scada_lts/dao/SystemSettingsDAO.java @@ -126,6 +126,9 @@ public class SystemSettingsDAO { private static final String DELETE_DATA_POINTS = "delete from dataPoints"; private static final String DELETE_DATA_SOURCES = "delete from dataSources"; + // Logging + public static final String DEFAULT_LOGGING_TYPE = "defaultLoggingType"; + // @formatter:off private static final String SELECT_SETTING_VALUE_WHERE = "" + "select " diff --git a/src/org/scada_lts/mango/service/SystemSettingsService.java b/src/org/scada_lts/mango/service/SystemSettingsService.java index fcd6a51034..ecde94b94b 100644 --- a/src/org/scada_lts/mango/service/SystemSettingsService.java +++ b/src/org/scada_lts/mango/service/SystemSettingsService.java @@ -1,6 +1,7 @@ package org.scada_lts.mango.service; import br.org.scadabr.db.configuration.ConfigurationDB; +import com.serotonin.bacnet4j.type.enumerated.LoggingType; import com.serotonin.mango.Common; import com.serotonin.mango.db.dao.DataPointDao; import com.serotonin.mango.db.dao.EventDao; @@ -8,6 +9,7 @@ import com.serotonin.mango.rt.event.type.SystemEventType; import com.serotonin.mango.rt.maint.DataPurge; import com.serotonin.mango.rt.maint.work.EmailWorkItem; +import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.User; import com.serotonin.mango.vo.bean.PointHistoryCount; import com.serotonin.mango.vo.event.EventTypeVO; @@ -54,6 +56,16 @@ public Map getSettings() { return settings; } + public Map getDefaultLoggingType() { + Map response = new HashMap<>(); + response.put("defaultLoggingType", DataPointVO.LoggingTypes.ON_CHANGE); + return response; + } + + public void setDefaultLoggingType(String defaultLoggingType) { + systemSettingsDAO.setValue(SystemSettingsDAO.DEFAULT_LOGGING_TYPE, defaultLoggingType); + } + public JsonSettingsEmail getEmailSettings() { JsonSettingsEmail json = new JsonSettingsEmail(); json.setAuth(SystemSettingsDAO.getBooleanValue(SystemSettingsDAO.EMAIL_AUTHORIZATION)); diff --git a/src/org/scada_lts/web/mvc/api/SystemSettingsAPI.java b/src/org/scada_lts/web/mvc/api/SystemSettingsAPI.java index 0e79e11132..46b0698d82 100644 --- a/src/org/scada_lts/web/mvc/api/SystemSettingsAPI.java +++ b/src/org/scada_lts/web/mvc/api/SystemSettingsAPI.java @@ -56,6 +56,46 @@ public ResponseEntity getSettings(HttpServletRequest request) { } } + @GetMapping(value = "/getDefaultLoggingType", produces = "application/json") + public ResponseEntity getLoggingType(HttpServletRequest request) { + LOG.info("/api/systemSettings/getDefaultLoggingType"); + try { + User user = Common.getUser(request); + if (user != null && user.isAdmin()) { + ObjectMapper mapper = new ObjectMapper(); + try { + String json = mapper.writeValueAsString(systemSettingsService.getDefaultLoggingType()); + return new ResponseEntity<>(json, HttpStatus.OK); + } catch (JsonProcessingException e) { + LOG.error(e); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + } else { + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } + } catch (Exception e) { + LOG.error(e); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + } + + @PostMapping(value = "/saveDefaultLoggingType/{defaultLoggingType}") + public ResponseEntity saveLoggingType(HttpServletRequest request, @PathVariable("defaultLoggingType") String defaultLoggingType) { + LOG.info("/api/systemSettings/saveLoggingType"); + try { + User user = Common.getUser(request); + if (user != null && user.isAdmin()) { + systemSettingsService.setDefaultLoggingType(defaultLoggingType); + return new ResponseEntity<>(SAVED_MSG, HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } + } catch (Exception e) { + LOG.error(e); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + } + @GetMapping(value = "/getEmail", produces = "application/json") public ResponseEntity getEmail(HttpServletRequest request) { LOG.info("/api/systemSettings/getEmail"); @@ -302,7 +342,7 @@ public ResponseEntity getDatabaseType(HttpServletRequest request) { } } - @GetMapping(value = "/saveDatabaseType/{databaseType}") + @PostMapping(value = "/saveDatabaseType/{databaseType}") public ResponseEntity saveDatabaseType(HttpServletRequest request, @PathVariable("databaseType") String databaseType) { LOG.info("/api/systemSettings/saveDatabaseType"); try { From b8661f40bd8374c91992c26ec8f11aaae30bb156 Mon Sep 17 00:00:00 2001 From: Artur Wolak Date: Mon, 7 Dec 2020 14:14:34 +0100 Subject: [PATCH 4/7] getDefaultLoggingType fix --- src/org/scada_lts/mango/service/SystemSettingsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/scada_lts/mango/service/SystemSettingsService.java b/src/org/scada_lts/mango/service/SystemSettingsService.java index ecde94b94b..27582bfa86 100644 --- a/src/org/scada_lts/mango/service/SystemSettingsService.java +++ b/src/org/scada_lts/mango/service/SystemSettingsService.java @@ -58,7 +58,7 @@ public Map getSettings() { public Map getDefaultLoggingType() { Map response = new HashMap<>(); - response.put("defaultLoggingType", DataPointVO.LoggingTypes.ON_CHANGE); + response.put("defaultLoggingType", SystemSettingsDAO.getIntValue(SystemSettingsDAO.DEFAULT_LOGGING_TYPE, DataPointVO.LoggingTypes.ON_CHANGE)); return response; } From 135f7fe76c32de4186b2df58c86889d8b8160939 Mon Sep 17 00:00:00 2001 From: Radek Jajko Date: Mon, 7 Dec 2020 16:03:12 +0100 Subject: [PATCH 5/7] Add Vue Unit tests for Default Logging Type Comp Simple Unit tests to validate functionality of that component. #1447 --- .../LoggingTypeSettings.spec.js | 76 +++++++++++++++++++ .../tests/unit/WatchListJsonChart.spec.js | 6 -- 2 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 scadalts-ui/tests/unit/SystemSettings/LoggingTypeSettings.spec.js diff --git a/scadalts-ui/tests/unit/SystemSettings/LoggingTypeSettings.spec.js b/scadalts-ui/tests/unit/SystemSettings/LoggingTypeSettings.spec.js new file mode 100644 index 0000000000..dffc820a29 --- /dev/null +++ b/scadalts-ui/tests/unit/SystemSettings/LoggingTypeSettings.spec.js @@ -0,0 +1,76 @@ + +import i18n from '@/i18n' + +import Vuex from 'vuex' +import { createLocalVue, mount } from '@vue/test-utils' +import DefaultLoggingTypeSettingsComponent from '@/views/SystemSettings/DefaultLoggTypeComponent' +import { expect } from 'chai' + +const localVue = createLocalVue(); +localVue.use(Vuex); + +const systemSettings = { + state: { + defaultLoggingType: 1 + }, + + mutations: { + setDefaultLoggingType(state, defaultLoggingType) { + state.defaultLoggingType = defaultLoggingType; + } + }, + + actions: { + getDefaultLoggingType(context) { + return new Promise(resolve => { + context.state.defaultLoggingType = 3; + resolve(3) + }) + }, + saveDefaultLoggingType(context) { + return new Promise(resolve => { + resolve(true) + }) + } + } +} + +const modules = { + systemSettings +} + + +const store = new Vuex.Store({modules}) + + +describe('SystemSettings - LoggingType Settings Tests', () => { + + const wrapper = mount(DefaultLoggingTypeSettingsComponent, { + store, localVue, i18n + }); + + it('Initialize Component', () => { + expect(wrapper.name()).to.equal('DefaultLoggingTypeSettingsComponent') + }) + + it('Test loading variable from Vuex store', () => { + expect(wrapper.vm.defaultLoggingType).to.equal(3); + expect(wrapper.vm.defaultLoggingTypeStore).to.equal(3); + }) + + it('Test i18n English Translation', () => { + expect(wrapper.findAll('option').at(1).html()).to.contain("All data") + expect(wrapper.findAll('option').at(2).html()).to.contain("Do not log") + }) + + it('Test value chagne', async () => { + wrapper.vm.defaultLoggingType = 5; + wrapper.vm.saveData(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.defaultLoggingType).to.equal(5); + expect(wrapper.vm.defaultLoggingTypeStore).to.equal(5); + }) + + }) + +}) \ No newline at end of file diff --git a/scadalts-ui/tests/unit/WatchListJsonChart.spec.js b/scadalts-ui/tests/unit/WatchListJsonChart.spec.js index a9f26e42d2..8f531b5f6c 100644 --- a/scadalts-ui/tests/unit/WatchListJsonChart.spec.js +++ b/scadalts-ui/tests/unit/WatchListJsonChart.spec.js @@ -60,10 +60,4 @@ describe('WatchListJsonChart.vue Test', () => { expect(wrapper.vm.chartType).to.equal('compare'); }) - it('Open chart settings', () => { - expect(wrapper.html()).not.contain('modal-body') - wrapper.find('i[class="glyphicon glyphicon-cog"]').trigger('click') - expect(wrapper.html()).contain('modal-body') - }) - }) \ No newline at end of file From a1087cb0d9c50e58f996a33b821a4e82d2171839 Mon Sep 17 00:00:00 2001 From: Radek Jajko Date: Tue, 8 Dec 2020 12:03:49 +0100 Subject: [PATCH 6/7] Added Unit and Cypress tests for Deff Logging Type Added required tests to check the functionality of the new implemented feature that allow users to change the Default Logging Type property for all new datapoints that are created by users. #1447 --- .../datasource_creation.spec.js | 51 +---------------- .../ScadaLTS_Views/system_settings.spec.js | 56 +++++++++++++++++++ scadalts-ui/cypress/utils/utils.js | 46 +++++++++++++++ scadalts-ui/src/README.md | 19 +++++++ .../DefaultLoggTypeComponent.vue | 2 +- .../LoggingTypeSettings.spec.js | 30 +++++++--- .../tests/unit/SystemSettings/README.md | 9 +++ 7 files changed, 157 insertions(+), 56 deletions(-) create mode 100644 scadalts-ui/cypress/utils/utils.js create mode 100644 scadalts-ui/src/README.md create mode 100644 scadalts-ui/tests/unit/SystemSettings/README.md diff --git a/scadalts-ui/cypress/integration/ScadaLTS_Views/datasource_creation.spec.js b/scadalts-ui/cypress/integration/ScadaLTS_Views/datasource_creation.spec.js index 6adc371162..4df1d59a1f 100644 --- a/scadalts-ui/cypress/integration/ScadaLTS_Views/datasource_creation.spec.js +++ b/scadalts-ui/cypress/integration/ScadaLTS_Views/datasource_creation.spec.js @@ -1,51 +1,6 @@ -context('Create Datasource', () => { - - function createVirtualDataSource(name) { - cy.visit('data_sources.shtm'); - cy.get("#dataSourceTypes").select('Virtual Data Source').should('have.value', '1'); - cy.get('img.ptr[src="images/icon_ds_add.png"]').first().click(); - cy.get('.smallTitle').should('contain', 'Virtual data source properties') - cy.get('#dataSourceName').type(name) - cy.get('#updatePeriods').type("{backspace}1").should('have.value', '1'); - cy.get('img.ptr[src="images/save.png"]').first().click(); - cy.get('#dataSourceMessage').should('contain', 'Data source has been saved') - // cy.debug('DataSource created!') - } +import {createVirtualDataSource, addVirtualDataPoint, login} from '../../utils/utils'; - /** - * - * @param {*} name DataPoint name - * @param {*} type [Multistate = 2| Numeric = 3] - */ - function addVirtualDataPoint(name, type) { - cy.get('img.ptr[src="images/icon_comp_add.png"]').click(); - cy.get('input#name').type(name) - cy.get('input#settable').click() - cy.get('select#dataTypeId').select(type) - if (type === '3') { - cy.wait(500) - cy.get('select#changeTypeId').select('Random') - cy.get('#divCH6').children().first().next().find('input').type("{backspace}20") - cy.get('#divCH6').children().first().next().next().find('input').type("2") - } else if (type === '2') { - cy.get('select#changeTypeId').select('8') - cy.get('input#randomMultistate').type("1") - for (let x = 1; x <= 5; x = x + 1) { - cy.get('img.ptr[src="images/add.png"]').click() - } - cy.get('select#randomMultistateChange.startValue').select('1') - } - cy.get('img.ptr#pointSaveImg').click() - cy.get('#pointMessage').should('contain', 'Point details saved') - // cy.debug(`DataPoint ${name} created!`) - } - - function login(username, password) { - cy.visit('/login.htm') - cy.get('input#username').type(username) - cy.get('input#password').type(password) - cy.get('.login-button > input').click() - } +context('Create Datasource', () => { before(() => { login("admin", "admin") @@ -58,7 +13,7 @@ context('Create Datasource', () => { cy.visit('/data_sources.shtm') createVirtualDataSource(`Test-${new Date().toISOString()}`) for (let i = 0; i < count; i = i + 1) { - addVirtualDataPoint(`0${i}-Test`, '3') + addVirtualDataPoint(`0${i}-Test`, 'Numeric') } cy.get('#pointsList').children().should('have.length', count) cy.get('img.ptr#enableAllImg').click(); diff --git a/scadalts-ui/cypress/integration/ScadaLTS_Views/system_settings.spec.js b/scadalts-ui/cypress/integration/ScadaLTS_Views/system_settings.spec.js index acaea145d2..9ce0de2d20 100644 --- a/scadalts-ui/cypress/integration/ScadaLTS_Views/system_settings.spec.js +++ b/scadalts-ui/cypress/integration/ScadaLTS_Views/system_settings.spec.js @@ -1,4 +1,5 @@ const { Context } = require("ag-grid-community"); +import {createVirtualDataSource, addVirtualDataPoint} from '../../utils/utils'; context('Test System Settings Vue.JS page', () => { @@ -60,4 +61,59 @@ context('Test System Settings Vue.JS page', () => { }) }) +}) + +context('Test System Settings Components functionality', () => { + + beforeEach(() => { + cy.clearCookies() + cy.visit('/login.htm') + cy.get('input#username').type("admin").should('have.value', 'admin') + cy.get('input#password').type("admin").should('have.value', 'admin') + cy.get('.login-button > input').click() + cy.location('pathname').should('include', 'watch_list') + }) + + describe("Test Default Logging Type Setting", () => { + + beforeEach(() => { + cy.visit('app.shtm#/system-settings') + }) + + it("Should be visible", () => { + cy.get('#default-logging-type-setting').should('be.visible'); + cy.get('#default-logging-type-setting > .align-items-center > .col-xs-12').should('contain', 'Default Data Point logging type'); + }) + + it("Save do not log value", () => { + let name = `Test_SystemSettings-${new Date().getTime()}`; + name = name.substring(0,30); + cy.get('.col-xs-12 > .form-control').select("Do not log"); + cy.get('.floated-right').click(); + cy.get('.btn-success').click(); + + createVirtualDataSource(name); + addVirtualDataPoint(`DP_${name}`, "Numeric") + + cy.get(':nth-child(5) > img[src="images/icon_comp_edit.png"]').click(); + cy.get('select#loggingType option[selected="selected"]').should('contain', 'Do not log'); + + }) + + it("Save do not log value", () => { + let name = `Test_SystemSettings2-${new Date().getTime()}`; + name = name.substring(0,30); + cy.get('.col-xs-12 > .form-control').select("When point value changes"); + cy.get('.floated-right').click(); + cy.get('.btn-success').click(); + + createVirtualDataSource(name); + addVirtualDataPoint(`DP_${name}`, "Numeric") + + cy.get(':nth-child(5) > img[src="images/icon_comp_edit.png"]').click(); + cy.get('select#loggingType option[selected="selected"]').should('contain', 'When point value changes'); + + }) + + }) }) \ No newline at end of file diff --git a/scadalts-ui/cypress/utils/utils.js b/scadalts-ui/cypress/utils/utils.js new file mode 100644 index 0000000000..75573d4f3d --- /dev/null +++ b/scadalts-ui/cypress/utils/utils.js @@ -0,0 +1,46 @@ +export function createVirtualDataSource(name) { + cy.visit('data_sources.shtm'); + cy.get("#dataSourceTypes").select('Virtual Data Source').should('have.value', '1'); + cy.get('img.ptr[src="images/icon_ds_add.png"]').first().click(); + cy.get('.smallTitle').should('contain', 'Virtual data source properties') + cy.get('#dataSourceName').type(name) + cy.get('#updatePeriods').type("{backspace}1").should('have.value', '1'); + cy.get('img.ptr[src="images/save.png"]').first().click(); + cy.get('#dataSourceMessage').should('contain', 'Data source has been saved') + // cy.debug('DataSource created!') +} + + /** + * + * @param {*} name DataPoint name + * @param {*} type [Multistate = 2| Numeric = 3] + */ +export function addVirtualDataPoint(name, type) { + cy.get('img.ptr[src="images/icon_comp_add.png"]').click(); + cy.get('input#name').type(name) + cy.get('input#settable').click() + cy.get('select#dataTypeId').select(type) + if (type === 'Numeric') { + cy.wait(500) + cy.get('select#changeTypeId').select('Random') + cy.get('#divCH6').children().first().next().find('input').type("{backspace}20") + cy.get('#divCH6').children().first().next().next().find('input').type("2") + } else if (type === 'Multistate') { + cy.get('select#changeTypeId').select('8') + cy.get('input#randomMultistate').type("1") + for (let x = 1; x <= 5; x = x + 1) { + cy.get('img.ptr[src="images/add.png"]').click() + } + cy.get('select#randomMultistateChange.startValue').select('1') + } + cy.get('img.ptr#pointSaveImg').click() + cy.get('#pointMessage').should('contain', 'Point details saved') + // cy.debug(`DataPoint ${name} created!`) +} + +export function login(username, password) { + cy.visit('/login.htm') + cy.get('input#username').type(username) + cy.get('input#password').type(password) + cy.get('.login-button > input').click() +} \ No newline at end of file diff --git a/scadalts-ui/src/README.md b/scadalts-ui/src/README.md new file mode 100644 index 0000000000..20460266cc --- /dev/null +++ b/scadalts-ui/src/README.md @@ -0,0 +1,19 @@ +# Scada-LTS User Interface +## Vue.js subproject for Views and Components + +## Description + +User Interface subproject to display ScadaLTS content. + +## Usage + +- To start a developmnent server type inside this directory: `npm run-script serve` +- To run unit test type: `npm run-script test:unit` +- To run E2E cypress tests type: `npm run-script test:e2e` +- To run Cypress testing framework type: `npm run-script cypress` + +## Creators +Developers from Scada-LTS project: +- @grzesiekb +- @radek2s + diff --git a/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue b/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue index ac1e48176d..453dc3c8c9 100644 --- a/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue +++ b/scadalts-ui/src/views/SystemSettings/DefaultLoggTypeComponent.vue @@ -1,5 +1,5 @@