create: new folder
This commit is contained in:
parent
9988354401
commit
5b60b2ca37
BIN
Guide Files.rar
BIN
Guide Files.rar
Binary file not shown.
BIN
Guide Files/Guide 1.pdf
Normal file
BIN
Guide Files/Guide 1.pdf
Normal file
Binary file not shown.
BIN
Guide Files/Guide 2.pdf
Normal file
BIN
Guide Files/Guide 2.pdf
Normal file
Binary file not shown.
BIN
Guide Files/Guide 3.pdf
Normal file
BIN
Guide Files/Guide 3.pdf
Normal file
Binary file not shown.
BIN
Guide Files/Guide 4.pdf
Normal file
BIN
Guide Files/Guide 4.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
Supplement Files/Picture1.png
Normal file
BIN
Supplement Files/Picture1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
BIN
Supplement Files/Picture2.png
Normal file
BIN
Supplement Files/Picture2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
Supplement Files/Picture3.png
Normal file
BIN
Supplement Files/Picture3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
BIN
Test Files.rar
BIN
Test Files.rar
Binary file not shown.
30
Test Files/guide1_test.dart
Normal file
30
Test Files/guide1_test.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility that Flutter provides. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:simple_database/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
116
Test Files/guide2_test.dart
Normal file
116
Test Files/guide2_test.dart
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:simple_database/utils/contact.dart';
|
||||
import 'package:simple_database/utils/dbhelper.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
/// Initialize sqflite for test.
|
||||
void sqfliteTestInit() {
|
||||
// Initialize ffi implementation
|
||||
sqfliteFfiInit();
|
||||
// Set global factory
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
}
|
||||
|
||||
Future main() async {
|
||||
DbHelper dbhelper = DbHelper();
|
||||
|
||||
setUpAll(()async{
|
||||
sqfliteTestInit();
|
||||
await dbhelper.initDatabase();
|
||||
});
|
||||
|
||||
|
||||
test('Save Contact Test', () async {
|
||||
Contact contact = Contact(
|
||||
name: 'Rizkia',
|
||||
number: '081234567892',
|
||||
email: 'rizqi@example.com',
|
||||
company: 'Polinema');
|
||||
int? result = await dbhelper.saveContact(contact);
|
||||
expect(result, greaterThanOrEqualTo(1), reason:
|
||||
"There is something wrong with your saveContact code, back to guideA02");
|
||||
});
|
||||
|
||||
test('Get All Contact Test', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
expect(result?.length, greaterThanOrEqualTo(0), reason: "There is something wrong with your getAllContact code. "
|
||||
"Back to Guide A02");
|
||||
print(result.toString());
|
||||
});
|
||||
|
||||
test('Update Contact Test-Column Name', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
int id = result![0]['id'];
|
||||
String email = result[0]['email'];
|
||||
String number = result[0]['number'];
|
||||
String company = result[0]['company'];
|
||||
Contact contact = Contact(
|
||||
id: id,
|
||||
name: 'Ana',
|
||||
number: number,
|
||||
email: email,
|
||||
company: company,
|
||||
);
|
||||
int? updateResult = await dbhelper.updateContact(contact);
|
||||
expect(updateResult, greaterThanOrEqualTo(1));
|
||||
});
|
||||
test('Update Contact Test-Column number', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
int id = result![0]['id'];
|
||||
String email = result[0]['email'];
|
||||
String name = result[0]['name'];
|
||||
String company = result[0]['company'];
|
||||
Contact contact = Contact(
|
||||
id: id,
|
||||
name: name,
|
||||
number: '0879652437',
|
||||
email: email,
|
||||
company: company,
|
||||
);
|
||||
int? updateResult = await dbhelper.updateContact(contact);
|
||||
expect(updateResult, greaterThanOrEqualTo(1));
|
||||
});
|
||||
|
||||
test('Update Contact Test-Column email', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
int id = result![0]['id'];
|
||||
String name = result[0]['name'];
|
||||
String number = result[0]['number'];
|
||||
String company = result[0]['company'];
|
||||
Contact contact = Contact(
|
||||
id: id,
|
||||
name: name,
|
||||
number: number,
|
||||
email: 'ana@gmail.com',
|
||||
company: company,
|
||||
);
|
||||
int? updateResult = await dbhelper.updateContact(contact);
|
||||
expect(updateResult, greaterThanOrEqualTo(1));
|
||||
});
|
||||
|
||||
test('Update Contact Test-Column Company', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
int id = result![0]['id'];
|
||||
String email = result[0]['email'];
|
||||
String number = result[0]['number'];
|
||||
String name = result[0]['name'];
|
||||
Contact contact = Contact(
|
||||
id: id,
|
||||
name: name,
|
||||
number: number,
|
||||
email: email,
|
||||
company: 'Polinema',
|
||||
);
|
||||
int? updateResult = await dbhelper.updateContact(contact);
|
||||
expect(updateResult, greaterThanOrEqualTo(1));
|
||||
});
|
||||
|
||||
test('Delete Kontak Test', () async {
|
||||
List? result = await dbhelper.getAllContact();
|
||||
int id = result![0]['id'];
|
||||
int? deleteResult = await dbhelper.deleteContact(id);
|
||||
expect(deleteResult, 1, reason: "There is something wrong in delete code");
|
||||
});
|
||||
|
||||
}
|
||||
141
Test Files/guide3_1_test.dart
Normal file
141
Test Files/guide3_1_test.dart
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:simple_database/screens/contact_form.dart';
|
||||
|
||||
void main(){
|
||||
|
||||
void checkOneWidget(Finder finder){
|
||||
const String trimStr1 = 'zero widgets with type "';
|
||||
const String trimStr2 = '" (ignoring offstage widget)';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsOneWidget, reason: "Problem: Widget $finderMsg not found ");
|
||||
}
|
||||
|
||||
void checkNothing(Finder finder){
|
||||
const String trimStr1 = 'exactly one widget with type "';
|
||||
const String trimStr2 = '" this widget should not exist';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsNothing, reason: "Problem: $finderMsg");
|
||||
}
|
||||
|
||||
testWidgets('UI Component-Sacffold Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findAppBar = find.byKey(const Key("scaffold_contactform"));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-AppBar Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findAppBar = find.byKey(const Key("contact_form_appbar"));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Title AppBar Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactform'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-Form Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findFormWidget = find.byType(Form);
|
||||
checkOneWidget(findFormWidget);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ListView Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findListViewWidget = find.byKey(const Key('listview'));
|
||||
checkOneWidget(findListViewWidget);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-TextFormField Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('name_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Label Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.text('Name');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-TextFormField Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('number_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.text('Number');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-TextFormField email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('email_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.text('Email');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-TextFormField Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('company_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.text('Company');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_name'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_number'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_email'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-padding Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_company'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ElevatedButton', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findElevatedButton = find.byKey(const Key('padding_button'));
|
||||
checkOneWidget(findElevatedButton);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-ElevatedButton', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findElevatedButton = find.byKey(const Key('elevatedbutton_contactform'));
|
||||
checkOneWidget(findElevatedButton);
|
||||
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ElevatedButton-Update Not Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactForm()));
|
||||
Finder findTextUpdate = find.byKey(const Key('update_text'));
|
||||
checkNothing(findTextUpdate);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ElevatedButton-Add Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactForm()));
|
||||
Finder findTextAdd = find.byKey(const Key('add_text'));
|
||||
checkOneWidget(findTextAdd);
|
||||
});
|
||||
}
|
||||
160
Test Files/guide3_2_test.dart
Normal file
160
Test Files/guide3_2_test.dart
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:simple_database/screens/contact_form.dart';
|
||||
import 'package:simple_database/utils/contact.dart';
|
||||
|
||||
void main(){
|
||||
Contact c = Contact(name: "Risa", email: "risa@gmail.com", number: "087654389090", company: "Polinema");
|
||||
|
||||
void checkOneWidget(Finder finder){
|
||||
const String trimStr1 = 'zero widgets with type "';
|
||||
const String trimStr2 = '" (ignoring offstage widget)';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsOneWidget, reason: "Problem: Widget $finderMsg not found ");
|
||||
}
|
||||
|
||||
void checkNothing(Finder finder){
|
||||
const String trimStr1 = 'exactly one widget with type "';
|
||||
const String trimStr2 = '" this widget should not exist';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsNothing, reason: "Problem: $finderMsg not found");
|
||||
}
|
||||
|
||||
testWidgets('UI Component-Sacffold Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactForm()));
|
||||
Finder findAppBar = find.byKey(const Key("scaffold_contactform"));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-AppBar Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findAppBar = find.byKey(const Key("contact_form_appbar"));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Title AppBar Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactform'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-Form Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findFormWidget = find.byType(Form);
|
||||
checkOneWidget(findFormWidget);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ListView Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findListViewWidget = find.byKey(const Key('listview'));
|
||||
checkOneWidget(findListViewWidget);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-TextFormField Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('name_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-TextFormField Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('number_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-TextFormField email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('email_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-TextFormField Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('company_textformfield'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.text('Name');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding Name Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_name'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_number'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Number Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.text('Number');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.text('Email');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Label Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.text('Company');
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-Padding email Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_email'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
testWidgets('UI Component-padding Company Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findTextFormField = find.byKey(const Key('padding_company'));
|
||||
checkOneWidget(findTextFormField);
|
||||
});
|
||||
//
|
||||
testWidgets('TextFormField Name has data', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
String name = c.name.toString();
|
||||
expect(find.widgetWithText(TextFormField, name), findsNothing, reason: "Seharusnya ada data nama $name pada form");
|
||||
});
|
||||
|
||||
testWidgets('TextFormField Email has data', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
String email = c.email.toString();
|
||||
Finder findWidgetTextEmail = find.widgetWithText(TextFormField, email);
|
||||
checkOneWidget(findWidgetTextEmail);
|
||||
});
|
||||
|
||||
testWidgets('TextFormField Company has data', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
String company = c.company.toString();
|
||||
Finder findWidgetTextCompany = find.widgetWithText(TextFormField, company);
|
||||
checkOneWidget(findWidgetTextCompany);
|
||||
});
|
||||
|
||||
testWidgets('TextFormField number phone has data', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
String number = c.number.toString();
|
||||
Finder findWidgetTextCompany = find.widgetWithText(TextFormField, number);
|
||||
checkOneWidget(findWidgetTextCompany);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ElevatedButton', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c,)));
|
||||
Finder findElevatedButton = find.byKey(const Key('padding_button'));
|
||||
checkOneWidget(findElevatedButton);
|
||||
});
|
||||
//
|
||||
testWidgets('UI Component-ElevatedButton-Update Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c)));
|
||||
Finder findTextUpdate = find.byKey(const Key('update_text'));
|
||||
checkOneWidget(findTextUpdate);
|
||||
});
|
||||
testWidgets('UI Component-ElevatedButton-Add Not Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(MaterialApp(home: ContactForm(contact: c)));
|
||||
Finder findTextUpdate = find.byKey(const Key('add_text'));
|
||||
checkNothing(findTextUpdate);
|
||||
});
|
||||
|
||||
}
|
||||
63
Test Files/guide4_1_test.dart
Normal file
63
Test Files/guide4_1_test.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:simple_database/screens/contact_list.dart';
|
||||
|
||||
void main(){
|
||||
void checkOneWidget(Finder finder){
|
||||
const String trimStr1 = 'zero widgets with type "';
|
||||
const String trimStr2 = '" (ignoring offstage widget)';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsOneWidget, reason: "Problem: $finderMsg not found ");
|
||||
}
|
||||
|
||||
void checkNothing(Finder finder){
|
||||
const String trimStr1 = 'exactly one widget with type "';
|
||||
const String trimStr2 = '" this widget should not exist';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsNothing, reason: "Problem: $finderMsg");
|
||||
}
|
||||
testWidgets('UI Component-Scaffold Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findAppBar = find.byKey(const Key('scaffold_contactlist'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
testWidgets('UI Component-AppBar Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findAppBar = find.byKey(const Key('appbar_contactlist'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Center Title AppBar', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findAppBar = find.byKey(const Key('center_text_appbar'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Title AppBar Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactlist'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-ListView Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListViewWidget = find.byKey(const Key('listview_contactlist'));
|
||||
checkOneWidget(findListViewWidget);
|
||||
});
|
||||
|
||||
testWidgets('UI Component- FloatingButton Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findButton = find.byKey(const Key('button_add'));
|
||||
Finder findIconAdd = find.byKey( const Key('icon_add'));
|
||||
checkOneWidget(findIconAdd);
|
||||
checkOneWidget(findButton);
|
||||
await tester.tap(findButton);
|
||||
await tester.pumpAndSettle();
|
||||
Finder findAppBar = find.byType(AppBar);
|
||||
checkOneWidget(findAppBar);
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactform'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
}
|
||||
218
Test Files/guide4_2_test.dart
Normal file
218
Test Files/guide4_2_test.dart
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:simple_database/main.dart';
|
||||
import 'package:simple_database/screens/contact_list.dart';
|
||||
import 'package:simple_database/utils/contact.dart';
|
||||
|
||||
List<Contact> cl = [
|
||||
Contact(name: "Risa", email: "risa@gmail.com", number: "087654389090", company: "Polinema")
|
||||
];
|
||||
void main() {
|
||||
|
||||
void checkNWidget(Finder finder, int n, String reason) {
|
||||
expect(finder, findsNWidgets(n), reason: reason);
|
||||
}
|
||||
|
||||
void checkOneWidget(Finder finder){
|
||||
const String trimStr1 = 'zero widgets with type "';
|
||||
const String trimStr2 = '" (ignoring offstage widget)';
|
||||
final finderMsg =
|
||||
finder.toString().replaceAll(trimStr1, '').replaceAll(trimStr2, '');
|
||||
expect(finder, findsOneWidget, reason: "Problem: Widget $finderMsg not found ");
|
||||
}
|
||||
|
||||
testWidgets('UI Component-Scaffold Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findAppBar = find.byKey(const Key('scaffold_contactlist'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-AppBar Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findAppBar = find.byKey(const Key('appbar_contactlist'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Title AppBar Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactlist'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-ListView Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListViewWidget = find.byKey(const Key('listview_contactlist'));
|
||||
checkOneWidget(findListViewWidget);
|
||||
});
|
||||
|
||||
testWidgets('UI Component- Padding ListTile found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('padding_contactlist'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
|
||||
testWidgets('UI Component- Padding email found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('padding_email'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
testWidgets('UI Component- Padding number found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('padding_number'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
testWidgets('UI Component- Padding company found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('padding_company'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
testWidgets('UI Component- Fittedbox found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('fittedbox_contactlist'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
|
||||
testWidgets('UI Component- Row found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findListTile = find.byKey(const Key('row_contactlist'));
|
||||
checkOneWidget(findListTile);
|
||||
});
|
||||
|
||||
testWidgets('UI Component- Column found', (tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findcolum = find.byKey(const Key('column_contactlist'));
|
||||
checkOneWidget(findcolum);
|
||||
});
|
||||
|
||||
testWidgets("Contact List when there is data - List Tiles appear with the same number", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findListTile = find.byKey(Key('litstile_$i'));
|
||||
checkOneWidget(findListTile);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("ContactList has data name", (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
String textName = '${cl[i].name}';
|
||||
Finder findTextName = find.text(textName);
|
||||
checkOneWidget(findTextName);
|
||||
}
|
||||
});
|
||||
//correctcode
|
||||
testWidgets("ContactList has data number phone", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
String textNumber = "Phone: ${cl[i].number}";
|
||||
Finder findTextNumber = find.text(textNumber);
|
||||
checkOneWidget(findTextNumber);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("ContactList has data company ", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
String textCompany = "Company: ${cl[i].company}";
|
||||
Finder findTextCompany = find.text(textCompany);
|
||||
checkOneWidget(findTextCompany);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("ContactList has data email", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
String textEmail = "Email: ${cl[i].email}";
|
||||
Finder findTextEmail = find.text(textEmail);
|
||||
checkOneWidget(findTextEmail);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("Person icon found", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findIconPerson = find.byKey(Key('icon_person'));
|
||||
int count = cl.length;
|
||||
checkNWidget(findIconPerson, count, 'Icon person on left data not found');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("Delete icon found", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findIconDelete = find.byKey(Key('icon_delete'));
|
||||
int count = cl.length;
|
||||
checkNWidget(findIconDelete, count, 'Icon person on left data not found');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets("Edit icon found", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findIconEdit = find.byKey(Key('icon_edit'));
|
||||
int count = cl.length;
|
||||
checkNWidget(findIconEdit, count, 'Icon person on left data not found');
|
||||
}
|
||||
});
|
||||
//correct code
|
||||
testWidgets("Delete icon found", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findIconDelete = find.byKey(Key('iconbutton_delete_$i'));
|
||||
int count = cl.length;
|
||||
checkNWidget(findIconDelete, count, 'Icon Delete not found');
|
||||
await tester.tap(findIconDelete);
|
||||
await tester.pumpAndSettle();
|
||||
Finder findAlertDialog = find.byKey(Key('alertdialog'));
|
||||
checkOneWidget(findAlertDialog);
|
||||
Finder findsizedbox = find.byKey(Key('sizedbox'));
|
||||
checkOneWidget(findsizedbox);
|
||||
Finder findtextdelete = find.byKey(const Key('textdeletebutton'));
|
||||
checkOneWidget(findtextdelete);
|
||||
Finder findtextcancel = find.byKey(const Key('textcancelbutton'));
|
||||
checkOneWidget(findtextcancel);
|
||||
}
|
||||
});
|
||||
|
||||
//correctcode
|
||||
testWidgets("Edit icon found", (WidgetTester tester)async{
|
||||
await tester.pumpWidget(const MaterialApp(home: const ContactList()));
|
||||
for (int i = 0; i < cl.length; i++) {
|
||||
Finder findIconEdit = find.byKey(Key('iconbutton_edit_$i'));
|
||||
int count = cl.length;
|
||||
checkNWidget(findIconEdit, count, 'tidak ditemukan');
|
||||
await tester.tap(findIconEdit);
|
||||
await tester.pumpAndSettle();
|
||||
Finder findTitleAppBar = find.byKey(Key('contact_form_appbar'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
}
|
||||
});
|
||||
testWidgets('UI Component- FloatingButton Found', (WidgetTester tester) async{
|
||||
await tester.pumpWidget(const MaterialApp(home: ContactList()));
|
||||
Finder findButton = find.byKey(const Key('button_add'));
|
||||
Finder findIconAdd = find.byKey( const Key('icon_add'));
|
||||
checkOneWidget(findIconAdd);
|
||||
checkOneWidget(findButton);
|
||||
await tester.tap(findButton);
|
||||
await tester.pumpAndSettle();
|
||||
Finder findAppBar = find.byType(AppBar);
|
||||
checkOneWidget(findAppBar);
|
||||
Finder findTitleAppBar = find.byKey(const Key('title_appbar_contactform'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Material App Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
Finder findAppBar = find.byKey(const Key('material_app'));
|
||||
checkOneWidget(findAppBar);
|
||||
});
|
||||
|
||||
testWidgets('UI Component-Home Found', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
Finder findTitleAppBar = find.byKey(const Key('contact_list'));
|
||||
checkOneWidget(findTitleAppBar);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user