Skip to content

Commit

Permalink
ADD: Tests for the squircle shapes from orig rejected PR
Browse files Browse the repository at this point in the history
  • Loading branch information
rydmike committed Aug 13, 2023
1 parent bb9fc3f commit 1b6cb7d
Show file tree
Hide file tree
Showing 2 changed files with 410 additions and 0 deletions.
150 changes: 150 additions & 0 deletions test/squircle_border_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// These are the original test for the rejected PR.
// Only updated to use borderRadius and null safety version. The tests needs
// to be reviewed and revised, but they are a good starting point.

import 'dart:io' show Platform;

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:squircle_study/squircle/squircle_border.dart';

void main() {
test('Continuous rectangle border scale and lerp', () {
const SquircleBorder c10 =
SquircleBorder(borderRadius: BorderRadius.all(Radius.circular(100)));
const SquircleBorder c15 =
SquircleBorder(borderRadius: BorderRadius.all(Radius.circular(150)));
const SquircleBorder c20 =
SquircleBorder(borderRadius: BorderRadius.all(Radius.circular(200)));
expect(c10.dimensions, EdgeInsets.zero);
expect(c10.scale(2.0), c20);
expect(c20.scale(0.5), c10);
expect(ShapeBorder.lerp(c10, c20, 0.0), c10);
expect(ShapeBorder.lerp(c10, c20, 0.5), c15);
expect(ShapeBorder.lerp(c10, c20, 1.0), c20);
});

testWidgets('Golden test medium sized rectangle, medium radius',
(WidgetTester tester) async {
await tester.pumpWidget(
RepaintBoundary(
child: Container(
alignment: Alignment.center,
child: Material(
color: Colors.blueAccent[400],
shape: const SquircleBorder(
borderRadius: BorderRadius.all(Radius.circular(28)),
),
child: const SizedBox(
height: 100,
width: 100,
),
),
),
),
);

await tester.pumpAndSettle();

await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'continuous_rectangle_border.golden_test_medium_medium.png'),
skip: !Platform.isLinux,
);
});

testWidgets('Golden test small sized rectangle, medium radius',
(WidgetTester tester) async {
await tester.pumpWidget(
RepaintBoundary(
child: Container(
alignment: Alignment.center,
child: Material(
color: Colors.blueAccent[400],
shape: const SquircleBorder(
borderRadius: BorderRadius.all(Radius.circular(28)),
),
child: const SizedBox(
height: 10,
width: 100,
),
),
),
),
);

await tester.pumpAndSettle();

await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'continuous_rectangle_border.golden_test_small_medium.png'),
skip: !Platform.isLinux,
);
});

testWidgets('Golden test very small rectangle, medium radius',
(WidgetTester tester) async {
await tester.pumpWidget(
RepaintBoundary(
child: Container(
alignment: Alignment.center,
child: Material(
color: Colors.blueAccent[400],
shape: const SquircleBorder(
borderRadius: BorderRadius.all(Radius.circular(28)),
),
child: const SizedBox(
height: 5,
width: 100,
),
),
),
),
);

await tester.pumpAndSettle();

await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'continuous_rectangle_border.golden_test_vsmall_medium.png'),
skip: !Platform.isLinux,
);
});

testWidgets('Golden test large rectangle, large radius',
(WidgetTester tester) async {
await tester.pumpWidget(
RepaintBoundary(
child: Container(
alignment: Alignment.center,
child: Material(
color: Colors.blueAccent[400],
shape: const SquircleBorder(
borderRadius: BorderRadius.all(Radius.circular(50)),
),
child: const SizedBox(
height: 300,
width: 300,
),
),
),
),
);

await tester.pumpAndSettle();

await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'continuous_rectangle_border.golden_test_large_large.png'),
skip: !Platform.isLinux,
);
});
}

0 comments on commit 1b6cb7d

Please sign in to comment.