-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1539 from qdraw/feature/202404_desktop_codesmells_9
code smells desktop 9
- Loading branch information
Showing
10 changed files
with
203 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ipRegex } from "./url-regex"; | ||
|
||
describe("ipRegex", () => { | ||
test("Should match valid URLs with IP addresses", () => { | ||
expect(ipRegex.test("https://255.255.255.255")).toBe(true); | ||
}); | ||
|
||
test("Should not match invalid URLs with IP addresses", () => { | ||
expect(ipRegex.test("http://192.168.0.1")).toBe(false); | ||
expect(ipRegex.test("http://123.45.67.89:8080")).toBe(true); | ||
expect(ipRegex.test("http://0.0.0.0:12345/path")).toBe(false); | ||
|
||
expect(ipRegex.test("http://300.168.0.1")).toBe(false); // Out of range octet | ||
expect(ipRegex.test("https://192.168.1")).toBe(false); // Incomplete IP address | ||
expect(ipRegex.test("http://192.168.0.1.")).toBe(false); // Extra dot at the end | ||
expect(ipRegex.test("http://192.168.0.1:")).toBe(true); // Colon without port number | ||
expect(ipRegex.test("http://192.168.0.1/path?query")).toBe(false); // Path and query string | ||
}); | ||
|
||
test("Should match valid URLs with domain names", () => { | ||
expect(ipRegex.test("http://example.com")).toBe(false); | ||
expect(ipRegex.test("https://sub.domain.com")).toBe(false); | ||
expect(ipRegex.test("http://www.example123.net:8080")).toBe(false); | ||
expect(ipRegex.test("http://www.example.com/path")).toBe(false); | ||
}); | ||
|
||
test("Should not match invalid URLs with domain names", () => { | ||
expect(ipRegex.test("http://example")).toBe(false); // No top-level domain | ||
expect(ipRegex.test("https://.example.com")).toBe(false); // Empty subdomain | ||
expect(ipRegex.test("http://example..com")).toBe(false); // Double dot in domain name | ||
expect(ipRegex.test("http://example.com:")).toBe(false); // Colon without port number | ||
expect(ipRegex.test("http://example.com/path?query")).toBe(false); // Path and query string | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
starskydesktop/src/app/edit-file/is-detail-view-result.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { IGetNetRequestResponse } from "../net-request/get-net-request"; | ||
import { IsDetailViewResult } from "./is-detail-view-result"; | ||
|
||
describe("IsDetailViewResult", () => { | ||
it("should return true for valid result", () => { | ||
const validResult: IGetNetRequestResponse = { | ||
statusCode: 200, | ||
data: { | ||
fileIndexItem: { | ||
status: "Ok", | ||
collectionPaths: [], | ||
sidecarExtensionsList: [], | ||
}, | ||
}, | ||
}; | ||
expect(IsDetailViewResult(validResult)).toBe(true); | ||
}); | ||
|
||
it("should return false if statusCode is not 200", () => { | ||
const invalidStatusCode: IGetNetRequestResponse = { | ||
statusCode: 404, | ||
data: { | ||
fileIndexItem: { | ||
status: "Ok", | ||
collectionPaths: [], | ||
sidecarExtensionsList: [], | ||
}, | ||
}, | ||
}; | ||
expect(IsDetailViewResult(invalidStatusCode)).toBe(false); | ||
}); | ||
|
||
it("should return false if any required property is missing", () => { | ||
const missingData: IGetNetRequestResponse = { | ||
statusCode: 200, | ||
data: undefined, | ||
}; | ||
const missingFileIndexItem: IGetNetRequestResponse = { | ||
statusCode: 200, | ||
data: {}, | ||
}; | ||
const missingStatus: IGetNetRequestResponse = { | ||
statusCode: 200, | ||
data: { | ||
fileIndexItem: {}, | ||
}, | ||
}; | ||
expect(IsDetailViewResult(missingData)).toBeUndefined(); | ||
expect(IsDetailViewResult(missingFileIndexItem)).toBeUndefined(); | ||
expect(IsDetailViewResult(missingStatus)).toBeUndefined(); | ||
}); | ||
|
||
it('should return false if status is not "Ok", "OkAndSame", or "Default"', () => { | ||
const invalidStatus: IGetNetRequestResponse = { | ||
statusCode: 200, | ||
data: { | ||
fileIndexItem: { | ||
status: "InvalidStatus", | ||
collectionPaths: [], | ||
sidecarExtensionsList: [], | ||
}, | ||
}, | ||
}; | ||
expect(IsDetailViewResult(invalidStatus)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { IGetNetRequestResponse } from "../net-request/get-net-request"; | ||
|
||
export function IsDetailViewResult(result: IGetNetRequestResponse) { | ||
return ( | ||
result.statusCode === 200 | ||
&& result.data | ||
&& result.data.fileIndexItem | ||
&& result.data.fileIndexItem.status | ||
&& result.data.fileIndexItem.collectionPaths | ||
&& result.data.fileIndexItem.sidecarExtensionsList | ||
&& (result.data.fileIndexItem.status === "Ok" | ||
|| result.data.fileIndexItem.status === "OkAndSame" | ||
|| result.data.fileIndexItem.status === "Default") | ||
&& result.data?.fileIndexItem?.status | ||
&& result.data?.fileIndexItem?.collectionPaths | ||
&& result.data?.fileIndexItem?.sidecarExtensionsList | ||
&& ["Ok", "OkAndSame", "Default"].includes(result.data.fileIndexItem.status) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IRelativeObjects, PageType } from "./IDetailView"; | ||
import { IFileIndexItem } from "./IFileindexItem"; | ||
|
||
export interface IArchive { | ||
breadcrumb: Array<string>; | ||
pageType: PageType; | ||
fileIndexItems: Array<IFileIndexItem>; | ||
relativeObjects: IRelativeObjects; | ||
subPath: string; | ||
colorClassActiveList: Array<number>; | ||
colorClassUsage: Array<number>; | ||
collectionsCount: number; | ||
isReadOnly: boolean; | ||
searchQuery?: string; | ||
collections?: boolean; | ||
dateCache: number; | ||
sort?: SortType; | ||
} | ||
|
||
export enum SortType { | ||
fileName = "fileName", | ||
imageFormat = "imageFormat", | ||
} | ||
|
||
export function newIArchive(): IArchive { | ||
return {} as IArchive; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { IFileIndexItem } from "./IFileindexItem"; | ||
|
||
export enum PageType { | ||
Loading = "Loading", | ||
Archive = "Archive", | ||
DetailView = "DetailView", | ||
Search = "Search", | ||
ApplicationException = "ApplicationException", | ||
NotFound = "NotFound", | ||
Unauthorized = "Unauthorized", | ||
Trash = "Trash", | ||
} | ||
|
||
export interface IRelativeObjects { | ||
nextFilePath: string; | ||
prevFilePath: string; | ||
nextHash: string; | ||
prevHash: string; | ||
args: Array<string>; | ||
} | ||
|
||
export function newIRelativeObjects(): IRelativeObjects { | ||
return { | ||
nextFilePath: "", | ||
prevFilePath: "", | ||
nextHash: "", | ||
prevHash: "", | ||
args: new Array<string>(), | ||
} as IRelativeObjects; | ||
} | ||
|
||
export interface IDetailView { | ||
breadcrumb: []; | ||
pageType: PageType; | ||
fileIndexItem: IFileIndexItem; | ||
relativeObjects: IRelativeObjects; | ||
subPath: string; | ||
colorClassActiveList: Array<number>; | ||
lastUpdated?: Date; | ||
isReadOnly: boolean; | ||
collections?: boolean; | ||
dateCache: number; | ||
} | ||
|
||
export function newDetailView(): IDetailView { | ||
return { pageType: PageType.DetailView } as IDetailView; | ||
} |