Skip to content

Commit

Permalink
Fix anniversary event (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneha-s authored Apr 1, 2024
1 parent 7e423f4 commit bad8de8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
19 changes: 11 additions & 8 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
200386442A0227A4004229C6 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
2098A8512A022A2400D543AF /* RunnerDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RunnerDebug.entitlements; sourceTree = "<group>"; };
20D227A02BB6922D002B4D6B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = file; name = PrivacyInfo.xcprivacy; path = ../PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
20D227A02BB6922D002B4D6B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
26A55DE803EBC37682D1817B /* GoogleService-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Runner/GoogleService-Info.plist"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
72C690916D5A4943B686E116 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -90,6 +90,7 @@
97C146E51CF9000F007C117D = {
isa = PBXGroup;
children = (
20D227A02BB6922D002B4D6B /* PrivacyInfo.xcprivacy */,
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
Expand All @@ -110,7 +111,6 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
20D227A02BB6922D002B4D6B /* PrivacyInfo.xcprivacy */,
2098A8512A022A2400D543AF /* RunnerDebug.entitlements */,
200386442A0227A4004229C6 /* Runner.entitlements */,
9A2DD91F2949D6B7002464EF /* GoogleService-Info.plist */,
Expand Down Expand Up @@ -414,17 +414,18 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.0.2;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S985H2T7J8;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Unity;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.canopas.projectunity;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -551,17 +552,18 @@
CODE_SIGN_ENTITLEMENTS = Runner/RunnerDebug.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.0.2;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S985H2T7J8;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Unity;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.canopas.projectunity;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -583,18 +585,19 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1.0.2;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = S985H2T7J8;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Unity;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.canopas.projectunity;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
8 changes: 8 additions & 0 deletions lib/data/core/extensions/date_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ extension TimestampExtension on DateTime {
.add(Duration(days: DateTime.daysPerWeek - currentDate.weekday))
.day;

int calculateDifferenceInYears(DateTime currentDate) {
int yearDifference = year - currentDate.year;
if (month < currentDate.month || !isDateInCurrentWeek(currentDate)) {
yearDifference--;
}
return yearDifference.abs();
}

bool isBeforeOrSame(DateTime date) =>
isBefore(date) || isAtSameMomentAs(date);

Expand Down
7 changes: 5 additions & 2 deletions lib/data/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@
}
},

"upcoming_anniversary_text":"{name} will have successfully completed {years} years with us on",


"upcoming_anniversary_text":"{years, plural, =1{{name} will have successfully completed {years} year with us on} other {{name} will have successfully completed {years} years with us on}}",
"@upcoming_anniversary_text":{
"placeholders":{
"name":{
Expand All @@ -287,7 +289,8 @@
}
}
},
"present_anniversary_text":"Congratulations on {years} with us {name} 💐💐! Keep up the good work!",

"present_anniversary_text":"{years,plural, =1{Congratulations on {years} year with us {name} 💐💐! Keep up the good work!} other {Congratulations on {years} years with us {name} 💐💐! Keep up the good work!}}",
"@present_anniversary_text":{
"placeholders":{
"name":{
Expand Down
8 changes: 5 additions & 3 deletions lib/ui/shared/events/bloc/celebrations_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class CelebrationsBloc extends Bloc<CelebrationEvent, CelebrationsState> {
final List<Employee> allEmployees = await _employeeService.getEmployees();
employees = allEmployees
.where((employee) => employee.status == EmployeeStatus.active)
.where((employee) => employee.status == EmployeeStatus.active).
map((e) {
.where((employee) => employee.status == EmployeeStatus.active)
.map((e) {
if (e.dateOfBirth != null) {
final birthdate = e.dateOfBirth!.convertToUpcomingDay();
final Event event = Event(
Expand All @@ -44,8 +44,10 @@ class CelebrationsBloc extends Bloc<CelebrationEvent, CelebrationsState> {
imageUrl: e.imageUrl);
allBirthdayEvents.add(event);
}
if (e.role != Role.admin) {
if (e.role != Role.admin &&
e.dateOfJoining.calculateDifferenceInYears(DateTime.now()) >= 1) {
final upcomingDate = e.dateOfJoining.convertToUpcomingDay();

final Event event = Event(
name: e.name,
dateTime: DateUtils.dateOnly(e.dateOfJoining),
Expand Down
31 changes: 20 additions & 11 deletions test/unit_test/shared/events/celebration_event_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
employeeId: "CA-1000",
email: "[email protected]",
designation: "Application Tester",
dateOfJoining: DateTime.now().dateOnly,
dateOfJoining: DateTime.now().dateOnly.add(const Duration(days: 360)),
level: "SW-L2",
gender: Gender.male,
dateOfBirth: DateTime.now().dateOnly,
Expand All @@ -36,17 +36,22 @@ void main() {
employeeId: "CA-1000",
email: "[email protected]",
designation: "Application Tester",
dateOfJoining: DateTime.now().add(const Duration(days: 7)).dateOnly,
dateOfJoining: DateTime.now().dateOnly.add(const Duration(days: 367)),
level: "SW-L2",
gender: Gender.male,
dateOfBirth: DateTime.now().add(const Duration(days: 7)).dateOnly,
);

Event event = Event(
Event birthEvent = Event(
name: employee1.name,
dateTime: employee1.dateOfBirth!,
upcomingDate: employee1.dateOfBirth!.convertToUpcomingDay(),
imageUrl: employee1.imageUrl);
Event anniversaryEvent2 = Event(
name: employee2.name,
dateTime: employee2.dateOfJoining,
upcomingDate: employee2.dateOfJoining.convertToUpcomingDay(),
imageUrl: employee1.imageUrl);
Event event2 = Event(
name: employee2.name,
dateTime: employee2.dateOfBirth!,
Expand Down Expand Up @@ -74,8 +79,8 @@ void main() {
const CelebrationsState(status: Status.loading),
CelebrationsState(
status: Status.success,
birthdays: [event],
anniversaries: [event]),
birthdays: [birthEvent],
anniversaries: [anniversaryEvent2]),
]),
);
});
Expand All @@ -88,11 +93,13 @@ void main() {
celebrationsBloc.add(ShowBirthdaysEvent());

final successState = CelebrationsState(
status: Status.success, birthdays: [event], anniversaries: [event]);
status: Status.success,
birthdays: [birthEvent],
anniversaries: [anniversaryEvent2]);
final allBdayState = successState.copyWith(
showAllBdays: !celebrationsState.showAllBdays,
birthdays: [event, event2],
anniversaries: [event]);
birthdays: [birthEvent, event2],
anniversaries: [anniversaryEvent2]);
expectLater(
celebrationsBloc.stream,
emitsInOrder([
Expand All @@ -112,11 +119,13 @@ void main() {
celebrationsBloc.add(ShowAnniversariesEvent());

final successState = CelebrationsState(
status: Status.success, birthdays: [event], anniversaries: [event]);
status: Status.success,
birthdays: [birthEvent],
anniversaries: [anniversaryEvent2]);
final allAnniversariesState = successState.copyWith(
showAllAnniversaries: !celebrationsState.showAllAnniversaries,
birthdays: [event],
anniversaries: [event, event2]);
birthdays: [birthEvent],
anniversaries: [anniversaryEvent2]);
expectLater(
celebrationsBloc.stream,
emitsInOrder([
Expand Down

0 comments on commit bad8de8

Please sign in to comment.