fix: Avoid adding a repeated server
This commit is contained in:
parent
8ba22fa750
commit
71156337ee
@ -80,6 +80,18 @@ describe('when adding a new server to the same key in the local storage', () =>
|
||||
jest.spyOn(Storage.prototype, 'setItem').mockImplementationOnce(jest.fn())
|
||||
})
|
||||
|
||||
describe('and the new server is already in the array of previously loaded servers', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(Storage.prototype, 'getItem').mockReturnValueOnce([newServer].join(','))
|
||||
addServerToPreviouslyLoaded(newServer)
|
||||
})
|
||||
|
||||
it('should not call the local storage set method to add the new server', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
expect(localStorage.setItem).not.toBeCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('and there was not previous loaded servers in the local storage', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(Storage.prototype, 'getItem').mockReturnValueOnce(null)
|
||||
|
||||
@ -5,6 +5,9 @@ export const getPreviouslyLoadedServers = () =>
|
||||
|
||||
export const addServerToPreviouslyLoaded = (server: string) => {
|
||||
const previouslyLoadedServers = getPreviouslyLoadedServers() || []
|
||||
|
||||
if (previouslyLoadedServers.includes(server)) return
|
||||
|
||||
previouslyLoadedServers.push(server)
|
||||
localStorage.setItem(PREVIOUSLY_LOADED_SERVERS_KEY, previouslyLoadedServers.join(','))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user