generated from xwiki-contrib/github-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRISTAL-194: Support for images edition
Add test for DefaultDocumentService
- Loading branch information
1 parent
8070b58
commit f6c95e8
Showing
4 changed files
with
118 additions
and
1 deletion.
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
80 changes: 80 additions & 0 deletions
80
core/document/document-default/src/__tests__/defaultDocumentService.test.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,80 @@ | ||
/* | ||
* See the LICENSE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
import { DefaultDocumentService } from "../defaultDocumentService"; | ||
import { flushPromises } from "@vue/test-utils"; | ||
import { | ||
ModelReferenceParser, | ||
ModelReferenceParserProvider, | ||
ModelReferenceSerializer, | ||
ModelReferenceSerializerProvider, | ||
} from "@xwiki/cristal-model-reference-api"; | ||
import { Container } from "inversify"; | ||
import { createPinia, setActivePinia } from "pinia"; | ||
import { beforeEach, describe, expect, it } from "vitest"; | ||
import { MockProxy, any, mock } from "vitest-mock-extended"; | ||
import type { CristalApp, PageData } from "@xwiki/cristal-api"; | ||
|
||
function initMocks(): MockProxy<CristalApp> & CristalApp { | ||
const cristalMock = mock<CristalApp>(); | ||
const containerMock = mock<Container>(); | ||
const modelReferenceParserProviderMock = mock<ModelReferenceParserProvider>(); | ||
modelReferenceParserProviderMock.get.mockReturnValue( | ||
mock<ModelReferenceParser>(), | ||
); | ||
const modelReferenceSerializerProviderMock = | ||
mock<ModelReferenceSerializerProvider>(); | ||
modelReferenceSerializerProviderMock.get.mockReturnValue( | ||
mock<ModelReferenceSerializer>(), | ||
); | ||
|
||
containerMock.get | ||
.calledWith("ModelReferenceParserProvider") | ||
.mockReturnValue(modelReferenceParserProviderMock); | ||
containerMock.get | ||
.calledWith("ModelReferenceSerializerProvider") | ||
.mockReturnValue(modelReferenceSerializerProviderMock); | ||
cristalMock.getContainer.mockReturnValue(containerMock); | ||
|
||
return cristalMock; | ||
} | ||
|
||
describe("defaultDocumentService", () => { | ||
beforeEach(() => { | ||
// creates a fresh pinia and makes it active so it's automatically picked up by any useStore() call without having | ||
// to pass it to it: `useStore(pinia)` | ||
setActivePinia(createPinia()); | ||
}); | ||
it("setCurrentDocument", async () => { | ||
const mockPageData = mock<PageData>(); | ||
const cristalMock = initMocks(); | ||
cristalMock.getPage | ||
.calledWith("A.B.C", any()) | ||
.mockReturnValue(Promise.resolve(mockPageData)); | ||
const defaultDocumentService = new DefaultDocumentService(cristalMock); | ||
|
||
const currentDocument = defaultDocumentService.getCurrentDocument(); | ||
|
||
expect(currentDocument.value).toBeUndefined(); | ||
defaultDocumentService.setCurrentDocument("A.B.C"); | ||
// Wait for the asynchronous store operations | ||
await flushPromises(); | ||
expect(currentDocument.value).toBe(mockPageData); | ||
}); | ||
}); |
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,25 @@ | ||
/* | ||
* See the LICENSE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
import localConfig from "./vite.config"; | ||
import { mergeConfig } from "vitest/config"; | ||
import defaultConfig from "@xwiki/cristal-dev-config/vitest-vue.config"; | ||
|
||
export default mergeConfig(defaultConfig, localConfig); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.