Skip to content

Commit

Permalink
chore: fix all linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: 12fab4 <[email protected]>
  • Loading branch information
12fab4 committed Feb 20, 2025
1 parent 54b15bf commit b08b05f
Show file tree
Hide file tree
Showing 40 changed files with 1,051 additions and 1,044 deletions.
27 changes: 14 additions & 13 deletions build-tools/fetch-schemas-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ export function vitePluginFetchSchemas() {
};
}

function sha256(data: string,): string {
return crypto.createHash("sha256",).update(data, "utf8",).digest("hex",);
function sha256( data: string, ): string {
return crypto.createHash( "sha256", ).update( data, "utf8", )
.digest( "hex", );
}

export function fetchRemoteSchemas() {
remoteSchemas.forEach(async (schema,) => {
if (!fs.existsSync(`./public/schemas/${schema.name}.json`,)) {
const fetchedSchemaYAML = await fetch(schema.url,).then((res,) => res.text(),);
const fetchedSchemaHash = sha256(fetchedSchemaYAML,);
if (fetchedSchemaHash !== schema.hash) {
throw new Error(`Schema hash mismatch for ${schema.url}. Expected: ${schema.hash}, got: ${fetchedSchemaHash}`,);
remoteSchemas.forEach( async ( schema, ) => {
if ( !fs.existsSync( `./public/schemas/${schema.name}.json`, ) ) {

Check warning on line 25 in build-tools/fetch-schemas-plugin.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build-tools/fetch-schemas-plugin.ts#L25

The application dynamically constructs file or path information.
const fetchedSchemaYAML = await fetch( schema.url, ).then( ( res, ) => res.text(), );
const fetchedSchemaHash = sha256( fetchedSchemaYAML, );
if ( fetchedSchemaHash !== schema.hash ) {
throw new Error( `Schema hash mismatch for ${schema.url}. Expected: ${schema.hash}, got: ${fetchedSchemaHash}`, );
}
const schemaJSON = yaml.load(fetchedSchemaYAML,);
const schemaJSON = yaml.load( fetchedSchemaYAML, );

Check failure on line 31 in build-tools/fetch-schemas-plugin.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build-tools/fetch-schemas-plugin.ts#L31

User controlled data in 'yaml.load()' function can result in Remote Code Injection.

schema.hash = fetchedSchemaHash;
fs.mkdirSync("./public/schemas", { recursive: true, },);
fs.writeFileSync(`./public/schemas/${schema.name}.json`, JSON.stringify(schemaJSON,),);
fs.mkdirSync( "./public/schemas", { recursive: true, }, );
fs.writeFileSync( `./public/schemas/${schema.name}.json`, JSON.stringify( schemaJSON, ), );

Check warning on line 35 in build-tools/fetch-schemas-plugin.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

build-tools/fetch-schemas-plugin.ts#L35

The application dynamically constructs file or path information.

console.log(`${schema.url} fetched and cached successfully.`,);
console.log( `${schema.url} fetched and cached successfully.`, );
}
},);
}, );
}
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest
import { defineConfig, } from "cypress";

export default defineConfig({
export default defineConfig( {
e2e: {
baseUrl: "http://127.0.0.1:8080",
},
},);
}, );
19 changes: 10 additions & 9 deletions cypress/e2e/config-management.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest
import { faker, } from "@faker-js/faker";

describe("ConfigManagement", () => {
it("should be possible to create and save a new config", () => {
describe( "ConfigManagement", () => {
it( "should be possible to create and save a new config", () => {
cy.connectToSimulator();
const configName = faker.word.words(1,);
cy.createConfig(configName,);
cy.get("#config-save-button",).click();
cy.get('[data-cy="configs-expansion-panel"]',).click();
cy.get('[data-cy="config-list-item"]',).contains(configName,).should("be.visible",);
},);
},);
const configName = faker.word.words( 1, );
cy.createConfig( configName, );
cy.get( "#config-save-button", ).click();
cy.get( '[data-cy="configs-expansion-panel"]', ).click();
cy.get( '[data-cy="config-list-item"]', ).contains( configName, )
.should( "be.visible", );
}, );
}, );
109 changes: 57 additions & 52 deletions cypress/e2e/connect-screen.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,76 @@
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest
import { faker, } from "@faker-js/faker";

describe("Connect-Screen", () => {
beforeEach(() => {
describe( "Connect-Screen", () => {
beforeEach( () => {
cy.clearAllLocalStorage();
},);
}, );

it("should load connect screen by default", () => {
cy.visit("/",);
cy.get('[data-cy="add-everest-instance"]',).should("be.visible",);
},);
it( "should load connect screen by default", () => {
cy.visit( "/", );
cy.get( '[data-cy="add-everest-instance"]', ).should( "be.visible", );
}, );

it("should be possible to create, edit and delete an Everest instance", () => {
cy.visit("/",);
it( "should be possible to create, edit and delete an Everest instance", () => {
cy.visit( "/", );
// add instance
cy.get('[data-cy="add-everest-instance"]',).click();
cy.get('[data-cy="delete-instance"]',).should("not.exist",);
const instanceName = faker.word.words(2,);
cy.get('[data-cy="instance-name-field"]',).type(instanceName,);
cy.get('[data-cy="host-address-field"]',).type("localhost",);
cy.get('[data-cy="port-field"]',).clear().type("8080",);
cy.get('[data-cy="save-instance"]',).click();
cy.get('[data-cy="server-list-item"]',).contains(instanceName,).should("be.visible",);
cy.get( '[data-cy="add-everest-instance"]', ).click();
cy.get( '[data-cy="delete-instance"]', ).should( "not.exist", );
const instanceName = faker.word.words( 2, );
cy.get( '[data-cy="instance-name-field"]', ).type( instanceName, );
cy.get( '[data-cy="host-address-field"]', ).type( "localhost", );
cy.get( '[data-cy="port-field"]', ).clear()
.type( "8080", );
cy.get( '[data-cy="save-instance"]', ).click();
cy.get( '[data-cy="server-list-item"]', ).contains( instanceName, )
.should( "be.visible", );

// edit instance
cy.get('[data-cy="server-list-item"]',)
.contains(instanceName,)
.parentsUntil(".v-list-subheader__text",)
.find('[data-cy="edit-instance"]',)
cy.get( '[data-cy="server-list-item"]', )
.contains( instanceName, )
.parentsUntil( ".v-list-subheader__text", )
.find( '[data-cy="edit-instance"]', )
.click();
const newInstanceName = faker.word.words(2,);
cy.get('[data-cy="instance-name-field"]',).type(`{selectall}{backspace}${newInstanceName}`,);
cy.get('[data-cy="save-instance"]',).click();
cy.get('[data-cy="server-list-item"]',)
.contains(newInstanceName,)
.should("be.visible",);
cy.get('[data-cy="server-list-item"]',)
.contains(instanceName,)
.should("not.exist",);
const newInstanceName = faker.word.words( 2, );
cy.get( '[data-cy="instance-name-field"]', ).type( `{selectall}{backspace}${newInstanceName}`, );
cy.get( '[data-cy="save-instance"]', ).click();
cy.get( '[data-cy="server-list-item"]', )
.contains( newInstanceName, )
.should( "be.visible", );
cy.get( '[data-cy="server-list-item"]', )
.contains( instanceName, )
.should( "not.exist", );


// delete instance
cy.get('[data-cy="server-list-item"]',)
.contains(newInstanceName,)
.parentsUntil(".v-list-subheader__text",)
.find('[data-cy="edit-instance"]',)
cy.get( '[data-cy="server-list-item"]', )
.contains( newInstanceName, )
.parentsUntil( ".v-list-subheader__text", )
.find( '[data-cy="edit-instance"]', )
.click();
cy.get('[data-cy="delete-instance"]',).click();
cy.get('[data-cy="server-list-item"]',)
.contains(instanceName,)
.should("not.exist",);
},);
cy.get( '[data-cy="delete-instance"]', ).click();
cy.get( '[data-cy="server-list-item"]', )
.contains( instanceName, )
.should( "not.exist", );
}, );

it("should automatically connect if autoConnect is set to true", () => {
cy.visit("/",);
cy.get('[data-cy="auto-connect-checkbox',).click();
cy.get('[data-cy="server-list-item',).contains("Simulator",).click();
cy.get('[data-cy="hamburger-menu"]',).click();
cy.get('[data-cy="switch-instance"]',).click();
it( "should automatically connect if autoConnect is set to true", () => {
cy.visit( "/", );
cy.get( '[data-cy="auto-connect-checkbox', ).click();
cy.get( '[data-cy="server-list-item', ).contains( "Simulator", )
.click();
cy.get( '[data-cy="hamburger-menu"]', ).click();
cy.get( '[data-cy="switch-instance"]', ).click();

// should not reconnect automatically after switching instance, only on page reload
cy.get('[data-cy="server-list-item"]', { timeout: 6000, },).contains("Simulator",).should("be.visible",);
cy.wait(1000,);
cy.get('[data-cy="server-list-item"]',).contains("Simulator",).should("be.visible",);
cy.get( '[data-cy="server-list-item"]', { timeout: 6000, }, ).contains( "Simulator", )
.should( "be.visible", );
cy.wait( 1000, );
cy.get( '[data-cy="server-list-item"]', ).contains( "Simulator", )
.should( "be.visible", );

// check if automatically reconnected
cy.visit("/",);
cy.get('[data-cy="hamburger-menu"]', { timeout: 6000, },).should("be.visible",);
},);
},);
cy.visit( "/", );
cy.get( '[data-cy="hamburger-menu"]', { timeout: 6000, }, ).should( "be.visible", );
}, );
}, );
19 changes: 10 additions & 9 deletions cypress/e2e/module-selection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import { faker, } from "@faker-js/faker";

describe("Module Selection", () => {
it("should be possible to search for EvseManager", () => {
describe( "Module Selection", () => {
it( "should be possible to search for EvseManager", () => {
cy.connectToSimulator();
cy.createConfig(faker.word.words(1,),);
cy.get('[data-cy="modules-search"]',).type("EvseManager",);
cy.get('[data-cy="module-list-item"]',).contains("EvseManager",).should("be.visible",);
cy.get('[data-cy="modules-search"]',).type("{selectall}{backspace}LoremIpsumDolorModule",);
cy.get('[data-cy="module-list-item"]',).should("not.exist",);
},);
},);
cy.createConfig( faker.word.words( 1, ), );
cy.get( '[data-cy="modules-search"]', ).type( "EvseManager", );
cy.get( '[data-cy="module-list-item"]', ).contains( "EvseManager", )
.should( "be.visible", );
cy.get( '[data-cy="modules-search"]', ).type( "{selectall}{backspace}LoremIpsumDolorModule", );
cy.get( '[data-cy="module-list-item"]', ).should( "not.exist", );
}, );
}, );
23 changes: 12 additions & 11 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ declare global {
namespace Cypress {
interface Chainable {
connectToSimulator(): Chainable<void>;
createConfig(name: string): Chainable<void>;
createConfig( name: string ): Chainable<void>;
}
}
}

Cypress.Commands.add("connectToSimulator", () => {
cy.visit("/",);
cy.get('[data-cy="server-list-item',).contains("Simulator",).click();
cy.get('[data-cy="hamburger-menu"]',).should("be.visible",);
},);
Cypress.Commands.add( "connectToSimulator", () => {
cy.visit( "/", );
cy.get( '[data-cy="server-list-item', ).contains( "Simulator", )
.click();
cy.get( '[data-cy="hamburger-menu"]', ).should( "be.visible", );
}, );

Cypress.Commands.add("createConfig", (name,) => {
cy.get('[data-cy="plus-create-config-btn"]',).click();
cy.get('[data-cy="config-name-input"]',).type(name,);
cy.get('[data-cy="accept-create-config-btn"]',).click();
},);
Cypress.Commands.add( "createConfig", ( name, ) => {
cy.get( '[data-cy="plus-create-config-btn"]', ).click();
cy.get( '[data-cy="config-name-input"]', ).type( name, );
cy.get( '[data-cy="accept-create-config-btn"]', ).click();
}, );
34 changes: 17 additions & 17 deletions src/components/ConfigPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ import { computed, inject, ref, } from "vue";
import { Notyf, } from "notyf";
import yaml from "js-yaml";

const notyf = inject<Notyf>("notyf",);
const dialogVisible = ref<boolean>(false,);
const notyf = inject<Notyf>( "notyf", );
const dialogVisible = ref<boolean>( false, );

const closeDialog = () => {
dialogVisible.value = false;
Expand All @@ -87,46 +87,46 @@ const props = defineProps<{
config: EVConfigModel,
}>();

const tab = ref("yaml",);
const tab = ref( "yaml", );

const jsonCode = computed(() => JSON.stringify(props.config.serialize(), null, 2,),);
const yamlCode = computed(() => yaml.dump(props.config.serialize(),),);
const jsonCode = computed( () => JSON.stringify( props.config.serialize(), null, 2, ), );
const yamlCode = computed( () => yaml.dump( props.config.serialize(), ), );

const downloadConfig = () => {
let filename = "";
let contentType = "";
let content = "";

if (tab.value === "json") {
if ( tab.value === "json" ) {
filename = `${props.config._name}.json`;
contentType = "application/json";
content = jsonCode.value;
} else if (tab.value === "yaml") {
} else if ( tab.value === "yaml" ) {
filename = `${props.config._name}.yaml`;
contentType = "text/yaml";
content = yamlCode.value;
}

const blob = new Blob([ content, ], { type: contentType, },);
const url = URL.createObjectURL(blob,);
const a = document.createElement("a",);
const blob = new Blob( [ content, ], { type: contentType, }, );
const url = URL.createObjectURL( blob, );
const a = document.createElement( "a", );
a.href = url;
a.download = filename;
document.body.appendChild(a,); // This line is necessary for the Firefox browser
document.body.appendChild( a, ); // This line is necessary for the Firefox browser
a.click();
document.body.removeChild(a,); // Clean up
URL.revokeObjectURL(url,); // Free up memory
document.body.removeChild( a, ); // Clean up
URL.revokeObjectURL( url, ); // Free up memory
};

const copyConfig = () => {
let content = "";
if (tab.value === "json") {
if ( tab.value === "json" ) {
content = jsonCode.value;
} else if (tab.value === "yaml") {
} else if ( tab.value === "yaml" ) {
content = yamlCode.value;
}
navigator.clipboard.writeText(content,);
notyf.success("Copied to clipboard!",);
navigator.clipboard.writeText( content, );
notyf.success( "Copied to clipboard!", );
};

</script>
Expand Down
Loading

0 comments on commit b08b05f

Please sign in to comment.