Skip to content

Commit

Permalink
+ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tfloxolodeiro committed Dec 5, 2023
1 parent 0ce1ed2 commit cb37b93
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ShareDialog = ({ open, setDialogOpen }: { open: boolean, setDialogOpen: (o
</>
}

const ShareModal = () => {
export const ShareModal = () => {
const { shareId } = useContext(CreatorContext)

const APP_URL = 'https://pilasbloques.program.ar/online'
Expand Down
50 changes: 48 additions & 2 deletions src/test/shareByUrl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ShareModal } from "../components/creator/Editor/ActionButtons/ShareChallenge/ShareButton"
import { ChallengeUpsertButton, ShareButtons } from "../components/creator/Editor/ActionButtons/ShareChallenge/ShareModalButtons"
import { CreatorContextProvider } from "../components/creator/Editor/CreatorContext"
import { SerializedChallenge } from "../components/serializedChallenge"
Expand All @@ -16,6 +17,12 @@ jest.mock("../pbApi", () => {

getSharedChallenge: (id: string) => mockChallenge,

//This mocks the scenario where the updated challenge is from another user
saveChallenge: (challenge: SerializedChallenge) => {
challenge.sharedId = "newShared"
return challenge
}

})
}
})
Expand Down Expand Up @@ -79,14 +86,53 @@ describe("Share by url", () => {
expect(shareButton.textContent).toBe("Compartir por url")
})

test("Should save sharedId when challenge is shared", async () => {
renderComponent(<CreatorContextProvider><ShareButtons/></CreatorContextProvider>)
const shareChallenge = async () => {
renderComponent(<CreatorContextProvider><ShareModal/></CreatorContextProvider>)
const shareButton = await screen.findByTestId('upsertButton')
await act(async () => {shareButton.click()})
}

test("Should save sharedId when challenge is shared", async () => {
await shareChallenge()

expect(LocalStorage.getCreatorChallenge()!.sharedId).toBe("shared")
})

test("Should show share URL on challenge share", async () => {
await shareChallenge()
const urlText = await screen.findByRole('textbox')

expect(urlText.getAttribute('value')).toBe("localhost:3000/#/desafio/guardado/shared")
})

test("Should change to save button on challenge share", async () => {
await shareChallenge()
const saveButton = await screen.findByTestId('upsertButton')

expect(saveButton.textContent).toBe("Guardar desafío")
})


test("Should save new sharedId on challenge save if the returned shared id is different", async() => {
//The mock of the pbApi always returns 'newShared' as id on challenge save
await shareChallenge()
const saveButton = await screen.findByTestId('upsertButton')
await act(async () => {saveButton.click()})

expect(LocalStorage.getCreatorChallenge()!.sharedId).toBe("newShared")
})

test.skip("Should change share URL on challenge save if the returned shared id is different", async() => {
//The mock of the pbApi always returns 'newShared' as id on challenge save
await shareChallenge()
const saveButton = await screen.findByTestId('upsertButton')
await act(async () => {saveButton.click()})
const urlText = await screen.findByRole('textbox')

//The url text is not changing in the text
expect(urlText.getAttribute('value')).toBe("localhost:3000/#/desafio/guardado/newShared")
})

})

})

0 comments on commit cb37b93

Please sign in to comment.