attachmentTests function

void attachmentTests()

Implementation

void attachmentTests() {
  acterTestWidget('Add attachment to created pin example', (t) async {
    final spaceId = await t.freshAccountWithSpace(
      userDisplayName: 'Alex',
      spaceDisplayName: 'Pins Attachments Example',
    );

    await t.createPin(
      spaceId,
      'Pin with attachment example',
      'This pin contains attachment',
      'https://acter.global',
    );

    // we expect to be thrown to the pin screen and see our title
    await find.text('Pin with attachment example').should(findsAtLeast(1));

    // create attachment drafts
    final imageDraft = await t.imageAttachmentDraft();
    final videoDraft = await t.videoAttachmentDraft();

    // send attachments
    final imageAttachmentId = await imageDraft.send();
    final videoAttachmentId = await videoDraft.send();

    final imageAttachmentKey = find.byKey(Key(imageAttachmentId.toString()));
    await imageAttachmentKey.should(findsOneWidget);
    final videoAttachmentKey = find.byKey(Key(videoAttachmentId.toString()));
    await videoAttachmentKey.should(findsOneWidget);
  });

  acterTestWidget(
      'Add attachment and user can see main attachment on pin in pins overview',
      (t) async {
    final spaceId = await t.freshAccountWithSpace(
      userDisplayName: 'Alex',
      spaceDisplayName: 'Main Attachment on pin card example',
    );

    await t.createPin(
      spaceId,
      'Attachment on pin item example',
      'This pin contains attachment',
      'https://acter.global',
    );

    // we expect to be thrown to the pin screen and see our title
    await find.text('Attachment on pin item example').should(findsAtLeast(1));

    final imageDraft = await t.imageAttachmentDraft();
    final imageAttachmentId = await imageDraft.send();

    await t.navigateTo([
      MainNavKeys.quickJump,
      QuickJumpKeys.pins,
    ]);

    // we expect to see our pin in list
    await find.text('Attachment on pin item example').should(findsAtLeast(1));

    // we expect to see attachment showing on pin item
    final imageAttachmentKey = find.byKey(Key(imageAttachmentId.toString()));
    await imageAttachmentKey.should(findsOneWidget);
  });

  acterTestWidget(
    'can delete attachment from pin and verify it no longer shows up',
    (t) async {
      final spaceId = await t.freshAccountWithSpace(
        userDisplayName: 'Alex',
        spaceDisplayName: 'Delete attachment example',
      );

      await t.createPin(
        spaceId,
        'Delete attachment from pin example',
        'This pin contains attachment and can be deleted',
        'https://acter.global',
      );

      final fileDraft = await t.fileAttachmentDraft();
      final fileAttachmentId = await fileDraft.send();

      // we assure that file attachment exists
      final fileAttachmentKey = find.byKey(Key(fileAttachmentId.toString()));
      await fileAttachmentKey.should(findsOneWidget);

      final redactBtn = find.byKey(AttachmentSectionWidget.redactBtnKey);
      await redactBtn.should(findsOneWidget);
      await redactBtn.tap();

      final confirmRedactBtn =
          find.byKey(AttachmentSectionWidget.confirmRedactKey);
      await confirmRedactBtn.should(findsOneWidget);
      await confirmRedactBtn.tap();

      // confirm that isn't there anymore...
      await fileAttachmentKey.should(findsNothing);
    },
  );
}