mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(media hosting): restore android imgur support
This commit is contained in:
+3
-3
@@ -107,18 +107,18 @@ describe('MediaHostingSettings', () => {
|
||||
expect(mockSetUploadMode).toHaveBeenCalledWith('none');
|
||||
});
|
||||
|
||||
it('disables unsupported providers on Android', async () => {
|
||||
it('enables Imgur on Android', async () => {
|
||||
uploadModeRef.value = 'preferred';
|
||||
preferredProviderRef.value = 'catbox';
|
||||
mockGetPlatform.mockReturnValue('android');
|
||||
render();
|
||||
const imgurRadio = container.querySelector<HTMLInputElement>('input[value="imgur"]');
|
||||
expect(imgurRadio).not.toBeNull();
|
||||
expect(imgurRadio?.disabled).toBe(true);
|
||||
expect(imgurRadio?.disabled).toBe(false);
|
||||
await act(async () => {
|
||||
imgurRadio?.click();
|
||||
});
|
||||
expect(mockSetPreferredProvider).not.toHaveBeenCalled();
|
||||
expect(mockSetPreferredProvider).toHaveBeenCalledWith('imgur');
|
||||
});
|
||||
|
||||
it('clicking supported provider in preferred mode calls setPreferredProvider', async () => {
|
||||
|
||||
@@ -44,8 +44,8 @@ vi.mock('../../lib/media-hosting/provider-order', () => ({
|
||||
if (opts.mode === 'none') return [];
|
||||
if (opts.runtime === 'web') return filterAvailable(opts.preferredProvider === 'catbox' ? ['catbox'] : []);
|
||||
if (opts.runtime === 'android') {
|
||||
if (opts.mode === 'preferred') return filterAvailable(opts.preferredProvider === 'catbox' || opts.preferredProvider === 'imgbb' ? [opts.preferredProvider] : []);
|
||||
return filterAvailable(['catbox', 'imgbb']);
|
||||
if (opts.mode === 'preferred') return filterAvailable(['catbox', 'imgur', 'imgbb'].includes(opts.preferredProvider) ? [opts.preferredProvider] : []);
|
||||
return filterAvailable(['catbox', 'imgur', 'imgbb']);
|
||||
}
|
||||
return filterAvailable(opts.mode === 'preferred' ? [opts.preferredProvider] : ['catbox', 'imgur', 'imgbb']);
|
||||
}),
|
||||
@@ -332,9 +332,10 @@ describe('useFileUpload', () => {
|
||||
expect(hook().isUploading).toBe(false);
|
||||
});
|
||||
|
||||
it('does not call Android plugin when preferred provider is unsupported', async () => {
|
||||
it('does not call Android plugin when preferred Imgur is unavailable from this network', async () => {
|
||||
uploadModeRef.value = 'preferred';
|
||||
preferredProviderRef.value = 'imgur';
|
||||
providerAvailabilityRef.value = { imgur: 'unavailable' };
|
||||
vi.mocked(Capacitor.getPlatform).mockReturnValue('android');
|
||||
const { onUploadComplete, hook } = mountHook();
|
||||
|
||||
@@ -343,7 +344,7 @@ describe('useFileUpload', () => {
|
||||
});
|
||||
|
||||
expect(FileUploader.pickAndUploadMedia).not.toHaveBeenCalled();
|
||||
expect(window.alert).toHaveBeenCalledWith('upload_failed: imgur is not supported on android. upload_failed_preferred_guidance');
|
||||
expect(window.alert).toHaveBeenCalledWith('upload_failed: imgur is unavailable from this network. upload_failed_preferred_guidance');
|
||||
expect(onUploadComplete).not.toHaveBeenCalled();
|
||||
expect(hook().isUploading).toBe(false);
|
||||
});
|
||||
@@ -368,7 +369,7 @@ describe('useFileUpload', () => {
|
||||
it('does not call Android plugin when random mode has no reachable providers', async () => {
|
||||
uploadModeRef.value = 'random';
|
||||
preferredProviderRef.value = 'catbox';
|
||||
providerAvailabilityRef.value = { catbox: 'unavailable', imgbb: 'unavailable' };
|
||||
providerAvailabilityRef.value = { catbox: 'unavailable', imgur: 'unavailable', imgbb: 'unavailable' };
|
||||
vi.mocked(Capacitor.getPlatform).mockReturnValue('android');
|
||||
const { onUploadComplete, hook } = mountHook();
|
||||
|
||||
@@ -401,6 +402,25 @@ describe('useFileUpload', () => {
|
||||
expect(onUploadComplete).toHaveBeenCalledWith('https://i.ibb.co/example/android.png', 'android.png');
|
||||
});
|
||||
|
||||
it('calls Android plugin with only Imgur when Imgur is chosen and reachable', async () => {
|
||||
uploadModeRef.value = 'preferred';
|
||||
preferredProviderRef.value = 'imgur';
|
||||
vi.mocked(Capacitor.getPlatform).mockReturnValue('android');
|
||||
vi.mocked(FileUploader.pickAndUploadMedia).mockResolvedValue({
|
||||
url: 'https://i.imgur.com/example.png',
|
||||
fileName: 'android.png',
|
||||
provider: 'imgur',
|
||||
});
|
||||
const { onUploadComplete, hook } = mountHook();
|
||||
|
||||
await act(async () => {
|
||||
await hook().handleUpload();
|
||||
});
|
||||
|
||||
expect(FileUploader.pickAndUploadMedia).toHaveBeenCalledWith({ providerOrder: ['imgur'] });
|
||||
expect(onUploadComplete).toHaveBeenCalledWith('https://i.imgur.com/example.png', 'android.png');
|
||||
});
|
||||
|
||||
it('Android call includes provider order payload', async () => {
|
||||
uploadModeRef.value = 'random';
|
||||
preferredProviderRef.value = 'catbox';
|
||||
@@ -422,6 +442,7 @@ describe('useFileUpload', () => {
|
||||
});
|
||||
const call = vi.mocked(FileUploader.pickAndUploadMedia).mock.calls[0][0];
|
||||
expect(call?.providerOrder).toEqual(expect.arrayContaining(['catbox']));
|
||||
expect(call?.providerOrder).toEqual(expect.arrayContaining(['imgur']));
|
||||
expect(call?.providerOrder).toEqual(expect.arrayContaining(['imgbb']));
|
||||
expect(onUploadComplete).toHaveBeenCalledWith('https://files.catbox.moe/random.jpg', 'random.jpg');
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('provider-availability', () => {
|
||||
|
||||
expect(snapshot.catbox).toBe('available');
|
||||
expect(snapshot.imgbb).toBe('available');
|
||||
expect(snapshot.imgur).toBe('unknown');
|
||||
expect(snapshot.imgur).toBe('available');
|
||||
});
|
||||
|
||||
it('marks a provider unavailable when one of its media probes fails', async () => {
|
||||
|
||||
@@ -55,6 +55,13 @@ describe('provider-order', () => {
|
||||
runtime: 'web',
|
||||
}),
|
||||
).toEqual(['catbox']);
|
||||
expect(
|
||||
getProviderOrder({
|
||||
mode: 'preferred',
|
||||
preferredProvider: 'imgur',
|
||||
runtime: 'android',
|
||||
}),
|
||||
).toEqual(['imgur']);
|
||||
expect(
|
||||
getProviderOrder({
|
||||
mode: 'preferred',
|
||||
@@ -79,13 +86,6 @@ describe('provider-order', () => {
|
||||
runtime: 'web',
|
||||
}),
|
||||
).toEqual([]);
|
||||
expect(
|
||||
getProviderOrder({
|
||||
mode: 'preferred',
|
||||
preferredProvider: 'imgur',
|
||||
runtime: 'android',
|
||||
}),
|
||||
).toEqual([]);
|
||||
expect(
|
||||
getProviderOrder({
|
||||
mode: 'preferred',
|
||||
@@ -137,14 +137,14 @@ describe('provider-order', () => {
|
||||
expect(order).toEqual(['catbox']);
|
||||
});
|
||||
|
||||
it('uses catbox and imgbb for android random mode', () => {
|
||||
it('uses catbox, imgur, and imgbb for android random mode', () => {
|
||||
const order = getProviderOrder({
|
||||
mode: 'random',
|
||||
preferredProvider: 'catbox',
|
||||
runtime: 'android',
|
||||
});
|
||||
expect(order).toHaveLength(2);
|
||||
expect([...order].sort()).toEqual(['catbox', 'imgbb']);
|
||||
expect(order).toHaveLength(3);
|
||||
expect([...order].sort()).toEqual(['catbox', 'imgbb', 'imgur']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ export const MEDIA_HOSTING_PROVIDERS: readonly ProviderDefinition[] = [
|
||||
label: 'Imgur',
|
||||
homepageUrl: 'https://imgur.com',
|
||||
availabilityProbeUrls: ['https://s.imgur.com/images/favicon-32x32.png', 'https://i.imgur.com/YpB7qfa.jpg'],
|
||||
supportedRuntimes: ['electron'],
|
||||
supportedRuntimes: ['electron', 'android'],
|
||||
},
|
||||
{
|
||||
id: 'imgbb',
|
||||
|
||||
@@ -28,6 +28,14 @@ describe('useMediaHostingStore', () => {
|
||||
availabilityProbeUrls: ['https://catbox.moe/pictures/logo.png', 'https://files.catbox.moe/8ten4y.png'],
|
||||
supportedRuntimes: ['web', 'electron', 'android'],
|
||||
});
|
||||
const imgur = MEDIA_HOSTING_PROVIDERS.find((p) => p.id === 'imgur');
|
||||
expect(imgur).toEqual({
|
||||
id: 'imgur',
|
||||
label: 'Imgur',
|
||||
homepageUrl: 'https://imgur.com',
|
||||
availabilityProbeUrls: ['https://s.imgur.com/images/favicon-32x32.png', 'https://i.imgur.com/YpB7qfa.jpg'],
|
||||
supportedRuntimes: ['electron', 'android'],
|
||||
});
|
||||
const imgbb = MEDIA_HOSTING_PROVIDERS.find((p) => p.id === 'imgbb');
|
||||
expect(imgbb).toEqual({
|
||||
id: 'imgbb',
|
||||
|
||||
Reference in New Issue
Block a user