Skip to content

Commit

Permalink
add initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErickWendel committed Jul 23, 2024
1 parent 0cfec2d commit b9b3efc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:1880',
testIsolation: false,
// testIsolation: false,
supportFile: false,
},
});
121 changes: 107 additions & 14 deletions cypress/e2e/app.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const spreadsheet = require('./../../spreadsheet.json')
class NodeRedEditor {
elements = {
focusedNode: () => cy.get('.red-ui-flow-node'),
nodeSearchInput: () => cy.get('#red-ui-type-search-input'),
nodeSearchInput: () => cy.get('#red-ui-type-search-input', { force: true }),
inputLabel: () => cy.get('#node-input-name'),
sheetsToJSON: {
sheetIdInput: () => cy.get('#node-input-sheetId'),
sheetListInput: () => cy.get('#node-input-sheetList'),
Expand All @@ -14,23 +15,83 @@ class NodeRedEditor {
configArea: () => cy.get('#node-config-input-config'),
},
},
httpIn: {
urlInput: () => cy.get('#node-input-url')
},
workspaceArea: () => cy.get('#red-ui-workspace-chart') // Adjust the selector to match the main editor area
}

successfullyAutoComplete() {

}
}
const editor = new NodeRedEditor();

// Generate unique IDs and names for the nodes
const generateRandomId = () => 'node-' + Math.random().toString(36).substr(2, 9);
const generateRandomName = (base, id) => base + '-' + id;

const httpInNodeId = generateRandomId();
const sheetsToJsonStreamNodeId = generateRandomId();
const httpResponseNodeId = generateRandomId();

const httpInNode = {
id: httpInNodeId,
type: 'http in',
name: generateRandomName('HTTP In', httpInNodeId),
url: '/sheets',
method: 'get',
x: 200,
y: 200,
wires: [[sheetsToJsonStreamNodeId]]
};

const sheetsToJsonStreamNode = {
id: sheetsToJsonStreamNodeId,
type: 'sheets-to-json-stream',
name: generateRandomName('Sheets to JSON Stream', sheetsToJsonStreamNodeId),
x: 250,
y: 250,
wires: [[httpResponseNodeId]]
};

const httpResponseNode = {
id: httpResponseNodeId,
type: 'http response',
name: generateRandomName('HTTP Response', httpResponseNodeId),
x: 350,
y: 300,
wires: [[]]
};


async function insertNodes(nodes) {
const insertRequest = await fetch('http://localhost:1880/flows', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(nodes)
});

// const response = await fetch('http://localhost:1880/flows')
// return response.json()
// cy.
}

// Usage in a test case
describe('Node-RED Interface', () => {
const editor = new NodeRedEditor();
function addSheetsNodeAndOpen() {
function addNodeAndOpen(nodeName) {
editor.elements.workspaceArea().click({ metaKey: true })
editor.elements.nodeSearchInput().type('sheets').type('{meta}').type('{enter}')
editor.elements.nodeSearchInput().type(nodeName).type('{meta}{enter}')
editor.elements.focusedNode().dblclick({ force: true })
const nodeId = `node-${Date.now()}`
editor.elements.inputLabel().type(nodeId)
cy.wait(500)

return nodeId
}

function addValidConfig() {
editor.elements.sheetsToJSON.addNewConfigInputBtn().click();

Expand All @@ -39,25 +100,34 @@ describe('Node-RED Interface', () => {
editor.elements.sheetsToJSON.gAuth.configArea().invoke('val', JSON.stringify(spreadsheet.googleAuthCredentials))
.type('{meta}{enter}');
}
function resetChart() {
editor.elements.workspaceArea().type('{meta}a').type('{del}').type('{meta}d')
return cy.wait(500);
}

beforeEach(() => {
// Navigate to the base URL before each test
cy.visit('/');
});
cy.visit('/').then(() => {
cy.get('body').should('be.visible');
return resetChart().then(() => {
return insertNodes([httpInNode, sheetsToJsonStreamNode, httpResponseNode])
})

it('should load the Node-RED interface', () => {
// Check if the page contains the Node-RED header
cy.contains('Node-RED');
});
});

it('should search for the Sheets module and add it to the workspace', () => {

it('should load sheets data and have values accourding to config', () => {
cy.viewport(1920, 735)
cy.visit('/')
cy.visit('/');


cy.get(`#${sheetsToJsonStreamNode.id}`).should('exist');
cy.get(`#${sheetsToJsonStreamNode.id}`).dblclick();

addSheetsNodeAndOpen()
addValidConfig();

editor.elements.sheetsToJSON.sheetIdInput().type(spreadsheet.spreadsheetId).type('{enter}')

cy.wait(500);
editor.elements.sheetsToJSON.sheetListInput()
.children('option')
Expand All @@ -70,9 +140,32 @@ describe('Node-RED Interface', () => {

editor.elements.sheetsToJSON.rangeInput().should('have.value', spreadsheet.range)
editor.elements.sheetsToJSON.columnsInput().should('have.value', JSON.stringify(spreadsheet.columns))

editor.elements.inputLabel().type('{meta}{enter}')
})

// it('should load sheets data and have values accourding to config', () => {

// cy.viewport(1920, 735)
// cy.visit('/').then(async () => {

// // resetChart()

// // const httpInId = addNodeAndOpen('http in')
// // editor.elements.httpIn.urlInput().type('/sheets')
// // editor.elements.httpIn.urlInput().type('{meta}{enter}')
// // cy.wait(200)
// // editor.elements.workspaceArea().type('{meta}d')
// // cy.wait(500)

// // const httpResponseId = addNodeAndOpen('http response')
// // cy.wait(500)
// // editor.elements.inputLabel().type('{meta}{enter}')


// })

// })



});
Expand Down
1 change: 1 addition & 0 deletions misc/install-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if [ $? -ne 0 ]; then
fi

# cp misc/flows.json misc/data/flows.json
cp misc/settings.js misc/data/settings.js

# Change directory to misc/data
cd misc/data || exit 1
Expand Down
9 changes: 9 additions & 0 deletions misc/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
editorTheme: {
tours: false,
projects: {
enabled: false
},
},
userDir: "/data",
};

0 comments on commit b9b3efc

Please sign in to comment.