fix: Fixing test suite
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mangiang 2021-12-08 15:23:33 -05:00
parent a647ea1485
commit 83937bd78d
10 changed files with 54 additions and 33 deletions

View File

@ -4,7 +4,7 @@ describe('Dark Mode Toggle', () => {
beforeEach(() => {
cy.window()
.its("sessionStorage")
.invoke("removeItem", "items.sp-tarkov.com-locales");
.invoke("removeItem", "db.sp-tarkov.com-locales");
cy.intercept(
'**/api/locales',
@ -35,7 +35,7 @@ describe('Dark Mode Toggle', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.removeItem('items.sp-tarkov.com-prefered-color-scheme')
window.localStorage.removeItem('db.sp-tarkov.com-prefered-color-scheme')
}
})
})
@ -55,7 +55,7 @@ describe('Dark Mode Toggle', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-color-scheme', 'light')
window.localStorage.setItem('db.sp-tarkov.com-prefered-color-scheme', 'light')
}
})
})
@ -74,7 +74,7 @@ describe('Dark Mode Toggle', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-color-scheme', 'dark')
window.localStorage.setItem('db.sp-tarkov.com-prefered-color-scheme', 'dark')
}
})
})
@ -94,7 +94,7 @@ describe('Dark Mode Toggle', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-color-scheme', 'light')
window.localStorage.setItem('db.sp-tarkov.com-prefered-color-scheme', 'light')
}
})
})
@ -123,7 +123,7 @@ describe('Dark Mode Toggle', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-color-scheme', 'dark')
window.localStorage.setItem('db.sp-tarkov.com-prefered-color-scheme', 'dark')
}
})
})

View File

@ -4,7 +4,7 @@ describe('Header', () => {
beforeEach(() => {
cy.window()
.its("sessionStorage")
.invoke("removeItem", "items.sp-tarkov.com-locales");
.invoke("removeItem", "db.sp-tarkov.com-locales");
cy.intercept(
'**/api/locales',

View File

@ -4,7 +4,7 @@ describe('Json Theme', () => {
beforeEach(() => {
cy.window()
.its("sessionStorage")
.invoke("removeItem", "items.sp-tarkov.com-locales");
.invoke("removeItem", "db.sp-tarkov.com-locales");
cy.intercept(
'**/api/locales',
@ -35,7 +35,7 @@ describe('Json Theme', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.removeItem('items.sp-tarkov.com-prefered-json-theme')
window.localStorage.removeItem('db.sp-tarkov.com-prefered-json-theme')
}
});
})
@ -54,7 +54,7 @@ describe('Json Theme', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-json-theme', 'eighties')
window.localStorage.setItem('db.sp-tarkov.com-prefered-json-theme', 'eighties')
}
});
})

View File

@ -4,7 +4,7 @@ describe('Locale select', () => {
beforeEach(() => {
cy.window()
.its("sessionStorage")
.invoke("removeItem", "items.sp-tarkov.com-locales");
.invoke("removeItem", "db.sp-tarkov.com-locales");
cy.intercept(
'**/api/locales',
@ -31,7 +31,7 @@ describe('Locale select', () => {
[]).as('getLocalesWithoutData');
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.removeItem('items.sp-tarkov.com-prefered-locale')
window.localStorage.removeItem('db.sp-tarkov.com-prefered-locale')
}
})
})
@ -60,7 +60,7 @@ describe('Locale select', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.removeItem('items.sp-tarkov.com-prefered-locale')
window.localStorage.removeItem('db.sp-tarkov.com-prefered-locale')
}
})
})
@ -77,7 +77,7 @@ describe('Locale select', () => {
before(() => {
cy.visit('/', {
onBeforeLoad: function (window) {
window.localStorage.setItem('items.sp-tarkov.com-prefered-locale', 'locale2')
window.localStorage.setItem('db.sp-tarkov.com-prefered-locale', 'locale2')
}
})
})

View File

@ -20,6 +20,14 @@ describe('Search area', ()=>{
body: condensedMilk
})
cy.intercept({
method: 'POST',
url: '**/api/search*'
}, {
statusCode: 200,
body: []
})
cy.intercept({
method: 'GET',
url: '**/api/item/hierarchy*'

View File

@ -1,12 +1,12 @@
export {};
import condensedMilk from '../fixtures/condensed_milk.json'
export {};
describe('Url check', () => {
beforeEach(() => {
cy.window()
.its("sessionStorage")
.invoke("removeItem", "items.sp-tarkov.com-locales");
.invoke("removeItem", "db.sp-tarkov.com-locales");
cy.intercept({
method: 'GET',
@ -24,6 +24,15 @@ describe('Url check', () => {
body: condensedMilk
})
cy.intercept({
method: 'POST',
url: '**/api/search*'
}, {
statusCode: 200,
body: []
})
cy.intercept({
method: 'GET',
url: '**/api/item/hierarchy*'

View File

@ -4,12 +4,16 @@ import { ItemData } from '../dto/ItemData';
import { useGlobalState } from '../state/GlobalState';
const handleFetch = async (url: string, init?: RequestInit | undefined): Promise<any | null> => {
try {
const resp = await fetch(url, { ...init, mode: 'cors' })
if (resp.status === 200) {
const jsonResponse = await resp.json();
return jsonResponse !== undefined ? jsonResponse : null;
} else if (resp.status >= 400) {
console.error(resp)
console.warn(resp)
}
}catch (e) {
console.warn(e)
}
return null;
}

View File

@ -1,10 +1,10 @@
export enum LocalStorageKeys {
PREFERED_COLOR_SCHEME = 'items.sp-tarkov.com-prefered-color-scheme',
PREFERED_JSON_THEME = 'items.sp-tarkov.com-prefered-json-theme',
PREFERED_LOCALE = 'items.sp-tarkov.com-prefered-locale'
PREFERED_COLOR_SCHEME = 'db.sp-tarkov.com-prefered-color-scheme',
PREFERED_JSON_THEME = 'db.sp-tarkov.com-prefered-json-theme',
PREFERED_LOCALE = 'db.sp-tarkov.com-prefered-locale'
}
export enum SessionStorageKeys {
LOCALES = 'items.sp-tarkov.com-locales',
ITEMS_HIERARCHY = 'items.sp-tarkov.com-items-hierarchy',
LOCALES = 'db.sp-tarkov.com-locales',
ITEMS_HIERARCHY = 'db.sp-tarkov.com-items-hierarchy',
}

View File

@ -26,11 +26,11 @@ export const MainPage = () => {
<Header/>
<BrowserRouter>
<Routes>
<Route path="/search" element={<InteractiveArea/>}>
<Route path=":id" element={<InteractiveArea/>}/>
</Route>
<Route path="/search" element={<InteractiveArea/>}/>
<Route path="/search/:id" element={<InteractiveArea/>}/>
<Route path="/404" element={<PageNotFound />}/>
<Route path="/" element={<Navigate replace to="/search"/>}/>
<Route path="*" element={<PageNotFound/>}/>
<Route path="*" element={<Navigate replace to="/404" />} />
</Routes>
</BrowserRouter>
<Footer/>

View File

@ -57,7 +57,7 @@ export const useGlobalState = create<GlobalState>((set) => ({
localesList: [],
refreshLocalesList: async () => {
const locales = sessionStorage.getItem(SessionStorageKeys.LOCALES);
const localesList = locales !== null && locales !== undefined && locales !== 'undefined' ? JSON.parse(locales) : await getLocaleList()
const localesList = locales !== null && locales !== undefined && locales !== 'undefined' && locales !== 'null' ? JSON.parse(locales) : await getLocaleList()
if (!locales) sessionStorage.setItem(SessionStorageKeys.LOCALES, JSON.stringify(localesList ? localesList : null))
set((_state) => ({ localesList: localesList ? localesList : [] }))
},