Skip to content

Commit

Permalink
add user module (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Templada authored and cvakiitho committed Nov 18, 2024
1 parent 1b086aa commit 721136c
Show file tree
Hide file tree
Showing 22 changed files with 513 additions and 50 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
"test:reuse:util:component": "npx wdio ./test/reuse/util/component/test.component.conf.js",
"test:reuse:util:file": "npx wdio ./test/reuse/util/file/test.file.conf.js",
"test:reuse:util:console": "npx wdio ./test/reuse/util/console/test.console.conf.js",
"test:reuse:util:system": "npx wdio ./test/reuse/util/system/test.system.conf.js",
"test:reuse:util:formatter": "npx wdio ./test/reuse/util/formatter/test.formatter.conf.js",
"test:reuse:util:system": "npx wdio ./test/reuse/util/system/test.system.conf.js",
"test:reuse:util:userSettings": "npx wdio ./test/reuse/util/userSettings/test.userSettings.apply.conf.js && npx wdio ./test/reuse/util/userSettings/test.userSettings.conf.js",
"test:reuse:util": "npm run test:reuse:util:browser && npm run test:reuse:util:browserCmndLineArgs && npm run test:reuse:util:data && npm run test:reuse:util:file && npm run test:reuse:util:formatter && npm run test:reuse:util:system && npm run test:reuse:util:console && npm run test:reuse:util:component",
"test:reuse:common:assertion": "npx wdio ./test/reuse/common/assertion/test.assertion.conf.js",
"test:reuse:common:navigation": "npx wdio ./test/reuse/common/navigation/test.navigation.conf.js",
Expand Down
3 changes: 2 additions & 1 deletion src/reuse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ReuseLibrary {
formatter: utilQmate.formatter,
function: utilQmate.function,
system: utilQmate.system,
component: utilQmate.component
component: utilQmate.component,
userSettings: utilQmate.userSettings
};
global.util = {
...util,
Expand Down
18 changes: 9 additions & 9 deletions src/reuse/modules/common/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getToday("mm/dd/yyyy");
*/
getToday(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getToday(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getToday);
const date = new Date();
vl.log(date.toISOString());
Expand All @@ -38,7 +38,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getTomorrow("mm/dd/yyyy");
*/
getTomorrow(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getTomorrow(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getTomorrow);
const date = new Date();
date.setDate(date.getDate() + 1);
Expand All @@ -54,7 +54,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getNextMonth("mm/dd/yyyy");
*/
getNextMonth(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getNextMonth(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getTomorrow);
const date = new Date();
date.setMonth(date.getMonth() + 1);
Expand All @@ -70,7 +70,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getPreviousMonth("mm/dd/yyyy");
*/
getPreviousMonth(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getPreviousMonth(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getPreviousMonth);
const date = new Date();
date.setMonth(date.getMonth() - 1);
Expand All @@ -86,7 +86,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getNextYear("mm/dd/yyyy");
*/
getNextYear(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getNextYear(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getNextYear);
const date = new Date();
date.setFullYear(date.getFullYear() + 1);
Expand All @@ -102,7 +102,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getPreviousYear("mm/dd/yyyy");
*/
getPreviousYear(format: DateFormatsType = DateFormats.OBJECT): Date | string {
getPreviousYear(format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getPreviousYear);
const date = new Date();
date.setFullYear(date.getFullYear() - 1);
Expand All @@ -119,7 +119,7 @@ export class DateModule {
* @returns {String} The date in the given format.
* @example const date = await common.date.getSpecific("2020, 0, 17", "mm/dd/yyyy");
*/
getSpecific(date: string, format: DateFormatsType = DateFormats.OBJECT): Date | string {
getSpecific(date: string, format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.getSpecific);
if (!date) {
throw new Error("Function 'getSpecific' failed: Please provide a date string ('2020, 0, 17') as first argument.");
Expand All @@ -136,10 +136,10 @@ export class DateModule {
* @description Calculates the date based on the input parameter and returns it in the given format.
* @param {String} [date="today"] - Supported values: today, tomorrow, nextMonth, previousMonth, nextYear, previousYear
* @param {String} [format="object"] - The expected format ("mm/dd/yyyy", "dd.mm.yyyy", "dd/mm/yyyy", "yyyymmdd", "yyyy/mm/dd", "mmm dd, yyyy", "mmm d, yyyy", "datetime", "object").
* @returns {String} The calculated date in the given format.
* @returns {String | Date} The calculated date in the given format.
* @example const date = await common.date.calculate("today", "mm/dd/yyyy");
*/
calculate(date: CalculateDatesType = CalculateDates.TODAY, format: DateFormatsType = DateFormats.OBJECT): Date | string {
calculate(date: CalculateDatesType = CalculateDates.TODAY, format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT): Date | string {
const vl = this.vlf.initLog(this.calculate);
if (date === null) {
date = CalculateDates.TODAY;
Expand Down
3 changes: 3 additions & 0 deletions src/reuse/modules/ui5/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ export class Session {
util.console.warn(error.toString());
}
}
if (browser.config.params.applyS4UserSettings === true) {
await util.userSettings.setS4UserSettings(username, password);
}
}

private async _clickSignOut() {
Expand Down
3 changes: 3 additions & 0 deletions src/reuse/modules/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import formatter, { Formatter } from "./formatter";
import functionModule, { FunctionModule } from "./function";
import system, { System } from "./system";
import component, { Component } from "./component";
import userSettings, { UserSettings } from "./userSettings";


interface DataHooksExtended extends Data {
decrypt: (input: string | Array<string>) => string;
Expand All @@ -21,6 +23,7 @@ export class Util {
function: FunctionModule = functionModule;
system: System = system;
component: Component = component;
userSettings: UserSettings = userSettings;
}

export default new Util();
10 changes: 8 additions & 2 deletions src/reuse/modules/util/constants/formatter.constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
export enum DateFormats {
MONTH_DAY_YEAR_SLASH = "mm/dd/yyyy",
MONTH_DAY_YEAR_DASH = "mm-dd-yyyy",
DAY_MONTH_YEAR_DOT = "dd.mm.yyyy",
DAY_MONTH_YEAR_SLASH = "dd/mm/yyyy",
YEAR_MONTH_DAY_PLAIN = "yyyymmdd",
YEAR_MONTH_DAY_SLASH = "yyyy/mm/dd",
YEAR_MONTH_DAY_DOT = "yyyy.mm.dd",
YEAR_MONTH_DAY_DASH = "yyyy-mm-dd",
DAY_MONTH_YEAR_TIME_DOT = "dd.mm.yyyy.hh.mm",
MONTH_DAY_YEAR_COMMA = "mmm dd, yyyy",
MONTH_DAY_YEAR_COMMA_SHORT = "mmm d, yyyy",
DATETIME = "datetime",
OBJECT = "object"
}
OBJECT = "object",
JAPANESE_DOT = "g.yy.mm.dd",
JAPANESE_SLASH = "g/yy/mm/dd",
JAPANESE_DASH = "g-yy-mm-dd",
}
84 changes: 51 additions & 33 deletions src/reuse/modules/util/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class Formatter {
* const formattedDate = util.formatter.formatDate(date, "mmm dd, yyyy");
* // returns "Apr 03, 2022"
*/
formatDate(date: Date, format: DateFormatsType, locale = "en-US"): string | Date {
formatDate(date: Date, format: DateFormatsType = process.env.USER_SETTINGS_DATE_FORMAT ? (process.env.USER_SETTINGS_DATE_FORMAT as DateFormatsType) : DateFormats.OBJECT, locale = "en-US"): string | Date {
if (format) {
format = format.toLowerCase() as DateFormats;
}
Expand Down Expand Up @@ -179,38 +179,56 @@ export class Formatter {

if (format) {
switch (format) {
case DateFormats.MONTH_DAY_YEAR_SLASH:
formattedDate = `${mm}/${dd}/${yyyy}`;
break;
case DateFormats.DAY_MONTH_YEAR_DOT:
formattedDate = `${dd}.${mm}.${yyyy}`;
break;
case DateFormats.DAY_MONTH_YEAR_SLASH:
formattedDate = `${dd}/${mm}/${yyyy}`;
break;
case DateFormats.YEAR_MONTH_DAY_PLAIN:
formattedDate = `${yyyy}${mm}${dd}`;
break;
case DateFormats.YEAR_MONTH_DAY_SLASH:
formattedDate = `${yyyy}/${mm}/${dd}`;
break;
case DateFormats.DAY_MONTH_YEAR_TIME_DOT:
formattedDate = `${dd}.${mm}.${yyyy}.${hour}.${min}`;
break;
case DateFormats.MONTH_DAY_YEAR_COMMA:
formattedDate = `${month} ${dd}, ${yyyy}`;
break;
case DateFormats.MONTH_DAY_YEAR_COMMA_SHORT:
formattedDate = `${month} ${dd}, ${yyyy}`;
break;
case DateFormats.DATETIME:
formattedDate = `datetime'${yyyy}-${mm}-${dd}T${hour}:${min}:${sec}'`;
break;
case DateFormats.OBJECT:
formattedDate = date;
break;
default:
break;
case DateFormats.MONTH_DAY_YEAR_SLASH:
formattedDate = `${mm}/${dd}/${yyyy}`;
break;
case DateFormats.MONTH_DAY_YEAR_DASH:
formattedDate = `${mm}-${dd}-${yyyy}`;
break;
case DateFormats.DAY_MONTH_YEAR_DOT:
formattedDate = `${dd}.${mm}.${yyyy}`;
break;
case DateFormats.DAY_MONTH_YEAR_SLASH:
formattedDate = `${dd}/${mm}/${yyyy}`;
break;
case DateFormats.YEAR_MONTH_DAY_PLAIN:
formattedDate = `${yyyy}${mm}${dd}`;
break;
case DateFormats.YEAR_MONTH_DAY_SLASH:
formattedDate = `${yyyy}/${mm}/${dd}`;
break;
case DateFormats.YEAR_MONTH_DAY_DOT:
formattedDate = `${yyyy}.${mm}.${dd}`;
break;
case DateFormats.YEAR_MONTH_DAY_DASH:
formattedDate = `${yyyy}-${mm}-${dd}`;
break;
case DateFormats.DAY_MONTH_YEAR_TIME_DOT:
formattedDate = `${dd}.${mm}.${yyyy}.${hour}.${min}`;
break;
case DateFormats.MONTH_DAY_YEAR_COMMA:
formattedDate = `${month} ${dd}, ${yyyy}`;
break;
case DateFormats.MONTH_DAY_YEAR_COMMA_SHORT:
formattedDate = `${month} ${dd}, ${yyyy}`;
break;
case DateFormats.DATETIME:
formattedDate = `datetime'${yyyy}-${mm}-${dd}T${hour}:${min}:${sec}'`;
break;
case DateFormats.OBJECT:
formattedDate = date;
break;
case DateFormats.JAPANESE_DOT:
formattedDate = `${date.toLocaleDateString(locale, { era: "short" })}.${mm}.${dd}`;
break;
case DateFormats.JAPANESE_SLASH:
formattedDate = `${date.toLocaleDateString(locale, { era: "short" })}/${mm}/${dd}`;
break;
case DateFormats.JAPANESE_DASH:
formattedDate = `${date.toLocaleDateString(locale, { era: "short" })}-${mm}-${dd}`;
break;
default:
break;
}
}

Expand Down
Loading

0 comments on commit 721136c

Please sign in to comment.