Skip to content

Commit

Permalink
Tests for new_visit
Browse files Browse the repository at this point in the history
  • Loading branch information
EPNW-Eric committed May 12, 2023
1 parent 4894f95 commit a93c959
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/ressources/mock/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const matomoCampaignContent = 'content';
const matomoCampaignId = 'id';
const matomoCampaignGroup = 'group';
const matomoCampaignPlacement = 'placement';
const matomoNewVisit = false;
const matomoChangedNewVisit = true;
const matomoEventPath = 'path';
const matomoEventAction = 'action';
const matomoEventCategory = 'eventCategory';
Expand Down
103 changes: 103 additions & 0 deletions test/src/matomo_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void main() {
subTotal: matomoSubTotal,
taxAmount: matomoTaxAmount,
trackingOrderItems: matomoTrackingOrderItems,
newVisit: matomoNewVisit,
);
}

Expand Down Expand Up @@ -72,6 +73,7 @@ void main() {
expect(matomotoEvent.subTotal, matomoSubTotal);
expect(matomotoEvent.taxAmount, matomoTaxAmount);
expect(matomotoEvent.trackingOrderItems, matomoTrackingOrderItems);
expect(matomotoEvent.newVisit, matomoNewVisit);
});

group(
Expand Down Expand Up @@ -207,4 +209,105 @@ void main() {
});
});
});

group('copyWith', () {
setUpAll(() {
when(() => mockMatomoTracker.visitor).thenReturn(mockVisitor);
when(() => mockMatomoTracker.session).thenReturn(mockSession);
when(() => mockMatomoTracker.screenResolution)
.thenReturn(matomoTrackerScreenResolution);
when(() => mockMatomoTracker.contentBase)
.thenReturn(matomoTrackerContentBase);
when(() => mockMatomoTracker.siteId).thenReturn(matomoTrackerSiteId);
when(() => mockVisitor.id).thenReturn(visitorId);
when(() => mockVisitor.uid).thenReturn(uid);
when(mockTrackingOrderItem.toArray).thenReturn([]);
when(() => mockSession.visitCount).thenReturn(sessionVisitCount);
when(() => mockSession.lastVisit).thenReturn(sessionLastVisite);
when(() => mockSession.firstVisit).thenReturn(sessionFirstVisite);
});

test('it should be able to create a unchanged copy', () {
final fixedDate = DateTime(2022).toUtc();

withClock(Clock.fixed(fixedDate), () {
final matomotoEvent = getCompleteMatomoEvent();
final unchangedCopy = matomotoEvent.copyWith();

expect(matomotoEvent.tracker, unchangedCopy.tracker);
expect(matomotoEvent.path, unchangedCopy.path);
expect(matomotoEvent.action, unchangedCopy.action);
expect(
matomotoEvent.eventInfo?.category,
unchangedCopy.eventInfo?.category,
);
expect(matomotoEvent.dimensions, unchangedCopy.dimensions);
expect(matomotoEvent.discountAmount, unchangedCopy.discountAmount);
expect(
matomotoEvent.eventInfo?.action,
unchangedCopy.eventInfo?.action,
);
expect(matomotoEvent.eventInfo?.value, unchangedCopy.eventInfo?.value);
expect(matomotoEvent.eventInfo?.name, unchangedCopy.eventInfo?.name);
expect(matomotoEvent.goalId, unchangedCopy.goalId);
expect(matomotoEvent.link, unchangedCopy.link);
expect(matomotoEvent.orderId, unchangedCopy.orderId);
expect(matomotoEvent.revenue, unchangedCopy.revenue);
expect(matomotoEvent.screenId, unchangedCopy.screenId);
expect(matomotoEvent.searchCategory, unchangedCopy.searchCategory);
expect(matomotoEvent.searchCount, unchangedCopy.searchCount);
expect(matomotoEvent.searchKeyword, unchangedCopy.searchKeyword);
expect(matomotoEvent.shippingCost, unchangedCopy.shippingCost);
expect(matomotoEvent.subTotal, unchangedCopy.subTotal);
expect(matomotoEvent.taxAmount, unchangedCopy.taxAmount);
expect(
matomotoEvent.trackingOrderItems,
unchangedCopy.trackingOrderItems,
);
expect(matomotoEvent.newVisit, unchangedCopy.newVisit);
});
});

test('it should be able to create a changed copy', () {
final fixedDate = DateTime(2022).toUtc();

withClock(Clock.fixed(fixedDate), () {
final matomotoEvent = getCompleteMatomoEvent();
final changedCopy =
matomotoEvent.copyWith(newVisit: matomoChangedNewVisit);

expect(matomotoEvent.tracker, changedCopy.tracker);
expect(matomotoEvent.path, changedCopy.path);
expect(matomotoEvent.action, changedCopy.action);
expect(
matomotoEvent.eventInfo?.category,
changedCopy.eventInfo?.category,
);
expect(matomotoEvent.dimensions, changedCopy.dimensions);
expect(matomotoEvent.discountAmount, changedCopy.discountAmount);
expect(
matomotoEvent.eventInfo?.action,
changedCopy.eventInfo?.action,
);
expect(matomotoEvent.eventInfo?.value, changedCopy.eventInfo?.value);
expect(matomotoEvent.eventInfo?.name, changedCopy.eventInfo?.name);
expect(matomotoEvent.goalId, changedCopy.goalId);
expect(matomotoEvent.link, changedCopy.link);
expect(matomotoEvent.orderId, changedCopy.orderId);
expect(matomotoEvent.revenue, changedCopy.revenue);
expect(matomotoEvent.screenId, changedCopy.screenId);
expect(matomotoEvent.searchCategory, changedCopy.searchCategory);
expect(matomotoEvent.searchCount, changedCopy.searchCount);
expect(matomotoEvent.searchKeyword, changedCopy.searchKeyword);
expect(matomotoEvent.shippingCost, changedCopy.shippingCost);
expect(matomotoEvent.subTotal, changedCopy.subTotal);
expect(matomotoEvent.taxAmount, changedCopy.taxAmount);
expect(
matomotoEvent.trackingOrderItems,
changedCopy.trackingOrderItems,
);
expect(matomoChangedNewVisit, changedCopy.newVisit);
});
});
});
}
9 changes: 9 additions & 0 deletions test/src/matomo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ void main() {
testTracking('it should be able to trackOutlink', (tracker) async {
tracker.trackOutlink(null);
});

test('it should be able to handle new_visit', () async {
final matomoTracker = await getInitializedMatomoTracker();

matomoTracker.trackDimensions(matomoTrackerDimensions);
expect(matomoTracker.queue.first.newVisit, true);
matomoTracker.trackDimensions(matomoTrackerDimensions);
expect(matomoTracker.queue.last.newVisit, null);
});
});

group('setVisitorUserId', () {
Expand Down

0 comments on commit a93c959

Please sign in to comment.