Skip to content

Commit

Permalink
Check local storage (not working yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
McFlink committed Mar 11, 2024
1 parent 2ad30ed commit e82e207
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions weather-forecast/tests/weatherTests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,36 @@ test('Empty input alert', async ({ page }) => {

expect(alertMessage.message()).toContain('Error: 400, Nothing to geocode \nPlease try again!');
});

test('Check local storage', async ({ page }) => {
let cityInput = page.locator('#city-input');
cityInput.fill('Göteborg');
cityInput.press('Enter');

await page.waitForSelector('.history-box');

let storedCities = await page.evaluate(() => {
return JSON.parse(localStorage.getItem('searchHistory'));
});

// await expect(storedCities[0].city).toBe('Gothenburg');

await cityInput.fill('Mellerud');
await cityInput.press('Enter');

await page.waitForSelector('.history-box');

storedCities = await page.evaluate(() => {
return JSON.parse(localStorage.getItem('searchHistory'));
});

let expectedCitites = ['Gothenburg', 'Mellerud'];

for (let i = 0; i < storedCities.length; i++) {
await expect(storedCities[0].city).toContain(expectedCitites[i]);
}

console.log("Testar", storedCities);

// await expect(storedCities[1].city).toBe('Gothenburg');
});

0 comments on commit e82e207

Please sign in to comment.