Skip to content

Commit

Permalink
fix: utils tu (#1416)
Browse files Browse the repository at this point in the history
* test(moodboard): refacto

* test(step): refacto

* test(aroundme): refacto

* test(aroundMe): retours PR
  • Loading branch information
alebret authored Aug 31, 2022
1 parent 1633be0 commit 9ee3782
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Text } from "react-native-elements";
import { TouchableOpacity } from "react-native-gesture-handler";

import { Colors, Margins, Paddings } from "../../styles";
import { MOODBOARD_ITEMS } from "../../utils/moodboard.util";
import { MOODBOARD_ITEMS } from "../../utils/moodboard/moodboard.util";

interface Props {
setActiveIndex: Dispatch<SetStateAction<number>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type {
UserSituation,
} from "../../types";
import { NotificationUtils, StorageUtils, TrackerUtils } from "../../utils";
import { checkErrorOnProfile } from "../../utils/step.util";
import { checkErrorOnProfile } from "../../utils/step/step.util";

interface Props {
navigation: StackNavigationProp<RootStackParamList>;
Expand Down
59 changes: 59 additions & 0 deletions front/src/utils/aroundMe/aroundMe.util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { LatLng, Region } from "react-native-maps";

import { AroundMeConstants } from "../../constants";
import { getLatLngPoint } from "./aroundMe.util";

describe("AroundMeUtils", () => {
describe("getLatLngPoint", () => {
const regionNantes: Region = {
latitude: 47.223324097274556,
latitudeDelta: 0.13430321917147126,
longitude: -1.538015529513359,
longitudeDelta: 0.13483263552188873,
};

it("Should return center point of a given region", () => {
const expected: LatLng = {
latitude: 47.223324097274556,
longitude: -1.538015529513359,
};

expect(
getLatLngPoint(regionNantes, AroundMeConstants.LatLngPointType.center)
).toEqual(expected);
});

it("Should return top left point of a given region", () => {
const newLatitude: number =
regionNantes.latitude + regionNantes.latitudeDelta / 2;
const newLongitude: number =
regionNantes.longitude - regionNantes.longitudeDelta / 2;
const expected: LatLng = {
latitude: newLatitude,
longitude: newLongitude,
};

expect(
getLatLngPoint(regionNantes, AroundMeConstants.LatLngPointType.topLeft)
).toEqual(expected);
});

it("Should return bottom right point of a given region", () => {
const newLatitude: number =
regionNantes.latitude - regionNantes.latitudeDelta / 2;
const newLongitude: number =
regionNantes.longitude + regionNantes.longitudeDelta / 2;
const expected: LatLng = {
latitude: newLatitude,
longitude: newLongitude,
};

expect(
getLatLngPoint(
regionNantes,
AroundMeConstants.LatLngPointType.bottomRight
)
).toEqual(expected);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LatLng, Region } from "react-native-maps";

import { AroundMeConstants } from "../constants";
import { PLATFORM_IS_IOS } from "../constants/platform.constants";
import { AroundMeConstants } from "../../constants";
import { PLATFORM_IS_IOS } from "../../constants/platform.constants";

export const getPostalCodeCoords = async (
postalCodeInput: string
Expand Down
6 changes: 3 additions & 3 deletions front/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AccessibilityUtils from "./accessibility/accessibility.util";
import * as AppUtils from "./app.util";
import * as AroundMeUtils from "./aroundMe.util";
import * as AroundMeUtils from "./aroundMe/aroundMe.util";
import * as AroundMeFilterUtils from "./aroundMe/aroundMeFilter.util";
import * as ArticleUtils from "./article.util";
import * as ArticleFilterUtils from "./articles/articleFilter.util";
Expand All @@ -11,11 +11,11 @@ import * as KeyboardUtils from "./keyboard.util";
import * as LinkingUtils from "./linking/linking.util";
import * as LoggingUtils from "./logging.util";
import { initMonitoring, reportError } from "./logging.util";
import * as MoodboardUtils from "./moodboard.util";
import * as MoodboardUtils from "./moodboard/moodboard.util";
import * as NotificationUtils from "./notification.util";
import * as RootNavigation from "./rootNavigation.util";
import * as SearchUtils from "./search.util";
import * as StepUtils from "./step.util";
import * as StepUtils from "./step/step.util";
import * as StorageUtils from "./storage.util";
import * as StringUtils from "./strings/strings.util";
import { getAppTheme } from "./theme.util";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AsyncStorage from "@react-native-async-storage/async-storage";
import { format } from "date-fns";

import { Formats, StorageKeysConstants } from "../constants";
import { MoodboardUtils, StorageUtils } from ".";
import { Formats, StorageKeysConstants } from "../../constants";
import { MoodboardUtils, StorageUtils } from "..";

describe("Moodboard utils", () => {
describe("saveMood", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { format } from "date-fns";

import { MoodboardAssets } from "../components/assets";
import { Formats, Labels, StorageKeysConstants } from "../constants";
import { Colors } from "../styles";
import type { MoodboardItem, MoodStorageItem } from "../type";
import { getObjectValue, storeObjectValue } from "./storage.util";
import { MoodboardAssets } from "../../components/assets";
import { Formats, Labels, StorageKeysConstants } from "../../constants";
import { Colors } from "../../styles";
import type { MoodboardItem, MoodStorageItem } from "../../type";
import { getObjectValue, storeObjectValue } from "./../storage.util";

export const MOODBOARD_ITEMS: MoodboardItem[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion front/src/utils/notification.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
StorageKeysConstants,
} from "../constants";
import type { Event, Step } from "../types";
import { countCurrentStepArticlesNotRead } from "./step.util";
import { countCurrentStepArticlesNotRead } from "./step/step.util";
import * as StorageUtils from "./storage.util";

export enum NotificationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
import { addDays, addWeeks, subDays, subMonths, subYears } from "date-fns";
import _ from "lodash";

import { Labels, StorageKeysConstants } from "../constants";
import { Labels, StorageKeysConstants } from "../../constants";
import {
GROSSESSE_TOTAL_SEMAINES_SA,
GROSSESSE_TRIMESTRE_2_SEMAINES_SA,
StepId,
USER_SITUATIONS,
UserInfo,
} from "../constants/profile.constants";
import type { UserSituation } from "../types";
import { StepUtils, StorageUtils } from ".";
} from "../../constants/profile.constants";
import type { UserSituation } from "../../types";
import { StepUtils, StorageUtils } from "..";

describe("Step utils", () => {
describe("Count Articles to read in CurrentStep", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {
} from "date-fns";
import _ from "lodash";

import { Labels, StorageKeysConstants } from "../constants";
import type { UserInfo } from "../constants/profile.constants";
import { Labels, StorageKeysConstants } from "../../constants";
import type { UserInfo } from "../../constants/profile.constants";
import {
DEFAULT_USER_INFOS,
GROSSESSE_TOTAL_SEMAINES_SA,
GROSSESSE_TRIMESTRE_2_SEMAINES_SA,
StepId,
} from "../constants/profile.constants";
import type { UserInfos, UserSituation } from "../types";
import { getObjectValue } from "./storage.util";
} from "../../constants/profile.constants";
import type { UserInfos, UserSituation } from "../../types";
import { getObjectValue } from "./../storage.util";

const getUserInfos = (
userSituations: UserSituation[] | null,
Expand Down

0 comments on commit 9ee3782

Please sign in to comment.