File size: 4,059 Bytes
b225a21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import 'package:auto_gpt_flutter_client/constants/app_colors.dart';
import 'package:auto_gpt_flutter_client/models/test_option.dart';
import 'package:flutter/material.dart';

class TestSuiteButton extends StatefulWidget {
  final bool isDisabled;
  final Function(String) onOptionSelected;
  final Function(String) onPlayPressed;
  String selectedOptionString;

  TestSuiteButton({
    this.isDisabled = false,
    required this.onOptionSelected,
    required this.onPlayPressed,
    required this.selectedOptionString,
  });

  @override
  _TestSuiteButtonState createState() => _TestSuiteButtonState();
}

class _TestSuiteButtonState extends State<TestSuiteButton> {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        // Dropdown button with test options
        Expanded(
          // Added Expanded to make sure it takes the available space
          child: PopupMenuButton<String>(
            enabled: !widget.isDisabled,
            onSelected: (value) {
              setState(() {
                widget.selectedOptionString = value;
              });
              widget.onOptionSelected(widget.selectedOptionString);
            },
            itemBuilder: (BuildContext context) {
              return [
                PopupMenuItem(
                  value: TestOption.runSingleTest.description,
                  child: Text(TestOption.runSingleTest.description),
                ),
                PopupMenuItem(
                  value: TestOption
                      .runTestSuiteIncludingSelectedNodeAndAncestors
                      .description,
                  child: Text(TestOption
                      .runTestSuiteIncludingSelectedNodeAndAncestors
                      .description),
                ),
                PopupMenuItem(
                  value: TestOption.runAllTestsInCategory.description,
                  child: Text(TestOption.runAllTestsInCategory.description),
                ),
              ];
            },
            child: Container(
              height: 50,
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              decoration: BoxDecoration(
                color: widget.isDisabled ? Colors.grey : AppColors.primaryLight,
                borderRadius: BorderRadius.circular(8.0),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Flexible(
                    child: Text(
                      widget.selectedOptionString,
                      style: const TextStyle(
                        color: Colors.white,
                        fontSize: 12.50,
                        fontFamily: 'Archivo',
                        fontWeight: FontWeight.w400,
                      ),
                      overflow: TextOverflow.ellipsis,
                      maxLines: 2,
                    ),
                  ),
                  const Icon(
                    Icons.arrow_drop_down,
                    color: Colors.white,
                  )
                ],
              ),
            ),
          ),
        ),
        // Play button
        const SizedBox(width: 10),
        SizedBox(
          height: 50,
          child: ElevatedButton(
            style: ElevatedButton.styleFrom(
              backgroundColor:
                  widget.isDisabled ? Colors.grey : AppColors.primaryLight,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8.0),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              elevation: 5.0,
            ),
            onPressed: widget.isDisabled
                ? null
                : () {
                    widget.onPlayPressed(widget.selectedOptionString);
                  },
            child: const Icon(
              Icons.play_arrow,
              color: Colors.white,
              size: 24,
            ),
          ),
        ),
      ],
    );
  }
}