Skip to content

Commit

Permalink
test: organizing tests into groups (#188)
Browse files Browse the repository at this point in the history
test: standardizing tests for badges

test: added debugFillProperties test helper function

docs: added helper function section to TESTING_README

docs: added link to excel sheet in TESTING_README

test: added test count script

fix: changed storybook to widgetbook in name of deploy preview in pull request github action

docs: created test counter script

docs: test_counter script improvements

test: moved script files to different PR

test: implemented helper function in avatar and banner tests

tests: organised button, chat_item, and checkbox tests

tests: organised tests for chip and comms button

tests: organised chat item, checkbox, chip, dialpad, fab, icon, in page banner, password, search bar, slider, stepper input,  and, tooltip

chore(automated): Lint commit and format

fix: removed '$componentName' from all test files

fix: removed analyzer from dependencies
  • Loading branch information
DE7924 authored Oct 15, 2024
1 parent 5987c21 commit ba4901d
Show file tree
Hide file tree
Showing 62 changed files with 2,733 additions and 2,054 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fi
deploy-preview:
name: Deploy preview version of the storybook on firebase
name: Deploy preview version of the widgetbook on firebase
needs: [code-quality, check-secret]
if: needs.check-secret.outputs.secret-exists == 'true'
runs-on: ubuntu-latest
Expand Down
45 changes: 27 additions & 18 deletions test/TESTING_README.mdx → test/TESTING_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,34 @@ As you are writing tests think about helper function you could write and add the

### Groups

- Accessibility Tests
- **Accessibility Tests**
Semantic labels, touch areas, contrast ratios, etc.
- Content Tests
Finds the widget, parameter statuses, etc.
- Dimensions Tests
Size, padding, margin, alignment, etc.
- Styling Tests

- **Content Tests**
Finds the widget, parameter statuses, etc.
Checking for the value of props and attributes of the widget. Checking for the presence of widgets.

- **Dimensions Tests**
Size, padding, margin, alignment, etc.
getSize().

- **Styling Tests**
Rendered colors, fonts, borders, radii etc.
- Interaction Tests
Checking the style of widgets and child widgets.

- **Interaction Tests**
Gesture recognizers, taps, drags, etc.
- Golden Tests
For example, using a boolean to check if the widgets interaction function runs.

- **Golden Tests**
Compares the rendered widget with the golden file. Use the `goldenTest()` function from test_utils/utils.dart.
- Performance Tests

- **Performance Tests**
Animation performance, rendering performance, data manupulation performance, etc.

### Testing File Template

```
```dart
import 'dart:ui';
import 'package:flutter/foundation.dart';
Expand All @@ -41,16 +51,15 @@ import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';
void main() {
const String componentName = 'ENTER_COMPONENT_NAME (e.g. ZetaButton)';
const String parentFolder = 'ENTER_PARENT_FOLDER (e.g. button)';
const goldenFile = GoldenFiles(component: parentFolder);
setUpAll(() {
goldenFileComparator = TolerantComparator(goldenFile.uri);
});
group('$componentName Accessibility Tests', () {});
group('$componentName Content Tests', () {
group('Accessibility Tests', () {});
group('Content Tests', () {
final debugFillProperties = {
'': '',
};
Expand All @@ -59,13 +68,13 @@ void main() {
debugFillProperties,
);
});
group('$componentName Dimensions Tests', () {});
group('$componentName Styling Tests', () {});
group('$componentName Interaction Tests', () {});
group('$componentName Golden Tests', () {
group('Dimensions Tests', () {});
group('Styling Tests', () {});
group('Interaction Tests', () {});
group('Golden Tests', () {
goldenTest(goldenFile, widget, widgetType, 'PNG_FILE_NAME');
});
group('$componentName Performance Tests', () {});
group('Performance Tests', () {});
}
```

Expand Down
26 changes: 26 additions & 0 deletions test/scripts/output/test_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
| Component | Accessibility | Content | Dimensions | Styling | Interaction | Golden | Performance | Unorganised | Total Tests |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Accordion | 0 | 2 | 0 | 1 | 2 | 0 | 0 | 0 | 5 |
| Avatar | 1 | 3 | 6 | 5 | 0 | 6 | 0 | 0 | 21 |
| Indicator | 0 | 7 | 0 | 0 | 0 | 5 | 0 | 0 | 12 |
| Label | 0 | 8 | 0 | 0 | 0 | 7 | 0 | 0 | 15 |
| Priority Pill | 0 | 5 | 0 | 0 | 0 | 4 | 0 | 0 | 9 |
| Status Label | 0 | 3 | 0 | 0 | 0 | 2 | 0 | 0 | 5 |
| Tag | 0 | 3 | 0 | 0 | 0 | 2 | 0 | 0 | 5 |
| Banner | 3 | 4 | 0 | 3 | 0 | 1 | 0 | 3 | 14 |
| Button | 0 | 10 | 0 | 2 | 1 | 8 | 0 | 0 | 21 |
| Chat Item | 0 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 10 |
| Checkbox | 0 | 3 | 0 | 0 | 3 | 2 | 0 | 0 | 8 |
| Chip | 0 | 1 | 0 | 0 | 5 | 0 | 0 | 0 | 6 |
| Comms Button | 2 | 7 | 0 | 0 | 0 | 1 | 0 | 0 | 10 |
| Dialpad | 0 | 2 | 0 | 1 | 2 | 3 | 0 | 0 | 8 |
| Fab | 0 | 6 | 0 | 1 | 1 | 4 | 0 | 0 | 12 |
| Icon | 1 | 4 | 1 | 6 | 0 | 0 | 0 | 0 | 12 |
| In Page Banner | 0 | 4 | 0 | 4 | 2 | 4 | 0 | 0 | 14 |
| Password Input | 0 | 4 | 0 | 0 | 0 | 1 | 0 | 0 | 5 |
| Search Bar | 0 | 5 | 0 | 0 | 5 | 5 | 0 | 0 | 15 |
| Slider | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
| Stepper Input | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 2 |
| Tooltip | 0 | 3 | 1 | 3 | 0 | 4 | 0 | 0 | 11 |
| Extended Top App Bar | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 3 |
| Total Tests | 7 | 95 | 8 | 26 | 23 | 59 | 0 | 6 | 224 |
19 changes: 11 additions & 8 deletions test/scripts/test_counter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class TestVisitor extends RecursiveAstVisitor<void> {
}
}

/// Generates an MDX (Markdown Extended) table representation of the test counts.
/// Generates an MD (Markdown) table representation of the test counts.
///
/// The function takes a nested map where the outer map's keys are test group names,
/// and the inner map's keys are test names with their corresponding integer counts.
Expand All @@ -139,7 +139,7 @@ class TestVisitor extends RecursiveAstVisitor<void> {
/// ```
///
/// Example output:
/// ```mdx
/// ```md
/// | Component | Accessibility | Content | Dimensions | Styling | Interaction | Golden | Performance | Unorganised | Total Tests |
/// | ----------- | ------------- | ------- | ---------- | ------- | ----------- | ------ | ----------- | ----------- | ----------- |
/// | Banner | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
Expand All @@ -151,8 +151,8 @@ class TestVisitor extends RecursiveAstVisitor<void> {
/// of test names with their corresponding counts.
///
/// Returns:
/// - A string in MDX format representing the test counts in a table with totals.
String generateMDX(Map<String, Map<String, int>> testCount) {
/// - A string in MD format representing the test counts in a table with totals.
String generateMD(Map<String, Map<String, int>> testCount) {
final Map<String, int> groupTotals = {
'Accessibility': 0,
'Content': 0,
Expand Down Expand Up @@ -228,14 +228,17 @@ void main() async {
final TestGroups testGroups = await parseTestFiles(testFiles);

// write test groups to file
await writeJSONToFile('${outputDirectory.path}/test_groups.json', testGroups);
// await writeJSONToFile('${outputDirectory.path}/test_groups.json', testGroups);

// count the number of tests in each group
final TestCount testCount = countTests(testGroups);

// write test counts to file
await writeJSONToFile('${outputDirectory.path}/test_counts.json', testCount);
// await writeJSONToFile('${outputDirectory.path}/test_counts.json', testCount);

// generate MDX table
await writeMDXToFile('${outputDirectory.path}/test_table.mdx', generateMDX(testCount));
// generate MD table
await writeMDToFile('${outputDirectory.path}/test_table.md', generateMD(testCount));

// ignore: avoid_print
print('Test table generated successfully!');
}
20 changes: 8 additions & 12 deletions test/scripts/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ extension NodeExtension on MethodInvocation {
/// Returns:
/// A [String] containing the sanitized name of the group.
String getGroupName() {
return argumentList.arguments.first
.toString()
.replaceAll("'", '')
.replaceAll(r'$componentName ', '')
.replaceAll(' Tests', '');
return argumentList.arguments.first.toString().replaceAll("'", '').replaceAll(' Tests', '');
}

/// Retrieves and sanitizes the name of the test.
Expand Down Expand Up @@ -185,16 +181,16 @@ Future<void> writeJSONToFile(String path, dynamic content) async {
await outputFileGroups.writeAsString(jsonOutputGroups);
}

/// Writes the given MDX data to a file at the specified path.
/// Writes the given MD data to a file at the specified path.
///
/// This function asynchronously writes the provided MDX data to a file
/// This function asynchronously writes the provided MD data to a file
/// located at the given path. If the file does not exist, it will be created.
///
/// [path] The file path where the MDX data should be written.
/// [mdxData] The MDX data to write to the file.
Future<void> writeMDXToFile(String path, String mdxData) async {
final mdxFile = File(path);
await mdxFile.writeAsString(mdxData);
/// [path] The file path where the MD data should be written.
/// [mdData] The MD data to write to the file.
Future<void> writeMDToFile(String path, String mdData) async {
final mdFile = File(path);
await mdFile.writeAsString(mdData);
}

extension ListExtension on List<String> {
Expand Down
Loading

0 comments on commit ba4901d

Please sign in to comment.