STYLE: Refactor code for improved readability and consistency
This commit is contained in:
@@ -27,5 +27,8 @@ class DocumentCapabilities extends Equatable {
|
||||
|
||||
bool get isImage => mimeType.startsWith('image/');
|
||||
bool get isText => mimeType.startsWith('text/');
|
||||
bool get isOffice => mimeType.contains('word') || mimeType.contains('spreadsheet') || mimeType.contains('presentation');
|
||||
bool get isOffice =>
|
||||
mimeType.contains('word') ||
|
||||
mimeType.contains('spreadsheet') ||
|
||||
mimeType.contains('presentation');
|
||||
}
|
||||
|
||||
@@ -217,7 +217,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
state.token,
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
@@ -263,8 +264,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
state.caps.mimeType.contains('word')
|
||||
? Icons.description
|
||||
: state.caps.mimeType.contains('sheet')
|
||||
? Icons.table_chart
|
||||
: Icons.folder_open,
|
||||
? Icons.table_chart
|
||||
: Icons.folder_open,
|
||||
size: 64,
|
||||
color: AppTheme.accentColor,
|
||||
),
|
||||
@@ -351,10 +352,9 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
|
||||
Future<String> _fetchTextContent(String url, String token) async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
).timeout(const Duration(seconds: 30));
|
||||
final response = await http
|
||||
.get(Uri.parse(url), headers: {'Authorization': 'Bearer $token'})
|
||||
.timeout(const Duration(seconds: 30));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
@@ -546,7 +546,8 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
token ?? '',
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
@@ -592,8 +593,8 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
state.caps.mimeType.contains('word')
|
||||
? Icons.description
|
||||
: state.caps.mimeType.contains('sheet')
|
||||
? Icons.table_chart
|
||||
: Icons.folder_open,
|
||||
? Icons.table_chart
|
||||
: Icons.folder_open,
|
||||
size: 64,
|
||||
color: AppTheme.accentColor,
|
||||
),
|
||||
@@ -675,10 +676,9 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
|
||||
Future<String> _fetchTextContent(String url, String token) async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
).timeout(const Duration(seconds: 30));
|
||||
final response = await http
|
||||
.get(Uri.parse(url), headers: {'Authorization': 'Bearer $token'})
|
||||
.timeout(const Duration(seconds: 30));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
|
||||
@@ -162,8 +162,8 @@ class FileService {
|
||||
String targetPath,
|
||||
) async {
|
||||
final endpoint = orgId.isEmpty
|
||||
? '/user/files/move'
|
||||
: '/orgs/$orgId/files/move';
|
||||
? '/user/files/move'
|
||||
: '/orgs/$orgId/files/move';
|
||||
await _apiClient.post(
|
||||
endpoint,
|
||||
data: {'sourcePath': sourcePath, 'targetPath': targetPath},
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:b0esche_cloud/blocs/document_viewer/document_viewer_bloc.dart';
|
||||
import 'package:b0esche_cloud/blocs/document_viewer/document_viewer_event.dart';
|
||||
import 'package:b0esche_cloud/blocs/document_viewer/document_viewer_state.dart';
|
||||
import 'package:b0esche_cloud/services/file_service.dart';
|
||||
import 'package:b0esche_cloud/models/viewer_session.dart';
|
||||
import 'package:b0esche_cloud/models/document_capabilities.dart';
|
||||
import 'package:b0esche_cloud/models/api_error.dart';
|
||||
|
||||
class MockFileService extends Mock implements FileService {
|
||||
Future<ViewerSession>? _viewerResponse;
|
||||
|
||||
void setViewerResponse(Future<ViewerSession> response) {
|
||||
_viewerResponse = response;
|
||||
}
|
||||
|
||||
void resetMock() {
|
||||
_viewerResponse = null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ViewerSession> requestViewerSession(String orgId, String fileId) {
|
||||
return _viewerResponse ??
|
||||
super.noSuchMethod(
|
||||
Invocation.method(#requestViewerSession, [orgId, fileId]),
|
||||
returnValue: Future.value(null),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// @override
|
||||
// Future<ViewerSession> requestViewerSession(String orgId, String fileId) {
|
||||
// return _viewerResponse ??
|
||||
// super.noSuchMethod(
|
||||
// Invocation.method(#requestViewerSession, [orgId, fileId]),
|
||||
// returnValue: Future.value(null),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
void main() {
|
||||
late MockFileService mockFileService;
|
||||
|
||||
setUp(() {
|
||||
mockFileService = MockFileService();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
reset(mockFileService);
|
||||
mockFileService.resetMock();
|
||||
});
|
||||
|
||||
group('DocumentViewerBloc', () {
|
||||
blocTest<DocumentViewerBloc, DocumentViewerState>(
|
||||
'emits [DocumentViewerLoading, DocumentViewerError] when DocumentOpened fails',
|
||||
build: () {
|
||||
mockFileService.setViewerResponse(
|
||||
Future.error(
|
||||
ApiError(
|
||||
code: 'server_error',
|
||||
message: 'Server error',
|
||||
status: 500,
|
||||
),
|
||||
),
|
||||
);
|
||||
return DocumentViewerBloc(mockFileService);
|
||||
},
|
||||
act: (bloc) => bloc.add(DocumentOpened(orgId: 'org1', fileId: 'file1')),
|
||||
expect: () => [
|
||||
DocumentViewerLoading(),
|
||||
DocumentViewerError(message: 'Failed to open document: Server error'),
|
||||
],
|
||||
);
|
||||
|
||||
blocTest<DocumentViewerBloc, DocumentViewerState>(
|
||||
'emits [DocumentViewerLoading, DocumentViewerReady] when DocumentOpened succeeds',
|
||||
build: () {
|
||||
mockFileService.setViewerResponse(
|
||||
Future.value(
|
||||
ViewerSession(
|
||||
viewUrl: Uri.parse('https://example.com/view'),
|
||||
capabilities: DocumentCapabilities(
|
||||
canEdit: true,
|
||||
canAnnotate: false,
|
||||
isPdf: false,
|
||||
),
|
||||
token: 'mock-token',
|
||||
expiresAt: DateTime.now().add(const Duration(minutes: 30)),
|
||||
),
|
||||
),
|
||||
);
|
||||
return DocumentViewerBloc(mockFileService);
|
||||
},
|
||||
act: (bloc) => bloc.add(DocumentOpened(orgId: 'org1', fileId: 'file1')),
|
||||
expect: () => [
|
||||
DocumentViewerLoading(),
|
||||
DocumentViewerReady(
|
||||
viewUrl: Uri.parse('https://example.com/view'),
|
||||
caps: DocumentCapabilities(
|
||||
canEdit: true,
|
||||
canAnnotate: false,
|
||||
isPdf: false,
|
||||
),
|
||||
token: 'mock-token',
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
blocTest<DocumentViewerBloc, DocumentViewerState>(
|
||||
'emits [DocumentViewerInitial] when DocumentClosed',
|
||||
build: () => DocumentViewerBloc(mockFileService),
|
||||
act: (bloc) => bloc.add(DocumentClosed()),
|
||||
expect: () => [DocumentViewerInitial()],
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1587,7 +1587,6 @@ func moveUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB
|
||||
w.Write([]byte(`{"status":"ok"}`))
|
||||
}
|
||||
|
||||
|
||||
// deleteUserFileHandler deletes a file/folder in user's personal workspace by path
|
||||
func deleteUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB, auditLogger *audit.Logger, cfg *config.Config) {
|
||||
userIDStr, ok := middleware.GetUserID(r.Context())
|
||||
|
||||
@@ -272,4 +272,3 @@ func (c *WebDAVClient) Move(ctx context.Context, sourcePath, targetPath string)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("webdav move failed: %d %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user