Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class ClipboardToolOptions extends ConsumerWidget {
ToastUtils.showShortToast(message: 'Nothing to paste!');
},
),
const SizedBox(width: 16),
CustomActionChip(
chipIcon: Icon(Icons.delete_outline, color: shadowColor),
hint: 'Clear clipboard',
chipBackgroundColor: Colors.white,
onPressed: clipboardOptionsState.hasCopiedContent
? (){
clipboardOptionsNotifier.clearClipboard();
}
: () {
ToastUtils.showShortToast(message: 'Nothing to clear!');
},
),
],
),
],
Expand Down
181 changes: 181 additions & 0 deletions test/integration/clipboard_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,186 @@ void main() {
'Canvas should change after pasting, and it should be different from just having A and B');
});
}
if (testID == -1 || testID == 5) {
testWidgets(
'[CLIPBOARD_TOOL_TEST_ID_5]: Clear operation removes content from clipboard after Copy operation',
(WidgetTester tester) async {
await ClipboardIntegrationTestUtils.launchAppAndInit(tester);

ui.Image? imageBeforeDraw =
await ClipboardIntegrationTestUtils.getCanvasImage(tester);

await ClipboardIntegrationTestUtils.drawSomethingOnCanvas(tester);
ui.Image? imageAfterDraw =
await ClipboardIntegrationTestUtils.getCanvasImage(tester);
expect(imageAfterDraw, isNotNull,
reason: 'Canvas image should be available after draw');
expect(
imageAfterDraw.hashCode, isNot(equals(imageBeforeDraw?.hashCode)),
reason: 'Canvas should change after drawing a shape');

await ClipboardIntegrationTestUtils.selectTool(
tester, ToolData.CLIPBOARD.name);
expect(find.byType(ClipboardToolOptions), findsOneWidget,
reason: 'Clipboard options should be visible');

final copyButton = find.widgetWithIcon(CustomActionChip, Icons.copy);
expect(copyButton, findsOneWidget,
reason: 'Copy button should be present');
await tester.tap(copyButton);
await tester.pumpAndSettle();

expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isTrue,
reason: 'hasCopiedContent should be true after copy');

final clearButton = find.widgetWithIcon(CustomActionChip, Icons.delete_outline);
expect(clearButton, findsOneWidget,
reason: 'Clear button should be present');

final undoBeforeClear = UIInteraction.getUndoStackLength();
await tester.tap(clearButton);
await tester.pumpAndSettle();
final undoAfterClear = UIInteraction.getUndoStackLength();
expect(undoAfterClear, equals(undoBeforeClear),
reason: 'Canvas should remain unchanged after clearing clipboard');

expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isFalse,
reason: 'hasCopiedContent should be false after clear');

ui.Image? imageAfterClear =
await ClipboardIntegrationTestUtils.getCanvasImage(tester,
forceUpdate: true);


final pasteButton = find.widgetWithIcon(CustomActionChip, Icons.paste);
expect(pasteButton, findsOneWidget,
reason: 'Paste button should be present');
await tester.tap(pasteButton);
await tester.pumpAndSettle();

ui.Image? imageAfterPasteAttempt =
await ClipboardIntegrationTestUtils.getCanvasImage(tester,
forceUpdate: false);
expect(imageAfterPasteAttempt?.hashCode, equals(imageAfterClear.hashCode),
reason:
'Canvas should not change when Paste operation is performed after clearing the clipboard');
});
}
if (testID == -1 || testID == 6) {
testWidgets(
'[CLIPBOARD_TOOL_TEST_ID_6]: Clear operation removes content from clipboard after Cut operation',
(WidgetTester tester) async {
await ClipboardIntegrationTestUtils.launchAppAndInit(tester);

ui.Image? imageBeforeDraw =
await ClipboardIntegrationTestUtils.getCanvasImage(tester);

await ClipboardIntegrationTestUtils.drawSomethingOnCanvas(tester);
ui.Image? imageAfterDraw =
await ClipboardIntegrationTestUtils.getCanvasImage(tester);
expect(imageAfterDraw, isNotNull,
reason: 'Canvas image should be available after draw');
expect(
imageAfterDraw.hashCode, isNot(equals(imageBeforeDraw?.hashCode)),
reason: 'Canvas should change after drawing a shape');

await ClipboardIntegrationTestUtils.selectTool(
tester, ToolData.CLIPBOARD.name);
expect(find.byType(ClipboardToolOptions), findsOneWidget,
reason: 'Clipboard options should be visible');

final cutButton =
find.widgetWithIcon(CustomActionChip, Icons.content_cut);
expect(cutButton, findsOneWidget,
reason: 'Cut button should be present');
await tester.tap(cutButton);
await tester.pumpAndSettle();

expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isTrue,
reason: 'hasCopiedContent should be true after cut');

ui.Image? imageAfterCut =
await ClipboardIntegrationTestUtils.getCanvasImage(tester);
expect(imageAfterCut, isNotNull,
reason: 'Canvas image should be available after cut');
expect(imageAfterCut.hashCode, isNot(equals(imageAfterDraw.hashCode)),
reason: 'Canvas should change after cut (shape removed)');

final clearButton = find.widgetWithIcon(CustomActionChip, Icons.delete_outline);
expect(clearButton, findsOneWidget,
reason: 'Clear button should be present');

final undoBeforeClear = UIInteraction.getUndoStackLength();
await tester.tap(clearButton);
await tester.pumpAndSettle();
final undoAfterClear = UIInteraction.getUndoStackLength();
expect(undoAfterClear, equals(undoBeforeClear),
reason: 'Canvas should remain unchanged after clearing clipboard');

ui.Image? imageAfterClear =
await ClipboardIntegrationTestUtils.getCanvasImage(tester,
forceUpdate: true);

expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isFalse,
reason: 'hasCopiedContent should be false after clearing clipboard');

final pasteButton = find.widgetWithIcon(CustomActionChip, Icons.paste);
expect(pasteButton, findsOneWidget,
reason: 'Paste button should be present');
await tester.tap(pasteButton);
await tester.pumpAndSettle();

ui.Image? imageAfterPasteAttempt =
await ClipboardIntegrationTestUtils.getCanvasImage(tester,
forceUpdate: false);
expect(imageAfterPasteAttempt?.hashCode, equals(imageAfterClear.hashCode),
reason:
'Canvas should not change when Paste operation is performed after clearing the clipboard');
});

}
if (testID == -1 || testID == 7) {
testWidgets(
'[CLIPBOARD_TOOL_TEST_ID_7]: Multiple Clear operations on empty clipboard are safe',
(WidgetTester tester) async {
await ClipboardIntegrationTestUtils.launchAppAndInit(tester);

await ClipboardIntegrationTestUtils.selectTool(
tester, ToolData.CLIPBOARD.name);
expect(find.byType(ClipboardToolOptions), findsOneWidget);
expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isFalse,
reason: 'Initially, clipboard should be empty');

final undoBefore = UIInteraction.getUndoStackLength();
await ClipboardIntegrationTestUtils.selectTool(
tester, ToolData.CLIPBOARD.name);
expect(find.byType(ClipboardToolOptions), findsOneWidget,
reason: 'Clipboard options should be visible');

final clearButton = find.widgetWithIcon(CustomActionChip, Icons.delete_outline);
expect(clearButton, findsOneWidget,
reason: 'Clear button should be present');
await tester.tap(clearButton);
await tester.pumpAndSettle();
expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isFalse,
reason: 'hasCopiedContent should be false after clear');

await tester.tap(clearButton);
await tester.pumpAndSettle();
expect(
ClipboardIntegrationTestUtils.getHasCopiedContent(tester), isFalse,
reason: 'hasCopiedContent should be false after multiple clear operations');

final undoAfter = UIInteraction.getUndoStackLength();
expect(undoAfter, equals(undoBefore),
reason: 'Multiple clear operations should not affect undo stack');
});
}
});
}
1 change: 1 addition & 0 deletions test/widget/workspace_page/clipboard_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void main() {
expect(find.widgetWithIcon(CustomActionChip, Icons.content_cut),
findsOneWidget);
expect(find.widgetWithIcon(CustomActionChip, Icons.paste), findsOneWidget);
expect(find.widgetWithIcon(CustomActionChip, Icons.delete_outline), findsOneWidget);
});

testWidgets(
Expand Down