From b445c7e74b574efe219f5054289b1efc00d0318b Mon Sep 17 00:00:00 2001 From: Ron Brosh <63312304+ron-brosh@users.noreply.github.com> Date: Wed, 24 Jan 2024 00:03:00 +0000 Subject: [PATCH 1/6] Update README.md --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 9bfb102..0aab383 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,57 @@ Feature: Sample Then I see {'Do not forget your towel!'} text ``` +While the `DataTable`-like syntax is a good practice for scenarios that require repeated steps, for example, entering text in different fields, sometimes we want to prepare test data in a readable way and mock our scneario's prerequisites and assert the expected result in an explicit domain driven way. +To handle this, we create a data table: +```ruby +Feature: Search songs + + Scenario: Searched text matches a song's details + Given available songs + | 'artist' | 'name' | + | 'The doors' | 'Riders on the storm' | + | 'Bob dylan' | "Knockin' On Heaven's Door" | + | 'The Beatles' | 'Here Comes the Sun' | + When I search for text {'door'} + Then I see songs + | 'artist' | 'name' | + | 'The doors' | 'Riders on the storm' | + | 'Bob dylan' | "Knockin' On Heaven's Door" | +``` +For each of the above step lines that are followed by a table, in the related generate step file, the created function will have an object parameter of type `DataTable`: +```dart +import 'package:bdd_widget_test/data_table.dart' as bdd; +import 'package:flutter_test/flutter_test.dart'; + +/// Usage: the following songs +Future availableSongs(WidgetTester tester, bdd.DataTable dataTable) async { + throw UnimplementedError(); +} +``` +This object can be used to retrieve the table's data. +Use the DataTable's **asLists** function to get the data as list of lists. +We can then iterate that list and extract data from each "column" in the current "row": +```dart + +dataTable.asLists().forEach((row) { + final artist = row[0] as String; + final name = row[1] as String; +}); +``` +**Keep in mind that if the first "row" is used for heading, you'll have to skip that first "row".** + +While a list of lists provides a foundational mechanism for extracting elements from a data table, the step implementation can be cryptic. The DataTable provides a list of maps mechanism as a more readable alternative by using the DataTable's **asMaps** function. +We can then iterate that list and extract data from each map using the "column" header as key. +For the above example, the asMaps function returns: +```dart +[ + {'artist': 'The doors', 'name': 'Riders on the storm'}, + {'artist': 'Bob dylan', 'name': "Knockin' On Heaven's Door"}, + {'artist': 'The Beatles', 'name': 'Here Comes the Sun'}, +] +``` +**In this case, we must provide a heading for our table.** + ## Tags Tags are used to filter scenarios in the test runner. Here are some examples: From bb22dd0fad9d6473de835d71f3b6b92a9fc0c05a Mon Sep 17 00:00:00 2001 From: Ron Brosh <63312304+ron-brosh@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:29:43 +0000 Subject: [PATCH 2/6] Update README.md Co-authored-by: Oleksandr Leushchenko <4376913+olexale@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0aab383..a2089ba 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,8 @@ Feature: Search songs Scenario: Searched text matches a song's details Given available songs | 'artist' | 'name' | - | 'The doors' | 'Riders on the storm' | - | 'Bob dylan' | "Knockin' On Heaven's Door" | + | 'The Doors' | 'Riders on the storm' | + | 'Bob Dylan' | "Knockin' On Heaven's Door" | | 'The Beatles' | 'Here Comes the Sun' | When I search for text {'door'} Then I see songs From 9c7e467f87d03525b4f50bd104ae52c8c212ebd8 Mon Sep 17 00:00:00 2001 From: Ron Brosh <63312304+ron-brosh@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:29:57 +0000 Subject: [PATCH 3/6] Update README.md Co-authored-by: Oleksandr Leushchenko <4376913+olexale@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2089ba..3884dec 100644 --- a/README.md +++ b/README.md @@ -139,8 +139,8 @@ Feature: Search songs When I search for text {'door'} Then I see songs | 'artist' | 'name' | - | 'The doors' | 'Riders on the storm' | - | 'Bob dylan' | "Knockin' On Heaven's Door" | + | 'The Doors' | 'Riders on the storm' | + | 'Bob Dylan' | "Knockin' On Heaven's Door" | ``` For each of the above step lines that are followed by a table, in the related generate step file, the created function will have an object parameter of type `DataTable`: ```dart From 25a9c03e9acf9bb8804b5ea3580837ba1adae79b Mon Sep 17 00:00:00 2001 From: Ron Brosh <63312304+ron-brosh@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:30:06 +0000 Subject: [PATCH 4/6] Update README.md Co-authored-by: Oleksandr Leushchenko <4376913+olexale@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3884dec..1494621 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ For each of the above step lines that are followed by a table, in the related ge import 'package:bdd_widget_test/data_table.dart' as bdd; import 'package:flutter_test/flutter_test.dart'; -/// Usage: the following songs +/// Usage: Given available songs Future availableSongs(WidgetTester tester, bdd.DataTable dataTable) async { throw UnimplementedError(); } From d8dfcbff0b9b87f88fc050d25309069cad2766ff Mon Sep 17 00:00:00 2001 From: Ron Brosh <63312304+ron-brosh@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:32:07 +0000 Subject: [PATCH 5/6] Update README.md Co-authored-by: Oleksandr Leushchenko <4376913+olexale@users.noreply.github.com> --- README.md | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1494621..b7019aa 100644 --- a/README.md +++ b/README.md @@ -152,29 +152,10 @@ Future availableSongs(WidgetTester tester, bdd.DataTable dataTable) async throw UnimplementedError(); } ``` -This object can be used to retrieve the table's data. -Use the DataTable's **asLists** function to get the data as list of lists. -We can then iterate that list and extract data from each "column" in the current "row": +Use the `DataTable` parameter to get access to the data: ```dart - -dataTable.asLists().forEach((row) { - final artist = row[0] as String; - final name = row[1] as String; -}); -``` -**Keep in mind that if the first "row" is used for heading, you'll have to skip that first "row".** - -While a list of lists provides a foundational mechanism for extracting elements from a data table, the step implementation can be cryptic. The DataTable provides a list of maps mechanism as a more readable alternative by using the DataTable's **asMaps** function. -We can then iterate that list and extract data from each map using the "column" header as key. -For the above example, the asMaps function returns: -```dart -[ - {'artist': 'The doors', 'name': 'Riders on the storm'}, - {'artist': 'Bob dylan', 'name': "Knockin' On Heaven's Door"}, - {'artist': 'The Beatles', 'name': 'Here Comes the Sun'}, -] -``` -**In this case, we must provide a heading for our table.** +final dataAsList = dataTable.asLists(); // [['artist', 'name'], ['The Doors', 'Riders on the storm'], ...] +final dataAsMaps = dataTable.asMaps(); // [{'artist: 'The Doors', 'name: 'Riders on the storm'}, ...] ## Tags From 39ddbc7472eaf0ee21e6b4d04ecf815d5d023bea Mon Sep 17 00:00:00 2001 From: Oleksandr Leushchenko <4376913+olexale@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:27:30 +0200 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7019aa..5777936 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Use the `DataTable` parameter to get access to the data: ```dart final dataAsList = dataTable.asLists(); // [['artist', 'name'], ['The Doors', 'Riders on the storm'], ...] final dataAsMaps = dataTable.asMaps(); // [{'artist: 'The Doors', 'name: 'Riders on the storm'}, ...] - +``` ## Tags Tags are used to filter scenarios in the test runner. Here are some examples: