added tests
This commit is contained in:
parent
655bfcc4a3
commit
c63e2dabb6
6 changed files with 49 additions and 6 deletions
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "Using fixtures to represent data",
|
||||
"email": "hello@cypress.io",
|
||||
"body": "Fixtures are a great way to mock data for responses to routes"
|
||||
}
|
||||
|
|
@ -14,3 +14,32 @@ describe('draw a vector', () => {
|
|||
cy.get('#2').invoke('attr','d').should('eq','M550 350 L500 200');
|
||||
})
|
||||
})
|
||||
|
||||
describe('draw a lazy vector', () => {
|
||||
it('adds the svg vector', () => {
|
||||
cy.visit('http://localhost:8080');
|
||||
|
||||
cy.get('#command_input').type("a = vector(0,0,0.5,0.5){enter}");
|
||||
cy.get('#0').invoke('attr','d').should('eq','M550 350 L600 300');
|
||||
cy.get('#0').invoke('attr','class').should('eq','vector');
|
||||
cy.get('#0').invoke('attr','marker-end').should('eq','url(#arrow)');
|
||||
|
||||
cy.get('#command_input').type("b = vector(0,0,-1,1){enter}");
|
||||
cy.get('#1').invoke('attr','d').should('eq','M550 350 L450 250');
|
||||
|
||||
cy.get('#command_input').type("c = \"a + b\"{enter}"); // same as above, but lazy
|
||||
cy.get('#3').invoke('attr','d').should('eq','M550 350 L500 200');
|
||||
|
||||
cy.get('#command_input').type("a = a*2{enter}"); // so what happens to lazy, when it's constituents are altered?
|
||||
// a is now double in size, so c must also changed
|
||||
// c now refers to @4
|
||||
cy.get('#4').invoke('attr','d').should('eq','M550 350 L650 250');
|
||||
|
||||
cy.get('#command_input').type("a = 1{enter}"); // so what happens to lazy, when it's constituents are altered?
|
||||
|
||||
cy.get("#l4").then(text => {
|
||||
expect(text.text()).to.equal('@4'); // binding has been changed (to 1, ie not a vector),
|
||||
// so this is now a 'free' vector with a reference label
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
// import './commands'
|
||||
|
||||
require('cypress-xpath');
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -1643,6 +1643,12 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"cypress-xpath": {
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/cypress-xpath/-/cypress-xpath-1.6.2.tgz",
|
||||
"integrity": "sha512-mtwJPl840GQPGtb480fKR5vDIcijBHhAVwby5/AIPIT/UVT7UJhM2L42/R+venR7N01I0PoOJErb6UiMbCyUxg==",
|
||||
"dev": true
|
||||
},
|
||||
"dashdash": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
"devDependencies": {
|
||||
"css-loader": "^5.0.2",
|
||||
"cypress": "^6.5.0",
|
||||
"cypress-xpath": "^1.6.2",
|
||||
"eslint": "^7.20.0",
|
||||
"eslint-loader": "^4.0.2",
|
||||
"eslint-plugin-cypress": "^2.11.2",
|
||||
|
|
|
|||
|
|
@ -37,17 +37,18 @@ const show = function (vector) {
|
|||
}
|
||||
|
||||
export const update_lazy_objects = function () {
|
||||
let b = Object.values(bindings);
|
||||
for (let i = 0; i < b.length; i++) {
|
||||
let b = Object.values(bindings); // a lazy expression must be bound
|
||||
for (let i = 0; i < b.length; i++) { // unbound ones can exist, but are meaningless, because you cannot refer to them
|
||||
let binding = b[i];
|
||||
if (state[binding.name].lazy_expression) {
|
||||
let value = visit(state[binding.name].lazy_expression);
|
||||
let existing_value = bindings[binding.name].evaluated;
|
||||
if (state[binding.name].lazy_expression) { // if lazy,
|
||||
let value = visit(state[binding.name].lazy_expression); // reevaluate,
|
||||
let existing_value = bindings[binding.name].evaluated; // update view
|
||||
if (existing_value.id) {
|
||||
// update view after reevaluation of lazy vectors
|
||||
update_vector_arrow(existing_value.id, value);
|
||||
bindings[binding.name].evaluated = value;
|
||||
} else if (value.is_new && value.is_vector){
|
||||
// hidden lazy object reappearing
|
||||
// hidden lazy vector reappears
|
||||
value.label_text=binding.name;
|
||||
add_vector_arrow_to_svg(value);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue