Skip to content

Commit 063765a

Browse files
committed
resources: Update cypress tets
1 parent 43fb553 commit 063765a

File tree

5 files changed

+54
-51
lines changed

5 files changed

+54
-51
lines changed

cypress/e2e/searchPage.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ describe('Search page', () => {
55
cy.interceptAll()
66
cy.visit('/resources')
77
cy.waitAuto()
8-
cy.waitAuto()
98
window.localStorage.setItem('CookieConsent', "{\"userPreference\":\"all\"}")
109
})
1110

@@ -112,6 +111,7 @@ describe('Search page', () => {
112111
})
113112

114113
it('checks if changing page size works', () => {
114+
// cy.waitAuto()
115115
cy.get('.results-sortBy-row').find('select').first().select('25')
116116
cy.waitAuto()
117117
// cy.wait(['@kiwi', '@resources', '@mongo'])

cypress/fixtures/filters.json

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
[
2-
{
3-
"_id": null,
4-
"category": [
5-
"workload",
6-
"simpoint",
7-
"disk_image",
8-
"binary",
9-
"checkpoint",
10-
"bootloader",
11-
"resource",
12-
"kernel"
13-
],
14-
"architecture": [
15-
"X86",
16-
"ARM",
17-
"MIPS",
18-
"RISCV",
19-
"POWER",
20-
"SPARC"
21-
],
22-
"gem5_versions": [
23-
"23.0"
24-
]
25-
}
1+
{
2+
"_id": null,
3+
"category": [
4+
"workload",
5+
"simpoint",
6+
"disk_image",
7+
"binary",
8+
"checkpoint",
9+
"bootloader",
10+
"resource",
11+
"kernel"
12+
],
13+
"architecture": [
14+
"X86",
15+
"ARM",
16+
"MIPS",
17+
"RISCV",
18+
"POWER",
19+
"SPARC"
20+
],
21+
"gem5_versions": [
22+
"23.0"
2623
]
24+
}

cypress/support/commands.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ Cypress.Commands.add('assertValueCopiedToClipboard', value => {
3333
})
3434

3535
Cypress.Commands.add('interceptAll', () => {
36+
// console.log('Intercepted:', req.method, req.url)
3637
cy.intercept('GET', /https.*json$/).as('jsonLink')
3738
cy.intercept('GET', /^\/\w*\.json$/).as('jsonLocal')
3839
cy.intercept('GET', '**/api/resources/find-resources-in-batch*', (req) => {
3940
const url = new URL(req.url);
4041
const ids = url.searchParams.getAll('id');
4142
const versions = url.searchParams.getAll('resource_version');
42-
43+
console.log("in find", url)
44+
console.log(ids)
45+
console.log(versions)
4346
// Check for specific resource requests
4447
if (ids.includes('arm64-ubuntu-20.04-boot')) {
4548
const versionIndex = ids.indexOf('arm64-ubuntu-20.04-boot');
@@ -54,33 +57,22 @@ Cypress.Commands.add('interceptAll', () => {
5457
fixture: 'getResource.json'
5558
})
5659
} else {
57-
req.reply({
58-
documents: [],
59-
})
60+
req.reply([])
6061
}
6162
} else {
62-
req.reply({
63-
documents: [],
64-
})
63+
req.reply([])
6564
}
6665
}).as('find')
67-
cy.intercept('GET', '**/api/resources/search*', (req) => {
66+
cy.intercept('GET', '**/api/resources/search*', (req) => {
6867
const url = new URL(req.url);
6968
const containsStr = url.searchParams.get('contains-str');
7069
const mustInclude = url.searchParams.get('must-include');
7170
const pageSize = parseInt(url.searchParams.get('page-size')) || 10;
7271
const page = parseInt(url.searchParams.get('page')) || 1;
73-
72+
console.log("in cypress")
7473
console.log('Search params:', { containsStr, mustInclude, pageSize, page });
7574

76-
// Handle different search scenarios based on your old pipeline logic
77-
if (!containsStr && !mustInclude) {
78-
// Empty search - equivalent to pipeline length 5
79-
req.reply({
80-
documents: [],
81-
totalCount: 0
82-
})
83-
} else if (mustInclude) {
75+
if (mustInclude) {
8476
// Parse must-include filters
8577
const filters = mustInclude.split(';').reduce((acc, filter) => {
8678
const [field, ...values] = filter.split(',');
@@ -89,36 +81,46 @@ Cypress.Commands.add('interceptAll', () => {
8981
}, {});
9082

9183
if (filters.category) {
84+
console.log("category")
9285
req.reply({
9386
fixture: 'searchDiskimage.json'
9487
})
9588
} else if (filters.architecture) {
89+
console.log("architecture")
9690
req.reply({
9791
fixture: 'searchArchitecture.json'
9892
})
93+
} else if (filters.tags) {
94+
req.reply({
95+
fixture: 'searchTags.json'
96+
})
9997
} else {
98+
console.log("exact")
10099
req.reply({
101100
fixture: 'searchExact.json'
102101
})
103102
}
104-
} else if (containsStr) {
103+
} else if (pageSize) {
105104
// Basic search with different page sizes
106105
if (pageSize === 25) {
106+
console.log("page 25")
107107
req.reply({
108108
fixture: 'search25.json'
109109
})
110110
} else {
111+
console.log("default page exact")
111112
req.reply({
112113
fixture: 'searchExact.json'
113114
})
114115
}
115116
} else {
117+
console.log("else")
116118
req.reply({
117119
documents: [],
118120
totalCount: 0
119121
})
120122
}
121-
}).as('search')
123+
}).as('mongo')
122124

123125
// Intercept filters request (replaces old MongoDB aggregate for filters)
124126
cy.intercept('GET', '**/api/resources/filters*', {
@@ -129,19 +131,19 @@ Cypress.Commands.add('interceptAll', () => {
129131
Cypress.Commands.add('waitFirst', () => {
130132
const resource = Object.keys(Cypress.env('SOURCES'))[0]
131133
if (Cypress.env('SOURCES')[resource].isMongo) {
132-
cy.wait(['@search'])
134+
// cy.wait(['@mongo'])
133135
} else {
134136
cy.waitJSON(Cypress.env('SOURCES')[resource].url.includes('http'))
135137
}
136138
return cy.wrap(Cypress.env('SOURCES')[resource].isMongo)
137139
})
138140

139141
Cypress.Commands.add('waitAll', value => {
140-
cy.wait(['@kiwi', '@resources', '@search', '@filters'])
142+
cy.wait(['@kiwi', '@resources', '@filters'])
141143
})
142144

143145
Cypress.Commands.add('waitMongo', () => {
144-
cy.wait(['@search', '@filters'])
146+
cy.wait(['@filters'])
145147
})
146148

147149
Cypress.Commands.add('waitJSON', (isUrl) => {
@@ -154,9 +156,10 @@ Cypress.Commands.add('waitJSON', (isUrl) => {
154156

155157
Cypress.Commands.add('waitAuto', () => {
156158
const resources = Cypress.env('SOURCES')
159+
console.log("resouces", resources)
157160
Object.keys(resources).forEach((i) => {
158161
if (resources[i].isMongo) {
159-
cy.wait(['@search'])
162+
cy.wait(['@mongo'])
160163
} else {
161164
cy.waitJSON(resources[i].url.includes('http'))
162165
}

pages/api/mongodb/getResourceByID.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ async function getResourceByID(url, id, version = null) {
1515

1616
let params = new URLSearchParams();
1717
params.append("id", id)
18-
if (version == null) {
18+
if (version != null) {
1919
params.append("resource_version", version)
20+
} else {
21+
params.append("resource_version", "None")
2022
}
2123

2224
const res = await fetch(`${url}/find-resources-in-batch?${params.toString()}`, {

pages/api/mongodb/getVersionsByID.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import compareVersions from "../compareVersions";
1010
* @throws {Error} - Throws an error if the fetch request fails.
1111
*/
1212
async function getVersionsByID(url, id) {
13-
const res = await fetch(`${url}/find-resources-in-batch?id=${id}`, {
13+
const res = await fetch(`${url}/find-resources-in-batch?id=${id}&resource_version=None`, {
1414
method: 'GET',
1515
headers: {
1616
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)