Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 981ac24

Browse files
release: v0.14.0 (#43)
* feat(ui): Show file size with units (#41) * refactor: Create barrel file in lib folder * feat(ui): Show size with units * feat: Delete files (#42) --------- Co-authored-by: Miguel Mateo Mendoza Rojas <115849391+MiguelMRojas@users.noreply.github.com>
1 parent ac53106 commit 981ac24

File tree

17 files changed

+479
-44
lines changed

17 files changed

+479
-44
lines changed

CHANGELOG.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
# [0.12.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.11.1...v0.12.0) (2023-10-24)
1+
# [0.14.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.13.0...v0.14.0) (2023-10-25)
22

33

44
### Features
55

6-
* Logout ([#38](https://github.com/PedroChaparro/alternative-frontend-react/issues/38)) ([da28481](https://github.com/PedroChaparro/alternative-frontend-react/commit/da2848173338776dd0fc64f12b18aa53f73f80b5))
6+
* Delete files ([#42](https://github.com/PedroChaparro/alternative-frontend-react/issues/42)) ([db61436](https://github.com/PedroChaparro/alternative-frontend-react/commit/db614364bd8883e36ef7bc38a9c2d83f057a5cae))
77

88

99

10-
## [0.11.1](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.11.0...v0.11.1) (2023-10-24)
10+
# [0.13.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.12.0...v0.13.0) (2023-10-24)
1111

1212

13-
### Bug Fixes
13+
### Features
1414

15-
* Allow to upload content into shared folders ([#36](https://github.com/PedroChaparro/alternative-frontend-react/issues/36)) ([9edeb38](https://github.com/PedroChaparro/alternative-frontend-react/commit/9edeb380d5d23a89f856eeb34f63df4e8ba8e023))
15+
* **ui:** Show file size with units ([#41](https://github.com/PedroChaparro/alternative-frontend-react/issues/41)) ([8614d86](https://github.com/PedroChaparro/alternative-frontend-react/commit/8614d8617a7bc8bb68c5739b3b9ed4af4db400fd))
1616

1717

1818

19-
# [0.11.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.10.0...v0.11.0) (2023-10-24)
19+
# [0.12.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.11.1...v0.12.0) (2023-10-24)
2020

2121

2222
### Features
2323

24-
* List shared files ([#33](https://github.com/PedroChaparro/alternative-frontend-react/issues/33)) ([b19c51f](https://github.com/PedroChaparro/alternative-frontend-react/commit/b19c51f733526ecefe01806ea6112aadeb275532))
24+
* Logout ([#38](https://github.com/PedroChaparro/alternative-frontend-react/issues/38)) ([da28481](https://github.com/PedroChaparro/alternative-frontend-react/commit/da2848173338776dd0fc64f12b18aa53f73f80b5))
2525

2626

2727

28-
# [0.10.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.9.0...v0.10.0) (2023-10-23)
28+
## [0.11.1](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.11.0...v0.11.1) (2023-10-24)
2929

3030

31-
### Features
31+
### Bug Fixes
3232

33-
* Share file ([#32](https://github.com/PedroChaparro/alternative-frontend-react/issues/32)) ([e91567a](https://github.com/PedroChaparro/alternative-frontend-react/commit/e91567a7a741e1bc9894753ad40e518d559bef20))
33+
* Allow to upload content into shared folders ([#36](https://github.com/PedroChaparro/alternative-frontend-react/issues/36)) ([9edeb38](https://github.com/PedroChaparro/alternative-frontend-react/commit/9edeb380d5d23a89f856eeb34f63df4e8ba8e023))
3434

3535

3636

37-
# [0.9.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.8.0...v0.9.0) (2023-10-21)
37+
# [0.11.0](https://github.com/PedroChaparro/alternative-frontend-react/compare/v0.10.0...v0.11.0) (2023-10-24)
3838

3939

4040
### Features
4141

42-
* Download file ([#28](https://github.com/PedroChaparro/alternative-frontend-react/issues/28)) ([b55be6c](https://github.com/PedroChaparro/alternative-frontend-react/commit/b55be6cec070a0e50d94c5062eab408d9d9c0e31))
42+
* List shared files ([#33](https://github.com/PedroChaparro/alternative-frontend-react/issues/33)) ([b19c51f](https://github.com/PedroChaparro/alternative-frontend-react/commit/b19c51f733526ecefe01806ea6112aadeb275532))
4343

4444

4545

e2e/files/remove-file.spec.tsx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { faker } from "@faker-js/faker";
2+
import { expect, test } from "@playwright/test";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
test.describe.serial("Users can remove a file", () => {
10+
const username = faker.internet.userName();
11+
const password = faker.internet.password({ length: 8 });
12+
13+
test("Register test user", async ({ page }) => {
14+
await page.goto("/register");
15+
16+
await page.getByLabel("Username").fill(username);
17+
await page.getByLabel("Password", { exact: true }).fill(password);
18+
await page.getByLabel("Confirm Password", { exact: true }).fill(password);
19+
await page.getByRole("button", { name: "Submit", exact: true }).click();
20+
21+
await expect(page.getByText("Account created successfully")).toBeVisible();
22+
await page.waitForURL(/\/files$/);
23+
});
24+
25+
test("Upload test file", async ({ page }) => {
26+
// Login with the registered user
27+
await page.goto("/login");
28+
await page.getByLabel("Username").fill(username);
29+
await page.getByLabel("Password", { exact: true }).fill(password);
30+
await page.getByRole("button", { name: "Submit", exact: true }).click();
31+
await page.waitForURL(/\/files$/);
32+
33+
// Open the upload modal
34+
await page.getByRole("button", { name: "Upload file" }).click();
35+
await expect(page.getByRole("dialog")).toBeVisible();
36+
await expect(page.getByText("Upload files", { exact: true })).toBeVisible();
37+
38+
// Upload a file
39+
const filesInput = page.getByLabel("Choose files to upload", {
40+
exact: true
41+
});
42+
await filesInput.setInputFiles([
43+
path.join(__dirname, "data/in/yellow.jpg"),
44+
path.join(__dirname, "data/in/blue.jpg")
45+
]);
46+
47+
// Submit the form
48+
await page.getByRole("button", { name: "Upload", exact: true }).click();
49+
50+
// Assert the modal is closed
51+
await expect(page.getByRole("dialog")).not.toBeVisible();
52+
53+
// Assert files are shown
54+
await expect(page.getByText("yellow.jpg")).toBeVisible();
55+
await expect(page.getByText("blue.jpg")).toBeVisible();
56+
});
57+
58+
test("Successfully deleted", async ({ page }) => {
59+
// Login with the registered user
60+
await page.goto("/login");
61+
await page.getByLabel("Username").fill(username);
62+
await page.getByLabel("Password", { exact: true }).fill(password);
63+
await page.getByRole("button", { name: "Submit", exact: true }).click();
64+
await page.waitForURL(/\/files$/);
65+
66+
// Open the file dropdown
67+
const fileCard = page.getByRole("button", { name: "yellow.jpg card" });
68+
await expect(fileCard).toBeVisible();
69+
await fileCard.getByLabel("More options for yellow.jpg").click();
70+
71+
// Open the modal
72+
const removeButton = page.getByRole("menuitem", {
73+
name: "Remove file",
74+
exact: true
75+
});
76+
77+
await expect(removeButton).toBeVisible();
78+
await removeButton.click();
79+
80+
await page.getByRole("button", { name: "Remove", exact: true }).click();
81+
82+
// Assert the modal is closed
83+
await expect(page.getByRole("dialog")).not.toBeVisible();
84+
85+
// Assert the file is not visible
86+
await expect(
87+
page.getByRole("button", { name: "yellow.jpg card" })
88+
).not.toBeVisible();
89+
90+
// Assert an alert is shown
91+
await expect(page.getByText("File successfully deleted")).toBeVisible();
92+
});
93+
94+
test("Cancel deleted", async ({ page }) => {
95+
// Login with the registered user
96+
await page.goto("/login");
97+
await page.getByLabel("Username").fill(username);
98+
await page.getByLabel("Password", { exact: true }).fill(password);
99+
await page.getByRole("button", { name: "Submit", exact: true }).click();
100+
await page.waitForURL(/\/files$/);
101+
102+
// Open the file dropdown
103+
const fileCard = page.getByRole("button", { name: "blue.jpg card" });
104+
await expect(fileCard).toBeVisible();
105+
await fileCard.getByLabel("More options for blue.jpg").click();
106+
107+
// Open the modal
108+
const removeButton = page.getByRole("menuitem", {
109+
name: "Remove file",
110+
exact: true
111+
});
112+
113+
await expect(removeButton).toBeVisible();
114+
await removeButton.click();
115+
116+
await page.getByRole("button", { name: "Cancel", exact: true }).click();
117+
118+
// Assert the modal is closed
119+
await expect(page.getByRole("dialog")).not.toBeVisible();
120+
});
121+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unofficial-frontend-react",
33
"private": true,
4-
"version": "0.12.0",
4+
"version": "0.14.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@hookform/resolvers": "^3.3.2",
20+
"@radix-ui/react-alert-dialog": "^1.0.5",
2021
"@radix-ui/react-dialog": "^1.0.5",
2122
"@radix-ui/react-dropdown-menu": "^2.0.6",
2223
"@radix-ui/react-label": "^2.0.2",

pnpm-lock.yaml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/file-card/Dropdown.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
import { FilesDialogsContext } from "@/context/index";
44
import { File } from "@/types/entities";
55
import { Dialogs } from "@/types/enums";
6-
import { Download, Key, MoreVertical, PenBox, Truck } from "lucide-react";
6+
import {
7+
Download,
8+
Key,
9+
MoreVertical,
10+
PenBox,
11+
Trash2,
12+
Truck
13+
} from "lucide-react";
714
import { useContext } from "react";
815

916
import { Button } from "../ui/button";
@@ -38,12 +45,17 @@ export const DropDown = ({ file }: { file: File }) => {
3845
<Truck className="mr-2 h-4 w-4" />
3946
Move {file.isFile ? "file" : "directory"}
4047
</DropdownMenuItem>
41-
{/*
42-
<DropdownMenuItem>
43-
<Trash2 className="mr-2 h-4 w-4" />
44-
Remove {file.isFile ? "file" : "directory"}
45-
</DropdownMenuItem>
46-
*/}
48+
49+
<DropdownMenuItem
50+
onClick={(e) => {
51+
e.stopPropagation();
52+
openDialog(Dialogs.REMOVE_FILE, file);
53+
}}
54+
>
55+
<Trash2 className="mr-2 h-4 w-4" />
56+
Remove {file.isFile ? "file" : "directory"}
57+
</DropdownMenuItem>
58+
4759
<DropdownMenuItem
4860
onClick={(e) => {
4961
e.stopPropagation();

src/components/file-card/FileCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
FoldersNavigationContext
77
} from "@/context/index";
88
import { FilesActionType } from "@/hooks/user-files/filesReducer";
9-
import { downloadBlob } from "@/lib/utils";
9+
import { downloadBlob, getSizeWithUnits } from "@/lib/index";
1010
import { downloadFileService } from "@/services/files/download-file.service";
1111
import { getFileByUUIDService } from "@/services/files/get-file-by-uuid.service";
1212
import { File } from "@/types/entities";
@@ -146,7 +146,8 @@ export const FileCard = ({ file }: { file: File }) => {
146146
</span>
147147
{file.isFile && (
148148
<span className="line-clamp-1 max-w-full text-sm text-foreground/75">
149-
<span className="font-semibold">Size:</span> {file.size} KB
149+
<span className="font-semibold">Size:</span>{" "}
150+
{getSizeWithUnits(file.size)}
150151
</span>
151152
)}
152153
</article>

0 commit comments

Comments
 (0)