|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +// ignore: depend_on_referenced_packages |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import '../../../barcodes.dart'; |
| 5 | +import 'codabar_samples.dart'; |
| 6 | + |
| 7 | +/// Unit test scripts of Codabar |
| 8 | +void codabarSamples() { |
| 9 | + SfBarcodeGenerator? barcode; |
| 10 | + late Codabar symbology; |
| 11 | + group('Default-rendering', () { |
| 12 | + testWidgets('Default-rendering', (WidgetTester tester) async { |
| 13 | + final _CodabarTestCasesExamples container = |
| 14 | + _codabarTestCases('with-value') as _CodabarTestCasesExamples; |
| 15 | + await tester.pumpWidget(container); |
| 16 | + barcode = container._barcode; |
| 17 | + symbology = barcode!.symbology as Codabar; |
| 18 | + }); |
| 19 | + |
| 20 | + test('to test with-value', () { |
| 21 | + expect(barcode!.symbology, symbology); |
| 22 | + expect(barcode?.value, '123456'); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + group('with-value1', () { |
| 27 | + testWidgets('Default-rendering', (WidgetTester tester) async { |
| 28 | + final _CodabarTestCasesExamples container = |
| 29 | + _codabarTestCases('with-value1') as _CodabarTestCasesExamples; |
| 30 | + await tester.pumpWidget(container); |
| 31 | + barcode = container._barcode; |
| 32 | + symbology = barcode!.symbology as Codabar; |
| 33 | + }); |
| 34 | + |
| 35 | + test('to test with-value1', () { |
| 36 | + expect(barcode!.symbology, symbology); |
| 37 | + expect(barcode?.value, '714411106011348790'); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + group('with-specialcharcter', () { |
| 42 | + testWidgets('Default-rendering', (WidgetTester tester) async { |
| 43 | + final _CodabarTestCasesExamples container = |
| 44 | + _codabarTestCases('with-specialcharcter') |
| 45 | + as _CodabarTestCasesExamples; |
| 46 | + await tester.pumpWidget(container); |
| 47 | + barcode = container._barcode; |
| 48 | + symbology = barcode!.symbology as Codabar; |
| 49 | + }); |
| 50 | + |
| 51 | + test('to test with-specialcharcter', () { |
| 52 | + expect(barcode!.symbology, symbology); |
| 53 | + expect(barcode?.value, '6738989812:/+'); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + group('enable-showValue', () { |
| 58 | + testWidgets('enable-showValue', (WidgetTester tester) async { |
| 59 | + final _CodabarTestCasesExamples container = |
| 60 | + _codabarTestCases('enable-showValue') as _CodabarTestCasesExamples; |
| 61 | + await tester.pumpWidget(container); |
| 62 | + barcode = container._barcode; |
| 63 | + symbology = barcode!.symbology as Codabar; |
| 64 | + }); |
| 65 | + |
| 66 | + test('to test enable-showValue', () { |
| 67 | + expect(barcode!.symbology, symbology); |
| 68 | + expect(barcode?.value, '123456'); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + group('show value for longest digit', () { |
| 73 | + testWidgets('show value for longest digit', (WidgetTester tester) async { |
| 74 | + final _CodabarTestCasesExamples container = |
| 75 | + _codabarTestCases('show value for longest digit') |
| 76 | + as _CodabarTestCasesExamples; |
| 77 | + await tester.pumpWidget(container); |
| 78 | + barcode = container._barcode; |
| 79 | + symbology = barcode!.symbology as Codabar; |
| 80 | + }); |
| 81 | + |
| 82 | + test('to test show value for longest digit', () { |
| 83 | + expect(barcode!.symbology, symbology); |
| 84 | + expect(barcode?.value, '714411106011348790123654'); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + group('change bar color', () { |
| 89 | + testWidgets('change bar color', (WidgetTester tester) async { |
| 90 | + final _CodabarTestCasesExamples container = |
| 91 | + _codabarTestCases('change bar color') as _CodabarTestCasesExamples; |
| 92 | + await tester.pumpWidget(container); |
| 93 | + barcode = container._barcode; |
| 94 | + symbology = barcode!.symbology as Codabar; |
| 95 | + }); |
| 96 | + |
| 97 | + test('to test change bar color', () { |
| 98 | + expect(barcode!.symbology, symbology); |
| 99 | + expect(barcode?.value, '7144111060113487'); |
| 100 | + expect(barcode?.barColor, Colors.green); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + group('chnage background color', () { |
| 105 | + testWidgets('chnage background color', (WidgetTester tester) async { |
| 106 | + final _CodabarTestCasesExamples container = |
| 107 | + _codabarTestCases('chnage background color') |
| 108 | + as _CodabarTestCasesExamples; |
| 109 | + await tester.pumpWidget(container); |
| 110 | + barcode = container._barcode; |
| 111 | + symbology = barcode!.symbology as Codabar; |
| 112 | + }); |
| 113 | + |
| 114 | + test('to test chnage background color', () { |
| 115 | + expect(barcode!.symbology, symbology); |
| 116 | + expect(barcode?.value, '7144111060113487'); |
| 117 | + expect(barcode?.backgroundColor, Colors.yellow); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + group('set text spacing with show value', () { |
| 122 | + testWidgets('set text spacing with show value', |
| 123 | + (WidgetTester tester) async { |
| 124 | + final _CodabarTestCasesExamples container = |
| 125 | + _codabarTestCases('set text spacing with show value') |
| 126 | + as _CodabarTestCasesExamples; |
| 127 | + await tester.pumpWidget(container); |
| 128 | + barcode = container._barcode; |
| 129 | + symbology = barcode!.symbology as Codabar; |
| 130 | + }); |
| 131 | + |
| 132 | + test('to test set text spacing with show value', () { |
| 133 | + expect(barcode!.symbology, symbology); |
| 134 | + expect(barcode?.value, '7144111060113487'); |
| 135 | + expect(barcode?.textSpacing, 10); |
| 136 | + expect(barcode?.showValue, true); |
| 137 | + }); |
| 138 | + }); |
| 139 | + |
| 140 | + group('text align as start with showValue', () { |
| 141 | + testWidgets('text align as start with showValue', |
| 142 | + (WidgetTester tester) async { |
| 143 | + final _CodabarTestCasesExamples container = |
| 144 | + _codabarTestCases('text align as start with showValue') |
| 145 | + as _CodabarTestCasesExamples; |
| 146 | + await tester.pumpWidget(container); |
| 147 | + barcode = container._barcode; |
| 148 | + symbology = barcode!.symbology as Codabar; |
| 149 | + }); |
| 150 | + |
| 151 | + test('to test text align as start with showValue', () { |
| 152 | + expect(barcode!.symbology, symbology); |
| 153 | + expect(barcode?.value, '7144111060113487'); |
| 154 | + expect(barcode?.showValue, true); |
| 155 | + expect(barcode?.textAlign, TextAlign.start); |
| 156 | + }); |
| 157 | + }); |
| 158 | + |
| 159 | + group('set text style with all the properties', () { |
| 160 | + testWidgets('set text style with all the properties', |
| 161 | + (WidgetTester tester) async { |
| 162 | + final _CodabarTestCasesExamples container = |
| 163 | + _codabarTestCases('set text style with all the properties') |
| 164 | + as _CodabarTestCasesExamples; |
| 165 | + await tester.pumpWidget(container); |
| 166 | + barcode = container._barcode; |
| 167 | + symbology = barcode!.symbology as Codabar; |
| 168 | + }); |
| 169 | + |
| 170 | + test('set text style with all the properties', () { |
| 171 | + expect(barcode!.symbology, symbology); |
| 172 | + expect(barcode?.value, '7144111060113487'); |
| 173 | + expect(barcode?.textSpacing, 10); |
| 174 | + expect(barcode?.backgroundColor, Colors.yellow); |
| 175 | + expect(barcode?.barColor, Colors.green); |
| 176 | + expect(barcode?.textAlign, TextAlign.right); |
| 177 | + expect(barcode?.showValue, true); |
| 178 | + expect( |
| 179 | + barcode?.textStyle, |
| 180 | + const TextStyle( |
| 181 | + fontSize: 20, |
| 182 | + fontStyle: FontStyle.italic, |
| 183 | + fontWeight: FontWeight.bold)); |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + group('set module with all properties', () { |
| 188 | + testWidgets('set module with all properties', (WidgetTester tester) async { |
| 189 | + final _CodabarTestCasesExamples container = |
| 190 | + _codabarTestCases('set module with all properties') |
| 191 | + as _CodabarTestCasesExamples; |
| 192 | + await tester.pumpWidget(container); |
| 193 | + barcode = container._barcode; |
| 194 | + symbology = barcode!.symbology as Codabar; |
| 195 | + }); |
| 196 | + |
| 197 | + test('set module with all properties', () { |
| 198 | + expect(barcode!.symbology, symbology); |
| 199 | + expect(symbology.module, 2); |
| 200 | + expect(barcode?.showValue, true); |
| 201 | + expect(barcode?.textSpacing, 10); |
| 202 | + expect(barcode?.barColor, Colors.green); |
| 203 | + expect(barcode?.backgroundColor, Colors.yellow); |
| 204 | + expect(barcode?.textStyle, |
| 205 | + const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)); |
| 206 | + expect(barcode?.textAlign, TextAlign.end); |
| 207 | + expect(barcode?.value, '7144111060113487'); |
| 208 | + }); |
| 209 | + }); |
| 210 | +} |
| 211 | + |
| 212 | +StatelessWidget _codabarTestCases(String sampleName) { |
| 213 | + return _CodabarTestCasesExamples(sampleName); |
| 214 | +} |
| 215 | + |
| 216 | +// ignore: must_be_immutable |
| 217 | +class _CodabarTestCasesExamples extends StatelessWidget { |
| 218 | + // ignore: prefer_const_constructors_in_immutables |
| 219 | + _CodabarTestCasesExamples(String sampleName) { |
| 220 | + _barcode = getCodabarGenerator(sampleName); |
| 221 | + } |
| 222 | + |
| 223 | + late SfBarcodeGenerator _barcode; |
| 224 | + |
| 225 | + @override |
| 226 | + Widget build(BuildContext context) { |
| 227 | + return MaterialApp( |
| 228 | + title: 'Flutter Demo', |
| 229 | + home: Scaffold( |
| 230 | + appBar: AppBar( |
| 231 | + title: const Text('Test Chart Widget'), |
| 232 | + ), |
| 233 | + body: Center( |
| 234 | + child: Container( |
| 235 | + margin: EdgeInsets.zero, |
| 236 | + child: _barcode, |
| 237 | + ))), |
| 238 | + ); |
| 239 | + } |
| 240 | +} |
0 commit comments