Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelphoenix98 committed May 20, 2021
1 parent 7047e67 commit bbc9a96
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -38,3 +38,7 @@

* Reformatted code to pass static analysis.

## [1.0.7] - 2021-20-05

* Added tests.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
conditional_questions: '^1.0.6'
conditional_questions: '^1.0.7'
```


Expand Down
1 change: 0 additions & 1 deletion example/questionnaire_app/lib/main.dart
Expand Up @@ -56,7 +56,6 @@ class _MyHomePageState extends State<MyHomePage> {
color: Colors.deepOrange,
splashColor: Colors.orangeAccent,
onPressed: () async {
// print("hello");
if (questionManager.validate()) setState(() {});
},
child: Text("Submit"),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: conditional_questions
description: A package that handles the creation and state of a dynamic questionnaire/survey with conditional questions.
version: 1.0.6
version: 1.0.7
author: Michel Thomas<michelphoenix98@gmail.com>
homepage: https://github.com/Michelphoenix98/conditional_questions

Expand Down
56 changes: 56 additions & 0 deletions test/conditional_questions_test.dart
Expand Up @@ -79,4 +79,60 @@ void main() {
});
expect(questionManager.toMap(), temp);
});

test('setState should replace current state:', () {
final questionManager = QuestionHandler(questions(), callback: update);
Map<String, dynamic> temp = {
"What is your name?": "mike",
"Have you made any donations in the past?": "No",
"In the last 3 months have you had a vaccination?": "No",
"Have you ever taken medication for HIV?": "No",
"The series will depend on your answer": "No",
"Have you sustained any injuries?": "Yes",
"Did it result in a disability?": "No"
};
questionManager.setState(temp);
expect(questionManager.toMap(), temp);
});

test('ResetState should produce default state:', () {
final questionManager = QuestionHandler(questions(), callback: update);
Map<String, dynamic> temp = {
"What is your name?": "mike",
"Have you made any donations in the past?": "No",
"In the last 3 months have you had a vaccination?": "No",
"Have you ever taken medication for HIV?": "No",
"The series will depend on your answer": "No",
"Have you sustained any injuries?": "Yes",
"Did it result in a disability?": "No"
};
questionManager.setState(temp);
expect(questionManager.toMap(), temp);
questionManager.resetState();
expect(questionManager.toMap(), {
"What is your name?": "",
"Have you made any donations in the past?": null,
"In the last 3 months have you had a vaccination?": null,
"Have you ever taken medication for HIV?": null,
"The series will depend on your answer": null
});
});

test('validation test:', () {
final questionManager = QuestionHandler(questions(), callback: update);
Map<String, dynamic> temp = {
"What is your name?": "mike",
"Have you made any donations in the past?": "No",
"In the last 3 months have you had a vaccination?": "No",
"Have you ever taken medication for HIV?": "No",
"The series will depend on your answer": "No",
"Have you sustained any injuries?": "Yes",
"Did it result in a disability?": "No"
};
questionManager.setState(temp);
expect(questionManager.toMap(), temp);
expect(questionManager.validate(), true);
questionManager.resetState();
expect(questionManager.validate(), false);
});
}

0 comments on commit bbc9a96

Please sign in to comment.