Поддельные данные перед загрузкой компонента AngularDart - PullRequest
0 голосов
/ 30 января 2020

Я работаю над тестом, чтобы загрузить некоторые данные в таблицу. Перед тем, как загрузить компонент / данные, пользователь должен выбрать две вещи из двух разных выпадающих. Я пытаюсь смоделировать это, чтобы я мог сделать некоторые утверждения для компонента, который я хочу протестировать.

Я получаю эту ошибку.

FetchResponse response Тип возврата ' FetchResponse 'не является' ProtoRpcRequest ', как определено анонимным closure.dart (return_of_invalid_type_from_closure)

цикл-код и год, которые пользователь обычно выбирает. Я пытаюсь установить это сам

var fetch = client.FetchRequest()
            ..section = client.Section.DETECT
            ..cycleCode = 'FALL'
            ..year = Int64(2020);

Файл прото для строки обнаружения выглядит следующим образом.

message DetectRow {
  required string product = 1;
  required int64 ready = 2;
  required int64 future_due = 3;
  required int64 dormancy_detected = 4;
  required int64 notification_pending = 5;
  required int64 notification_not_needed = 6;
  required int64 notification_initiated = 7;
  required int64 notification_processed = 8;
}

Я использую дротик-версию mockito https://github.com/dart-lang/mockito

@Component(
  selector: 'detect-dormancy-test',
  directives: [DetectDormancyComponent],
  template: '<detect-dormancy></detect-dormancy>',
)
class DetectDormancyComponentTest {}

class MockProtoAupService extends Mock implements ProtoAupService {}

class MockYearCycleService extends Mock implements YearCycleService {}

@GenerateInjector([
  ClassProvider(ProtoAupService, useClass: MockProtoAupService),
  ClassProvider(NotificationManager),
  ExistingProvider(NotificationConsumer, NotificationManager),
  ClassProvider(YearCycleService, useClass: MockYearCycleService),
])
final InjectorFactory injector = ng.injector$Injector;

void main() {
  group('DetectDormancyComponent', () {
    Acx2TestBed<DetectDormancyComponentTest> testBed;
    DetectDormancyPO detectDormancyPO;
    DetectDormancyComponentTest detectDormancyComponentTest;
    MockProtoAupService mockProtoAupService;
    MockYearCycleService mockYearCycleService;

    final one = Int64(1);
    setUp(() async {
      mockProtoAupService = MockProtoAupService();

      testBed = createNgTestBed(
          component: ng.DetectDormancyComponentTestNgFactory,
          injector: injector);
      detectDormancyComponentTest =
          (await testBed.load(DetectDormancyComponentTest)).componentInstance;

      detectDormancyPO =
          DetectDormancyPO.create(await testBed.rootPageLoader3Element);
    });

    tearDown(() => testBed.dispose());

    Future<void> loadTable() async {
      var testContext = await testBed.load(DetectDormancyComponentTest,
          beforeComponentCreated: (injector) {
        mockProtoAupService = injector.get(ProtoAupService);
      });

      var row1 = {
        'product': 'name 1',
        'ready': one,
        'futuredue': one,
        'dormancydetected': one,
        'notificationpending': one,
        'notificationnotneeded': one,
        'notificationinitiated': one,
        'notificationprocessed': one
      };

      var row2 = {
        'product': 'name 1',
        'ready': one,
        'futuredue': one,
        'dormancydetected': one,
        'notificationpending': one,
        'notificationnotneeded': one,
        'notificationinitiated': one,
        'notificationprocessed': one
      };

      var fetch = client.FetchRequest()
        ..section = client.Section.DETECT
        ..cycleCode = 'FALL'
        ..year = Int64(2020);

      var response = client.FetchResponse()
        ..table.detect.rows.addAll([row1 as client.DetectRow, row2 as client.DetectRow]);

      when(mockProtoAupService.FetchData(fetch)).thenAnswer((_) => response);


      detectDormancyComponentTest = testContext.componentInstance;
      detectDormancyPO =
          DetectDormancyPO.lookup(await testBed.rootPageLoader3Element);
    }

    test('inital data is loaded', () {
      loadTable();
      expect(detectDormancyPO.essTable.dataRows.length, 2);
    });

    test('inital error message when cycle and year are not selected', () {
      const errorMessage =
          'Please select at least one option for year and cycle.';
      expect(detectDormancyPO.title, contains(errorMessage));
    });
  });
}
...