-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUN-2307 unit tests for edit project file #9084
Changes from 1 commit
e39d1da
daaeff5
b2aa351
d57d5b4
7662d52
71be35b
fd2910e
270021e
3b6970d
36984ad
972c418
eddb439
8e3da89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,9 +35,7 @@ jest.mock("@/library/rundeckService", () => ({ | |||||
}), | ||||||
url: jest.fn().mockReturnValue("http://localhost:4440"), | ||||||
})); | ||||||
|
||||||
let wrapper; | ||||||
|
||||||
const mountEditProjectFile = async (props = {}) => { | ||||||
wrapper = mount(EditProjectFile, { | ||||||
props: { | ||||||
|
@@ -63,26 +61,21 @@ describe("EditProjectFile", () => { | |||||
jest.clearAllMocks(); | ||||||
}); | ||||||
|
||||||
// This test checks if the correct title is rendered based on the filename | ||||||
describe.each([ | ||||||
it.each([ | ||||||
["readme.md", "edit.readme.label"], | ||||||
["motd.md", "edit.motd.label"], | ||||||
])("renders the correct title for %s", (filename, expectedTitle) => { | ||||||
it("checks title", async () => { | ||||||
await mountEditProjectFile({ filename }); | ||||||
expect(wrapper.find('[data-test-id="title"]').text()).toContain( | ||||||
expectedTitle, | ||||||
); | ||||||
}); | ||||||
])("renders the correct title for %s", async (filename, expectedTitle) => { | ||||||
await mountEditProjectFile({ filename }); | ||||||
expect(wrapper.find('[data-test-id="title"]').text()).toContain( | ||||||
expectedTitle, | ||||||
); | ||||||
}); | ||||||
|
||||||
// This test checks if the file content is rendered when the getFileText method returns successfully | ||||||
it("renders file content when getFileText method returns successfully", async () => { | ||||||
await wrapper.vm.$nextTick(); | ||||||
expect(wrapper.vm.fileText).toBe("sample file content"); | ||||||
}); | ||||||
|
||||||
// This test checks if an error is handled correctly when the getFileText method fails | ||||||
it("handles failure when getFileText method fails", async () => { | ||||||
(editProjectFileService.getFileText as jest.Mock).mockImplementationOnce( | ||||||
() => Promise.reject(new Error("Failed to fetch file")), | ||||||
|
@@ -92,7 +85,6 @@ describe("EditProjectFile", () => { | |||||
expect(wrapper.vm.notifyError).toHaveBeenCalledWith("Failed to fetch file"); | ||||||
}); | ||||||
|
||||||
// This test checks if an error is handled correctly when the user edits the file and fails to save it | ||||||
it("handles failure when user edits the file and fails to save it", async () => { | ||||||
(editProjectFileService.saveProjectFile as jest.Mock).mockRejectedValue( | ||||||
new Error("Failed to save file"), | ||||||
|
@@ -103,7 +95,6 @@ describe("EditProjectFile", () => { | |||||
expect(wrapper.vm.notifyError).toHaveBeenCalledWith("Failed to save file"); | ||||||
}); | ||||||
|
||||||
// This test checks if the file is saved successfully when the user edits the file and saves it | ||||||
it("handles success when user edits the file and saves it", async () => { | ||||||
wrapper.vm.fileText = "new content"; | ||||||
await wrapper.find('[data-test-id="save"]').trigger("click"); | ||||||
|
@@ -112,7 +103,6 @@ describe("EditProjectFile", () => { | |||||
).toHaveBeenCalledWith("default", "readme.md", "new content"); | ||||||
}); | ||||||
|
||||||
// This test checks if the correct message and configuration link are displayed when the user is an admin | ||||||
it("displays admin specific message and configuration link when user is an admin", async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
await mountEditProjectFile({ | ||||||
displayConfig: ["none"], | ||||||
|
@@ -124,7 +114,6 @@ describe("EditProjectFile", () => { | |||||
); | ||||||
}); | ||||||
|
||||||
// This test checks if the correct message is displayed when the user is not an admin | ||||||
it("displays non-admin specific message when user is not an admin", async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
await mountEditProjectFile({ | ||||||
authAdmin: false, | ||||||
|
@@ -135,31 +124,17 @@ describe("EditProjectFile", () => { | |||||
"file.warning.not.displayed.nonadmin.message", | ||||||
); | ||||||
}); | ||||||
|
||||||
// This test checks if the save button is not displayed for non-admin users | ||||||
it("does not allow non-admin user to save the file", async () => { | ||||||
await mountEditProjectFile({ authAdmin: false }); | ||||||
expect(wrapper.find('[data-test-id="save"]').exists()).toBe(false); | ||||||
}); | ||||||
|
||||||
// This test checks if the editor is not displayed for non-admin users | ||||||
it("does not allow non-admin user to edit the file", async () => { | ||||||
await mountEditProjectFile({ authAdmin: false }); | ||||||
expect(wrapper.find('[data-test-id="editor"]').exists()).toBe(false); | ||||||
}); | ||||||
|
||||||
// This test checks if the Ace Editor is rendered | ||||||
it("renders the Ace Editor", () => { | ||||||
const aceEditor = wrapper.find('[data-test-id="ace-editor"]'); | ||||||
expect(aceEditor.exists()).toBe(true); | ||||||
}); | ||||||
//TODO: working on this one | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smartinellibenedetti Can you please look at it? This one not working. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you trigger actions that require the UI to re-render, remember to do a:
before trying to assert the values |
||||||
// it("does not change file content when user cancels the edit", async () => { | ||||||
// | ||||||
// }); | ||||||
}); | ||||||
|
||||||
// This one is commented out because it is not working as expected | ||||||
// it("does not change file content when user cancels the edit", async () => { | ||||||
// const originalFileText = wrapper.vm.fileText; | ||||||
// wrapper.vm.fileText = "new content"; | ||||||
// await wrapper.find('[data-test-id="cancel"]').trigger("click"); | ||||||
// console.log("After click event:", wrapper.vm.fileText); | ||||||
// expect(wrapper.vm.fileText).toBe(originalFileText); | ||||||
// }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change this test to assert instead that the HTML rendered by ace-editor has this string inside of it?