7d493d61db
no issue
- Fixed a bug where the Unsplash button in site design didn't hide if
the integration was disabled.
- Cleaned up Unsplash in preparation for moving it to it's own package
in future.
---
<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 4da5d12</samp>
Refactored and improved the Unsplash integration feature in the admin
settings app. Moved all files related to Unsplash to a separate
`unsplash` folder and renamed some classes and interfaces to avoid
confusion. Added a feature flag for Unsplash in the brand settings
component and a prop to customize the portal container for the Unsplash
search modal. Created a new class `PhotoUseCases` to handle the logic
for fetching, searching, and downloading photos from Unsplash.
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import MasonryService from '../../../src/unsplash/masonry/MasonryService';
|
|
import {IUnsplashService, UnsplashService} from '../../../src/unsplash/UnsplashService';
|
|
import {InMemoryUnsplashProvider} from '../../../src/unsplash/api/InMemoryUnsplashProvider';
|
|
import {PhotoUseCases} from '../../../src/unsplash/photo/PhotoUseCase';
|
|
import {fixturePhotos} from '../../../src/unsplash/api/unsplashFixtures';
|
|
|
|
describe('UnsplashService', () => {
|
|
let unsplashService: IUnsplashService;
|
|
let UnsplashProvider: InMemoryUnsplashProvider;
|
|
let masonryService: MasonryService;
|
|
let photoUseCases: PhotoUseCases;
|
|
|
|
beforeEach(() => {
|
|
UnsplashProvider = new InMemoryUnsplashProvider();
|
|
masonryService = new MasonryService(3);
|
|
photoUseCases = new PhotoUseCases(UnsplashProvider);
|
|
unsplashService = new UnsplashService(photoUseCases, masonryService);
|
|
});
|
|
|
|
it('can load new photos', async function () {
|
|
await unsplashService.loadNew();
|
|
const photos = unsplashService.photos;
|
|
expect(photos).toEqual(fixturePhotos);
|
|
});
|
|
|
|
it('set up new columns of 3', async function () {
|
|
await unsplashService.loadNew();
|
|
const columns = unsplashService.getColumns();
|
|
if (columns) {
|
|
expect(columns.length).toBe(3);
|
|
}
|
|
});
|
|
|
|
it('can search for photos', async function () {
|
|
await unsplashService.updateSearch('cat');
|
|
const photos = unsplashService.photos;
|
|
expect(photos.length).toBe(0);
|
|
await unsplashService.updateSearch('photo');
|
|
const photos2 = unsplashService.photos;
|
|
expect(photos2.length).toBe(1);
|
|
});
|
|
|
|
it('can check if search is running', async function () {
|
|
const isRunning = unsplashService.searchIsRunning();
|
|
expect(isRunning).toBe(false);
|
|
});
|
|
|
|
it('can load next page', async function () {
|
|
await unsplashService.loadNextPage();
|
|
const photos = unsplashService.photos;
|
|
expect(photos.length).toBe(2);
|
|
});
|
|
});
|