diff --git a/items/frontend/cypress/fixtures/condensed_milk.json b/items/frontend/cypress/fixtures/condensed_milk.json new file mode 100644 index 0000000..8493398 --- /dev/null +++ b/items/frontend/cypress/fixtures/condensed_milk.json @@ -0,0 +1,84 @@ +{ + "item": { + "_id": "5734773724597737fd047c14", + "_name": "condensed_milk", + "_parent": "5448e8d04bdc2ddf718b4569", + "_props": { + "AllowSpawnOnLocations": [], + "AnimationVariantsNumber": 0, + "BackgroundColor": "orange", + "CanRequireOnRagfair": true, + "CanSellOnRagfair": true, + "ChangePriceCoef": 1, + "ConflictingItems": [], + "CreditsPrice": 24943, + "Description": "Condensed milk", + "DiscardingBlock": false, + "ExamineExperience": 20, + "ExamineTime": 1, + "ExaminedByDefault": false, + "ExtraSizeDown": 0, + "ExtraSizeForceAdd": false, + "ExtraSizeLeft": 0, + "ExtraSizeRight": 0, + "ExtraSizeUp": 0, + "FixedPrice": false, + "Height": 1, + "HideEntrails": false, + "IsAlwaysAvailableForInsurance": false, + "IsLockedafterEquip": false, + "IsUnbuyable": false, + "IsUndiscardable": false, + "IsUngivable": false, + "IsUnsaleable": false, + "ItemSound": "food_tin_can", + "LootExperience": 50, + "MaxResource": 1, + "MergesWithChildren": false, + "Name": "Condensed milk", + "NotShownInSlot": false, + "Prefab": { + "path": "assets/content/weapons/usable_items/item_food_condensed_milk/item_food_condensed_milk_loot.bundle", + "rcid": "" + }, + "QuestItem": false, + "RagFairCommissionModifier": 1, + "Rarity": "Rare", + "RepairCost": 0, + "RepairSpeed": 0, + "SendToClient": false, + "ShortName": "Condensed milk", + "SpawnChance": 9, + "StackMaxSize": 1, + "StackObjectsCount": 1, + "StimulatorBuffs": "Buffs_food_condensed_milk", + "Unlootable": false, + "UnlootableFromSide": [], + "UnlootableFromSlot": "FirstPrimaryWeapon", + "UsePrefab": { + "path": "assets/content/weapons/usable_items/item_food_condensed_milk/item_food_condensed_milk_container.bundle", + "rcid": "" + }, + "Weight": 0.4, + "Width": 1, + "effects_damage": [], + "effects_health": { + "Energy": { + "value": 75 + }, + "Hydration": { + "value": -65 + } + }, + "foodEffectType": "afterUse", + "foodUseTime": 4 + }, + "_proto": "5734770f24597738025ee254", + "_type": "Item" + }, + "locale": { + "Description": "Condensed milk, also called \"Sguschyonka\" in Russia, once was a part of field ration for the Union soldiers in Civil War, but later reached unprecedented popularity in post-Soviet countries, becoming almost a staple product. Canned, it can be stored for decades and remain just as sweet, tasty and nutritious.", + "Name": "Condensed milk", + "ShortName": "Cond. milk" + } +} \ No newline at end of file diff --git a/items/frontend/cypress/fixtures/example.json b/items/frontend/cypress/fixtures/example.json deleted file mode 100644 index 02e4254..0000000 --- a/items/frontend/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} diff --git a/items/frontend/src/cypress/integration/search.spec.tsx b/items/frontend/src/cypress/integration/search.spec.tsx index 9c7c60b..cc9dc5b 100644 --- a/items/frontend/src/cypress/integration/search.spec.tsx +++ b/items/frontend/src/cypress/integration/search.spec.tsx @@ -1,11 +1,32 @@ +import condensedMilk from "../../../cypress/fixtures/condensed_milk.json"; + export {}; describe('Search area', ()=>{ beforeEach(() => { - cy.intercept('GET','**/api/locales', { + cy.intercept({ + method: 'GET', + url: '**/api/locales' + }, { statusCode: 200, body: ['locale1', 'locale2'] - }); + }).as('getLocalesWithoutData'); + + cy.intercept({ + method: 'GET', + url: '**/api/item?*' + }, { + statusCode: 200, + body: condensedMilk + }) + + cy.intercept({ + method: 'GET', + url: '**/api/item/hierarchy*' + }, { + statusCode: 200, + body: condensedMilk + }) cy.visit('/'); }) @@ -31,4 +52,19 @@ describe('Search area', ()=>{ .should('be.visible') .contains('p', 'No data to display'); }) + + describe('Searching', () => { + it('Search using ID displays the json with locale', () => { + cy.get('#search-autocomplete').type(condensedMilk.item._id); + setTimeout(() => { + cy.get('#search-autocomplete').should('have.value', condensedMilk.locale.Name) + }, 5000) + cy.get(`.react-json-view .object-key-val > .pushed-content > .object-content > .variable-row > .variable-value > div > .string-value:contains("${condensedMilk.item._id}")`) + .should('have.length', 1) + .invoke('text') + .should('eq', `"${condensedMilk.item._id}"`); + cy.get(`.react-json-view .object-key-val > .pushed-content > .object-content > .variable-row > .variable-value > div > .string-value:contains("${condensedMilk.locale.Name}")`) + .should('have.length.above', 0); + }) + }) }) \ No newline at end of file diff --git a/items/frontend/src/cypress/integration/url-check.spec.tsx b/items/frontend/src/cypress/integration/url-check.spec.tsx new file mode 100644 index 0000000..c3695f2 --- /dev/null +++ b/items/frontend/src/cypress/integration/url-check.spec.tsx @@ -0,0 +1,73 @@ +export {}; + +import condensedMilk from '../../../cypress/fixtures/condensed_milk.json' + +describe('Dark Mode Toggle', () => { + beforeEach(() => { + cy.window() + .its("sessionStorage") + .invoke("removeItem", "items.sp-tarkov.com-locales"); + + cy.intercept({ + method: 'GET', + url: '**/api/locales' + }, { + statusCode: 200, + body: [] + }).as('getLocalesWithoutData'); + + cy.intercept({ + method: 'GET', + url: '**/api/item?*' + }, { + statusCode: 200, + body: condensedMilk + }) + + cy.intercept({ + method: 'GET', + url: '**/api/item/hierarchy*' + }, { + statusCode: 200, + body: condensedMilk + }) + }) + + afterEach(() => { + cy.clearLocalStorage(); + }) + + describe('Check page not found', () => { + it('Invalid url should redirect to page not found', () => { + cy.visit('/ABC') + cy.get('#not-found-message').contains("This page does not exist !"); + }) + }) + + describe('Check root redirection', () => { + it('Root should redirect to search', () => { + cy.visit('/') + cy.url().should("include", "/search"); + }) + }) + + describe('Check url changes with search input', () => { + it('ID in url applies search', () => { + cy.visit(`/search/${condensedMilk.item._id}`); + cy.get('#search-autocomplete').should('have.value', condensedMilk.locale.Name) + }) + + it('Search reflects in url', () => { + cy.visit(`/`); + cy.get('#search-autocomplete').type(condensedMilk.item._id); + setTimeout(() => { + cy.get('#search-autocomplete').should('have.value', condensedMilk.locale.Name) + }, 5000) + cy.url().should("include", `/search/${condensedMilk.item._id}`); + cy.get(`.react-json-view .object-key-val > .pushed-content > .object-content > .variable-row > .variable-value > div > .string-value:contains("${condensedMilk.item._id}")`) + .should('have.length', 1) + .invoke('text') + .should('eq', `"${condensedMilk.item._id}"`); + }) + }) +}) \ No newline at end of file