Fixed input

This commit is contained in:
veeso
2021-03-14 14:09:03 +01:00
parent 0f4649ab8d
commit 371ba5c399

View File

@@ -366,14 +366,7 @@ mod tests {
assert_eq!(component.get_value(), Payload::Text(String::from("home"))); assert_eq!(component.get_value(), Payload::Text(String::from("home")));
// RenderData // RenderData
//assert_eq!(component.render().unwrap().cursor, 4); //assert_eq!(component.render().unwrap().cursor, 4);
assert_eq!( assert_eq!(component.states.cursor, 4);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
4
);
// Handle events // Handle events
// Try key with ctrl // Try key with ctrl
assert_eq!( assert_eq!(
@@ -386,14 +379,7 @@ mod tests {
// String shouldn't have changed // String shouldn't have changed
assert_eq!(component.get_value(), Payload::Text(String::from("home"))); assert_eq!(component.get_value(), Payload::Text(String::from("home")));
//assert_eq!(component.render().unwrap().cursor, 4); //assert_eq!(component.render().unwrap().cursor, 4);
assert_eq!( assert_eq!(component.states.cursor, 4);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
4
);
// Character // Character
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('/')))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('/')))),
@@ -401,14 +387,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("home/"))); assert_eq!(component.get_value(), Payload::Text(String::from("home/")));
//assert_eq!(component.render().unwrap().cursor, 5); //assert_eq!(component.render().unwrap().cursor, 5);
assert_eq!( assert_eq!(component.states.cursor, 5);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
5
);
// Verify max length (shouldn't push any character) // Verify max length (shouldn't push any character)
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('a')))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('a')))),
@@ -416,14 +395,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("home/"))); assert_eq!(component.get_value(), Payload::Text(String::from("home/")));
//assert_eq!(component.render().unwrap().cursor, 5); //assert_eq!(component.render().unwrap().cursor, 5);
assert_eq!( assert_eq!(component.states.cursor, 5);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
5
);
// Enter // Enter
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Enter))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Enter))),
@@ -436,14 +408,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("home"))); assert_eq!(component.get_value(), Payload::Text(String::from("home")));
//assert_eq!(component.render().unwrap().cursor, 4); //assert_eq!(component.render().unwrap().cursor, 4);
assert_eq!( assert_eq!(component.states.cursor, 4);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
5
);
// Check backspace at 0 // Check backspace at 0
component.states.input = vec!['h']; component.states.input = vec!['h'];
component.states.cursor = 1; component.states.cursor = 1;
@@ -453,14 +418,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from(""))); assert_eq!(component.get_value(), Payload::Text(String::from("")));
//assert_eq!(component.render().unwrap().cursor, 0); //assert_eq!(component.render().unwrap().cursor, 0);
assert_eq!( assert_eq!(component.states.cursor, 0);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
0
);
// Another one... // Another one...
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Backspace))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Backspace))),
@@ -468,14 +426,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from(""))); assert_eq!(component.get_value(), Payload::Text(String::from("")));
//assert_eq!(component.render().unwrap().cursor, 0); //assert_eq!(component.render().unwrap().cursor, 0);
assert_eq!( assert_eq!(component.states.cursor, 0);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
0
);
// See del behaviour here // See del behaviour here
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Delete))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Delete))),
@@ -483,14 +434,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from(""))); assert_eq!(component.get_value(), Payload::Text(String::from("")));
//assert_eq!(component.render().unwrap().cursor, 0); //assert_eq!(component.render().unwrap().cursor, 0);
assert_eq!( assert_eq!(component.states.cursor, 0);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
0
);
// Check del behaviour // Check del behaviour
component.states.input = vec!['h', 'e']; component.states.input = vec!['h', 'e'];
component.states.cursor = 1; component.states.cursor = 1;
@@ -500,14 +444,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("h"))); assert_eq!(component.get_value(), Payload::Text(String::from("h")));
//assert_eq!(component.render().unwrap().cursor, 1); // Shouldn't move //assert_eq!(component.render().unwrap().cursor, 1); // Shouldn't move
assert_eq!( assert_eq!(component.states.cursor, 1);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
1
);
// Another one (should do nothing) // Another one (should do nothing)
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Delete))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Delete))),
@@ -515,14 +452,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("h"))); assert_eq!(component.get_value(), Payload::Text(String::from("h")));
//assert_eq!(component.render().unwrap().cursor, 1); // Shouldn't move //assert_eq!(component.render().unwrap().cursor, 1); // Shouldn't move
assert_eq!( assert_eq!(component.states.cursor, 1);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
1
);
// Move cursor right // Move cursor right
component.states.input = vec!['h', 'e', 'l', 'l', 'o']; component.states.input = vec!['h', 'e', 'l', 'l', 'o'];
component.states.cursor = 1; component.states.cursor = 1;
@@ -532,14 +462,7 @@ mod tests {
Msg::None Msg::None
); );
//assert_eq!(component.render().unwrap().cursor, 2); // Should increment //assert_eq!(component.render().unwrap().cursor, 2); // Should increment
assert_eq!( assert_eq!(component.states.cursor, 2);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
2
);
// Put a character here // Put a character here
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('a')))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('a')))),
@@ -547,28 +470,14 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Text(String::from("heallo"))); assert_eq!(component.get_value(), Payload::Text(String::from("heallo")));
//assert_eq!(component.render().unwrap().cursor, 3); //assert_eq!(component.render().unwrap().cursor, 3);
assert_eq!( assert_eq!(component.states.cursor, 3);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
3
);
// Move left // Move left
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Left))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Left))),
Msg::None Msg::None
); );
//assert_eq!(component.render().unwrap().cursor, 2); // Should decrement //assert_eq!(component.render().unwrap().cursor, 2); // Should decrement
assert_eq!( assert_eq!(component.states.cursor, 2);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
2
);
// Go at the end // Go at the end
component.states.cursor = 6; component.states.cursor = 6;
// Move right // Move right
@@ -577,28 +486,14 @@ mod tests {
Msg::None Msg::None
); );
//assert_eq!(component.render().unwrap().cursor, 6); // Should stay //assert_eq!(component.render().unwrap().cursor, 6); // Should stay
assert_eq!( assert_eq!(component.states.cursor, 6);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
6
);
// Move left // Move left
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Left))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Left))),
Msg::None Msg::None
); );
//assert_eq!(component.render().unwrap().cursor, 5); // Should decrement //assert_eq!(component.render().unwrap().cursor, 5); // Should decrement
assert_eq!( assert_eq!(component.states.cursor, 5);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
5
);
// Go at the beginning // Go at the beginning
component.states.cursor = 0; component.states.cursor = 0;
assert_eq!( assert_eq!(
@@ -606,39 +501,18 @@ mod tests {
Msg::None Msg::None
); );
//assert_eq!(component.render().unwrap().cursor, 0); // Should stay //assert_eq!(component.render().unwrap().cursor, 0); // Should stay
assert_eq!( assert_eq!(component.states.cursor, 0);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
0
);
// End - begin // End - begin
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::End))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::End))),
Msg::None Msg::None
); );
assert_eq!( assert_eq!(component.states.cursor, 6);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
6
);
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Home))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Home))),
Msg::None Msg::None
); );
assert_eq!( assert_eq!(component.states.cursor, 0);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
0
);
// Update value // Update value
component.update( component.update(
component component
@@ -672,14 +546,7 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Unsigned(3000)); assert_eq!(component.get_value(), Payload::Unsigned(3000));
//assert_eq!(component.render().unwrap().cursor, 4); //assert_eq!(component.render().unwrap().cursor, 4);
assert_eq!( assert_eq!(component.states.cursor, 4);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
4
);
// Push a number // Push a number
assert_eq!( assert_eq!(
component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('1')))), component.on(InputEvent::Key(KeyEvent::from(KeyCode::Char('1')))),
@@ -687,13 +554,6 @@ mod tests {
); );
assert_eq!(component.get_value(), Payload::Unsigned(30001)); assert_eq!(component.get_value(), Payload::Unsigned(30001));
//assert_eq!(component.render().unwrap().cursor, 5); //assert_eq!(component.render().unwrap().cursor, 5);
assert_eq!( assert_eq!(component.states.cursor, 5);
component
.states
.render_value(component.props.input_type)
.len()
+ 1,
5
);
} }
} }