aboutsummaryrefslogtreecommitdiff
path: root/test/components/AppList_test.dart
blob: dabc616177c151bed666cc6c1e9d12bf5d60932e (plain) (blame)
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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:device_apps/device_apps.dart';

import 'package:owyn/components/AppList.dart';

import '../utils.dart';

void main() {
  List<Application> appList = <Application>[
    makeApp('Reddit', 'org.example.reddit'),
    makeApp('Spotify', 'org.example.spotify'),
    makeApp('Twitter', 'org.example.twitter'),
    makeApp('Youtube', 'org.example.youtube'),
  ];

  testWidgets('Should render nothing for empty list', (WidgetTester tester) async {
    await tester.pumpWidget(wrapper(AppList(appList: <Application>[])));

    expect(find.byType(ListTile), findsNothing);
  });

  testWidgets('Should render nothing for list of 4 items', (WidgetTester tester) async {
    await tester.pumpWidget(wrapper(AppList(appList: appList)));

    expect(find.byType(ListTile), findsNWidgets(4));
  });

  testWidgets('Should open app on tap', (WidgetTester tester) async {
    bool wasAppOpened = false;
    Application openedApp;
    void mockOpenApp(Application app) {
      wasAppOpened = true;
      openedApp = app;
    }

    await tester.pumpWidget(wrapper(AppList(appList: appList, openApp: mockOpenApp)));

    var listTiles = find.byType(ListTile);

    await tester.tap(listTiles.at(1));
    await tester.pump();

    expect(wasAppOpened, equals(true));
    expect(openedApp.packageName, equals('org.example.spotify'));
  });

  testWidgets('Should open dialog menu on tap and hold', (WidgetTester tester) async {
    bool wasAppOpened = false;
    Application openedApp;
    void mockOpenOptionsMenu(Application app) {
      wasAppOpened = true;
      openedApp = app;
    }

    await tester.pumpWidget(wrapper(AppList(appList: appList, openOptionsMenu: mockOpenOptionsMenu)));

    var listTiles = find.byType(ListTile);

    await tester.longPress(listTiles.at(3));
    await tester.pump();

    expect(wasAppOpened, equals(true));
    expect(openedApp.packageName, equals('org.example.youtube'));
  });
}