Skip to content

Commit

Permalink
feature: added sample
Browse files Browse the repository at this point in the history
  • Loading branch information
efraespada committed Oct 6, 2024
1 parent 6bc09b4 commit 797ec1d
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 33 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ This package allows you to create a widget catalog and all kinds of screenshots.

[- What are dummies?](https://github.com/landamessenger/catalog/wiki/Dummies#what-are-dummies)

[- Complex page catalog](https://github.com/landamessenger/catalog/wiki/Dummies#complex-page-catalog)

[- Prepare dummies](https://github.com/landamessenger/catalog/wiki/Dummies#prepare-dummies)

### [Test](https://github.com/landamessenger/catalog/wiki/Test)

[- Tests](https://github.com/landamessenger/catalog/wiki/Test#tests)

[- Integration Tests](https://github.com/landamessenger/catalog/wiki/Test#integration-tests)

[- Sample](https://github.com/landamessenger/catalog/wiki/Test#sample)

### [Build & Run](https://github.com/landamessenger/catalog/wiki/Build-&-Run)

[- Building your catalog](https://github.com/landamessenger/catalog/wiki/Build-&-Run#building-your-catalog)
Expand All @@ -52,4 +58,3 @@ This package allows you to create a widget catalog and all kinds of screenshots.
[- Samples](https://github.com/landamessenger/catalog/wiki/Screenshots#samples)

### [Catalog Sample](https://landamessenger.com/catalog)

23 changes: 13 additions & 10 deletions example/integration_test/catalog_widget_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
import 'package:integration_test/integration_test.dart';

import 'package:example/widgets/utils/bottom/catalog/integration_test/fab_widget_integration_test.dart'
as fwie;
as nsyv;
import 'package:example/widgets/other_utils/bottom/catalog/integration_test/warning_info_widget_integration_test.dart'
as aznv;
as fhuz;
import 'package:example/widgets/screen/catalog/integration_test/sized_container_integration_test.dart'
as qaip;
import 'package:example/widgets/screen/catalog/integration_test/body_widget_integration_test.dart'
as yzoq;
as afnp;
import 'package:example/widgets/screen/catalog/integration_test/counter_widget_integration_test.dart'
as zciv;
as mvnf;
import 'package:example/widgets/catalog/integration_test/main_screen_integration_test.dart'
as lwvd;
as gnzn;

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

fwie.FabWidgetIntegrationTest().main();
aznv.WarningInfoWidgetIntegrationTest().main();
yzoq.BodyWidgetIntegrationTest().main();
zciv.CounterWidgetIntegrationTest().main();
lwvd.MainScreenIntegrationTest().main();
nsyv.FabWidgetIntegrationTest().main();
fhuz.WarningInfoWidgetIntegrationTest().main();
qaip.SizedContainerIntegrationTest().main();
afnp.BodyWidgetIntegrationTest().main();
mvnf.CounterWidgetIntegrationTest().main();
gnzn.MainScreenIntegrationTest().main();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// AUTOGENERATED FILE.
///
/// Use this file to prepare the preview and the tests:
///
/// - SizedContainerPreview
/// - SizedContainerTest
/// - SizedContainerIntegrationTest
///
import 'package:catalog/catalog.dart';
import 'package:flutter/widgets.dart';

class SizedContainerDummy extends PreviewDummy {
@override
List<Dummy> get dummies => List.generate(
8,
(index) => Dummy(
parameters: {
'width': (index + 1) * 100.0,
'child': Text(bigText * 4),
},
),
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// AUTOGENERATED FILE.
///
/// Use this file to test the widget SizedContainer
///
import 'package:catalog/catalog.dart';
import 'package:flutter/widgets.dart';

import '../dummy/sized_container.dummy.dart';
import '../preview/sized_container.preview.dart';

class SizedContainerIntegrationTest {
void main() {
group(
'SizedContainer - IntegrationTest Tests',
() {
testWidgets(
'Child does not exceed the width',
(tester) async {
// prepare the context
await tester.setupTestContext();

for (var dummy in SizedContainerDummy().dummies) {
// prepare the widget
final widget = buildSizedContainer(dummy);
await tester.test(widget);

// get the size of the widget
final widgetSize = tester.getSize(find.byWidget(widget));

// check the maximum width
expect(
widgetSize.width,
dummy.parameters['width'],
);
}
},
);

testWidgets(
'Child does exceed the width',
(tester) async {
// prepare the context
await tester.setupTestContext();

for (var dummy in SizedContainerDummy().dummies) {
// prepare the widget
final widget = Container(
child: dummy.parameters['child'],
);
await tester.test(widget);

// get the size of the widget
final widgetSize = tester.getSize(find.byWidget(widget));

// check the maximum width
expect(
widgetSize.width,
greaterThanOrEqualTo(
dummy.parameters['width'],
),
);
}
},
);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/// AUTOGENERATED FILE. DO NOT EDIT
import 'package:catalog/catalog.dart';
import 'package:flutter/material.dart';
import 'package:example/widgets/screen/sized_container.dart';
import '../dummy/sized_container.dummy.dart';

@Preview(
description: 'Container with a max width',
parameters: ['width', 'child'],
)
class SizedContainerPreview extends ParentPreviewWidget {
@override
String get title => 'sized_container';

@override
String get basePath => '/catalog';

const SizedContainerPreview({super.key});

@override
Widget preview(BuildContext context) {
Catalog().widgetBasicPreviewMap.clear();
Catalog().widgetDevicePreviewMap.clear();

if (SizedContainerDummy().dummies.isEmpty) {
return Container();
}

final deviceScreenshotsAvailable =
SizedContainerDummy().deviceScreenshotsAvailable;
final screenshotsAvailable = SizedContainerDummy().screenshotsAvailable;

int basicScreenshots = screenshotsAvailable - deviceScreenshotsAvailable;

return ListView(
children: [
Column(
children: [
if (basicScreenshots > 0)
Center(
child: Container(
constraints: const BoxConstraints(
maxWidth: 400,
),
child: Card(
clipBehavior: Clip.hardEdge,
child: Container(
padding: const EdgeInsets.all(15),
color: Colors.white,
child: Row(
children: [
Expanded(
child: Center(
child: Text(
'$basicScreenshots basic screenshots available',
),
),
),
const IconButton(
onPressed: processBasicScreenshots,
icon: Icon(
Icons.screenshot,
),
)
],
),
),
),
),
),
if (deviceScreenshotsAvailable > 0)
Center(
child: Container(
constraints: const BoxConstraints(
maxWidth: 400,
),
child: Card(
clipBehavior: Clip.hardEdge,
child: Container(
padding: const EdgeInsets.all(15),
color: Colors.white,
child: Row(
children: [
Expanded(
child: Center(
child: Text(
'$deviceScreenshotsAvailable device screenshots available',
),
),
),
const IconButton(
onPressed: processDeviceScreenshots,
icon: Icon(
Icons.screenshot,
),
)
],
),
),
),
),
),
for (int i = 0; i < SizedContainerDummy().dummies.length; i++)
PreviewBoundary(
widgetKey: GlobalKey(),
dummyBuilder: () => SizedContainerDummy().dummies[i],
builder: (BuildContext context, Dummy dummy) {
return buildSizedContainer(dummy);
},
),
],
)
],
);
}
}

SizedContainer buildSizedContainer(Dummy dummy) {
return SizedContainer(
width: dummy.parameters['width'],
child: dummy.parameters['child'],
);
}
69 changes: 69 additions & 0 deletions example/lib/widgets/screen/catalog/test/sized_container_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// AUTOGENERATED FILE.
///
/// Use this file to test the widget SizedContainer
///
import 'package:catalog/catalog.dart';
import 'package:flutter/widgets.dart';

import '../dummy/sized_container.dummy.dart';
import '../preview/sized_container.preview.dart';

class SizedContainerTest {
void main() {
group(
'SizedContainer - Tests',
() {
testWidgets(
'Child does not exceed the width',
(tester) async {
// prepare the context
await tester.setupTestContext();

for (var dummy in SizedContainerDummy().dummies) {
// prepare the widget
final widget = buildSizedContainer(dummy);
await tester.test(widget);

// get the size of the widget
final widgetSize = tester.getSize(find.byWidget(widget));

// check the maximum width
expect(
widgetSize.width,
dummy.parameters['width'],
);
}
},
);

testWidgets(
'Child does exceed the width',
(tester) async {
// prepare the context
await tester.setupTestContext();

for (var dummy in SizedContainerDummy().dummies) {
// prepare the widget
final widget = Container(
child: dummy.parameters['child'],
);
await tester.test(widget);

// get the size of the widget
final widgetSize = tester.getSize(find.byWidget(widget));

// check the maximum width
expect(
widgetSize.width,
greaterThanOrEqualTo(
dummy.parameters['width'],
),
);
}
},
);
},
);
}
}
25 changes: 25 additions & 0 deletions example/lib/widgets/screen/sized_container.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:catalog/catalog.dart';
import 'package:flutter/material.dart';

@Preview(
description: 'Container with a max width',
parameters: ['width', 'child'],
)
class SizedContainer extends StatelessWidget {
final double width;
final Widget child;

const SizedContainer({
super.key,
this.width = 500,
required this.child,
});

@override
Widget build(BuildContext context) => Container(
constraints: BoxConstraints(
maxWidth: width,
),
child: child,
);
}
Loading

0 comments on commit 797ec1d

Please sign in to comment.