Skip to content

Commit 3a9ab5b

Browse files
committed
Add collection indexing tests
1 parent 03f5aa2 commit 3a9ab5b

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed

cypress/e2e/features.cy.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
const {
2+
env,
3+
apiKey,
4+
[env]: { adminUrl, host },
5+
} = Cypress.env()
6+
7+
const USER_CREDENTIALS = {
8+
9+
password: 'Password1234',
10+
}
11+
12+
describe('Meilisearch features', () => {
13+
const loginUser = ({ email, password }) => {
14+
cy.visit(`${adminUrl}`)
15+
cy.get('form').should('be.visible')
16+
cy.get('input[name="email"]').type(email)
17+
cy.get('input[name="password"]').type(password)
18+
cy.get('button[role="checkbox"]').click()
19+
cy.get('button[type="submit"]').click()
20+
}
21+
22+
const visitPluginPage = () => {
23+
cy.visit(`${adminUrl}/plugins/meilisearch`)
24+
cy.contains('Collections').should('be.visible')
25+
cy.contains('Settings').should('be.visible')
26+
}
27+
28+
const clickCollection = ({ rowNb }) => {
29+
const row = `table[role='grid'] tbody tr:nth-child(${rowNb})`
30+
cy.get(`${row} button[role="checkbox"]`, { timeout: 10000 }).click({
31+
timeout: 10000,
32+
})
33+
}
34+
35+
const checkCollectionContent = ({ rowNb, contains }) => {
36+
const row = `table[role='grid'] tbody tr:nth-child(${rowNb})`
37+
contains.map(value =>
38+
cy
39+
.get(row, {
40+
timeout: 10000,
41+
})
42+
.contains(value, { timeout: 10000 }),
43+
)
44+
}
45+
46+
const clickAndCheckRowContent = ({ rowNb, contains }) => {
47+
clickCollection({ rowNb })
48+
checkCollectionContent({ rowNb, contains })
49+
}
50+
51+
beforeEach(() => {
52+
cy.session(
53+
USER_CREDENTIALS.email,
54+
() => {
55+
loginUser({
56+
email: USER_CREDENTIALS.email,
57+
password: USER_CREDENTIALS.password,
58+
})
59+
},
60+
{
61+
validate() {
62+
cy.wait(1000)
63+
cy.contains('Hello User who can manage Meilisearch').should(
64+
'be.visible',
65+
)
66+
},
67+
},
68+
)
69+
})
70+
71+
it('can update credentials', () => {
72+
visitPluginPage()
73+
cy.get('button:contains("Settings")').click()
74+
75+
cy.get('input[name="host"]').clear()
76+
cy.get('input[name="host"]').type(host)
77+
cy.get('input[name="apiKey"]').clear()
78+
cy.get('input[name="apiKey"]').type(apiKey)
79+
cy.contains('button', 'Save').click({ force: true })
80+
81+
cy.get('div[role="status').contains('success').should('be.visible')
82+
cy.get('div[role="status')
83+
.contains('Credentials successfully updated')
84+
.should('be.visible')
85+
cy.removeNotifications()
86+
})
87+
88+
it('displays credentials', () => {
89+
visitPluginPage()
90+
cy.get('button:contains("Settings")').click()
91+
92+
cy.get('input[name="host"]').should('have.value', host)
93+
cy.get('input[name="apiKey"]').should('have.value', apiKey)
94+
})
95+
96+
it('displays all collections', () => {
97+
visitPluginPage()
98+
99+
cy.contains('user')
100+
cy.contains('about-us')
101+
cy.contains('category')
102+
cy.contains('homepage')
103+
cy.contains('restaurant')
104+
})
105+
106+
it.only('can add collections to index', () => {
107+
visitPluginPage()
108+
109+
// Intercepts used to wait for the UI to refresh after toggles
110+
cy.intercept('POST', '**/meilisearch/content-type').as('addCollection')
111+
cy.intercept('GET', '**/meilisearch/content-type/**').as('fetchCollections')
112+
113+
cy.get("table[role='grid'] tbody tr")
114+
.should('have.length.at.least', 1)
115+
.each((_row, idx) => {
116+
const rowIndex = idx + 1
117+
const rowSelector = `table[role='grid'] tbody tr:nth-child(${rowIndex})`
118+
const checkboxSelector = `${rowSelector} button[role="checkbox"]`
119+
120+
// Click only if not already checked to avoid deleting the collection
121+
cy.get(checkboxSelector).then(checkbox => {
122+
const isChecked =
123+
checkbox.attr('aria-checked') === 'true' ||
124+
checkbox.attr('data-state') === 'checked'
125+
126+
if (!isChecked) {
127+
cy.wrap(checkbox).click({ force: true })
128+
cy.wait('@addCollection')
129+
cy.wait('@fetchCollections') // wait for the refetch after the POST
130+
}
131+
})
132+
133+
// Re-select the row after the network sync to avoid stale element references
134+
cy.get(rowSelector)
135+
.should('contain.text', 'Yes')
136+
.and('contain.text', 'Hooked')
137+
})
138+
})
139+
})

playground/pre-seeded-database.db

0 Bytes
Binary file not shown.

playground/src/api/restaurant/content-types/restaurant/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"info": {
55
"singularName": "restaurant",
66
"pluralName": "restaurants",
7-
"displayName": "restaurant",
7+
"displayName": "Restaurant",
88
"description": ""
99
},
1010
"options": {

playground/types/generated/contentTypes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ export interface ApiRestaurantRestaurant extends Struct.CollectionTypeSchema {
465465
collectionName: 'restaurants'
466466
info: {
467467
description: ''
468-
displayName: 'restaurant'
468+
displayName: 'Restaurant'
469469
pluralName: 'restaurants'
470470
singularName: 'restaurant'
471471
}

0 commit comments

Comments
 (0)