-
Notifications
You must be signed in to change notification settings - Fork 157
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 #11752 from owncloud/app-store-unit-tests
App store unit tests (first batch)
- Loading branch information
Showing
14 changed files
with
649 additions
and
19 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
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
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
57 changes: 57 additions & 0 deletions
57
packages/web-app-app-store/tests/unit/LayoutContainer.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,57 @@ | ||
import LayoutContainer from '../../src/LayoutContainer.vue' | ||
import { | ||
defaultComponentMocks, | ||
defaultPlugins, | ||
mount, | ||
nextTicks | ||
} from '@ownclouders/web-test-helpers' | ||
import { useAppsStore } from '../../src/piniaStores' | ||
|
||
const selectors = { | ||
loadingSpinner: '#app-loading-spinner', | ||
routerView: '[data-testid="app-store-router-view"]' | ||
} | ||
|
||
describe('LayoutContainer', () => { | ||
it('shows a loading spinner while apps are loading from repositories', () => { | ||
const { wrapper } = getWrapper({ keepLoadingApps: true }) | ||
expect(wrapper.find(selectors.loadingSpinner).exists()).toBeTruthy() | ||
expect(wrapper.find(selectors.routerView).exists()).toBeFalsy() | ||
}) | ||
it('renders the router view when loading apps is done', async () => { | ||
const { wrapper } = getWrapper({}) | ||
await nextTicks(2) | ||
expect(wrapper.find(selectors.loadingSpinner).exists()).toBeFalsy() | ||
expect(wrapper.find(selectors.routerView).exists()).toBeTruthy() | ||
}) | ||
}) | ||
|
||
function getWrapper({ keepLoadingApps }: { keepLoadingApps?: boolean }) { | ||
const plugins = defaultPlugins({}) | ||
|
||
const { loadApps } = useAppsStore() | ||
vi.mocked(loadApps).mockReturnValue( | ||
new Promise((res) => { | ||
if (!keepLoadingApps) { | ||
return res() | ||
} | ||
return setTimeout(() => res(), 500) | ||
}) | ||
) | ||
|
||
const mocks = { | ||
...defaultComponentMocks(), | ||
loadApps | ||
} | ||
|
||
return { | ||
mocks, | ||
wrapper: mount(LayoutContainer, { | ||
global: { | ||
mocks, | ||
provide: mocks, | ||
plugins | ||
} | ||
}) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/web-app-app-store/tests/unit/components/AppActions.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,54 @@ | ||
import { defaultPlugins, mount } from '@ownclouders/web-test-helpers' | ||
import AppActions from '../../../src/components/AppActions.vue' | ||
import { App, AppVersion } from '../../../src/types' | ||
import { mock } from 'vitest-mock-extended' | ||
|
||
const version1: AppVersion = { | ||
version: '1.0.0', | ||
url: 'https://example.com/app-1.0.0.zip' | ||
} | ||
const version2: AppVersion = { | ||
version: '1.1.0', | ||
url: 'https://example.com/app-1.1.0.zip' | ||
} | ||
const versions = [version1, version2] | ||
const mostRecentVersion = version2 | ||
|
||
const selectors = { | ||
downloadButton: 'button' | ||
} | ||
|
||
describe('AppActions', () => { | ||
it('renders a "Download" button', () => { | ||
const { wrapper } = getWrapper({}) | ||
expect(wrapper.find(selectors.downloadButton).text()).toBe('Download') | ||
}) | ||
describe('calling the "download" handler', () => { | ||
it('uses the most recent version when none is specified', async () => { | ||
const { wrapper } = getWrapper({}) | ||
await wrapper.find(selectors.downloadButton).trigger('click') | ||
expect(window.location.href).toBe(mostRecentVersion.url) | ||
}) | ||
it('uses the version provided via props', async () => { | ||
const { wrapper } = getWrapper({ version: version1 }) | ||
await wrapper.find(selectors.downloadButton).trigger('click') | ||
expect(window.location.href).toBe(version1.url) | ||
}) | ||
}) | ||
}) | ||
|
||
const getWrapper = ({ version }: { version?: AppVersion }) => { | ||
const app = { ...mock<App>({}), versions, mostRecentVersion } | ||
|
||
return { | ||
wrapper: mount(AppActions, { | ||
props: { | ||
app, | ||
version | ||
}, | ||
global: { | ||
plugins: [...defaultPlugins()] | ||
} | ||
}) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/web-app-app-store/tests/unit/components/AppAuthors.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,58 @@ | ||
import AppAuthors from '../../../src/components/AppAuthors.vue' | ||
import { mock } from 'vitest-mock-extended' | ||
import { App, AppAuthor } from '../../../src/types' | ||
import { mount } from '@ownclouders/web-test-helpers' | ||
|
||
const author1: AppAuthor = { | ||
name: 'John Doe', | ||
url: 'https://johndoe.com' | ||
} | ||
const author2: AppAuthor = { | ||
name: 'Jane Doe' | ||
} | ||
const author3: AppAuthor = { | ||
name: 'Wololo Priest', | ||
url: 'wololo' | ||
} | ||
const author4: AppAuthor = { | ||
url: 'trololo' | ||
} | ||
const authors = [author1, author2, author3, author4] | ||
|
||
const selectors = { | ||
item: '.app-author-item', | ||
link: '[data-testid="author-link"]', | ||
label: '[data-testid="author-label"]' | ||
} | ||
|
||
describe('AppAuthors.vue', () => { | ||
it('renders only authors with name and valid or empty url', () => { | ||
const { wrapper } = getWrapper() | ||
expect(wrapper.findAll(selectors.item).length).toBe(2) | ||
}) | ||
it('renders authors as link when they have a url and name', () => { | ||
const { wrapper } = getWrapper() | ||
const author = wrapper.findAll(selectors.item).at(0) | ||
expect(author.exists()).toBeTruthy() | ||
const link = author.find(selectors.link) | ||
expect(link.exists()).toBeTruthy() | ||
expect(link.attributes().href).toBe(author1.url) | ||
expect(link.text()).toBe(author1.name) | ||
}) | ||
it('renders authors as span when they only have a name', () => { | ||
const { wrapper } = getWrapper() | ||
const author = wrapper.findAll(selectors.item).at(1) | ||
expect(author.find(selectors.link).exists()).toBeFalsy() | ||
expect(author.find(selectors.label).text()).toBe(author2.name) | ||
}) | ||
}) | ||
|
||
const getWrapper = () => { | ||
const app = { ...mock<App>({}), authors } | ||
|
||
return { | ||
wrapper: mount(AppAuthors, { | ||
props: { app } | ||
}) | ||
} | ||
} |
Oops, something went wrong.