Skip to content

Commit b201e0d

Browse files
committed
Add editor role to can-manage user
1 parent 3b7724f commit b201e0d

File tree

2 files changed

+106
-80
lines changed

2 files changed

+106
-80
lines changed

cypress/e2e/features.cy.js

Lines changed: 106 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const USER_CREDENTIALS = {
99
password: 'Password1234',
1010
}
1111

12+
const FIXTURES = {
13+
RESTAURANTS_COUNT: 2,
14+
}
15+
1216
describe('Meilisearch features', () => {
1317
const loginUser = ({ email, password }) => {
1418
cy.visit(`${adminUrl}`)
@@ -25,13 +29,6 @@ describe('Meilisearch features', () => {
2529
cy.contains('Settings').should('be.visible')
2630
}
2731

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-
3532
const checkCollectionContent = ({ rowNb, contains }) => {
3633
const row = `table[role='grid'] tbody tr:nth-child(${rowNb})`
3734
contains.map(value =>
@@ -63,88 +60,117 @@ describe('Meilisearch features', () => {
6360
)
6461
})
6562

66-
it('can update credentials', () => {
67-
visitPluginPage()
68-
cy.get('button:contains("Settings")').click()
69-
70-
cy.get('input[name="host"]').clear()
71-
cy.get('input[name="host"]').type(host)
72-
cy.get('input[name="apiKey"]').clear()
73-
cy.get('input[name="apiKey"]').type(apiKey)
74-
cy.contains('button', 'Save').click({ force: true })
75-
76-
cy.get('div[role="status').contains('success').should('be.visible')
77-
cy.get('div[role="status')
78-
.contains('Credentials successfully updated')
79-
.should('be.visible')
80-
cy.removeNotifications()
81-
})
63+
describe('Settings panel', () => {
64+
it('allows to update credentials', () => {
65+
visitPluginPage()
66+
cy.get('button:contains("Settings")').click()
67+
68+
cy.get('input[name="host"]').clear()
69+
cy.get('input[name="host"]').type(host)
70+
cy.get('input[name="apiKey"]').clear()
71+
cy.get('input[name="apiKey"]').type(apiKey)
72+
cy.contains('button', 'Save').click({ force: true })
73+
74+
cy.get('div[role="status').contains('success').should('be.visible')
75+
cy.get('div[role="status')
76+
.contains('Credentials successfully updated')
77+
.should('be.visible')
78+
cy.removeNotifications()
79+
})
8280

83-
it('displays credentials', () => {
84-
visitPluginPage()
85-
cy.get('button:contains("Settings")').click()
81+
it('displays credentials', () => {
82+
visitPluginPage()
83+
cy.get('button:contains("Settings")').click()
8684

87-
cy.get('input[name="host"]').should('have.value', host)
88-
cy.get('input[name="apiKey"]').should('have.value', apiKey)
85+
cy.get('input[name="host"]').should('have.value', host)
86+
cy.get('input[name="apiKey"]').should('have.value', apiKey)
87+
})
8988
})
9089

91-
it('displays all collections', () => {
92-
visitPluginPage()
90+
describe('Collections panel', () => {
91+
it('displays all collections', () => {
92+
visitPluginPage()
9393

94-
cy.contains('user')
95-
cy.contains('about-us')
96-
cy.contains('category')
97-
cy.contains('homepage')
98-
cy.contains('restaurant')
99-
})
94+
cy.contains('user')
95+
cy.contains('about-us')
96+
cy.contains('category')
97+
cy.contains('homepage')
98+
cy.contains('restaurant')
99+
})
100100

101-
it('can add collections to index', () => {
102-
visitPluginPage()
103-
104-
// Intercepts used to wait for the UI to refresh after toggles
105-
cy.intercept('POST', '**/meilisearch/content-type').as('addCollection')
106-
cy.intercept('GET', '**/meilisearch/content-type/**').as('fetchCollections')
107-
108-
cy.get("table[role='grid'] tbody tr")
109-
.should('have.length.at.least', 1)
110-
.each((_row, idx) => {
111-
const rowIndex = idx + 1
112-
const rowSelector = `table[role='grid'] tbody tr:nth-child(${rowIndex})`
113-
const checkboxSelector = `${rowSelector} button[role="checkbox"]`
114-
115-
// Click only if not already checked to avoid deleting the collection
116-
cy.get(checkboxSelector).then(checkbox => {
117-
const isChecked =
118-
checkbox.attr('aria-checked') === 'true' ||
119-
checkbox.attr('data-state') === 'checked'
120-
121-
if (!isChecked) {
122-
cy.wrap(checkbox).click({ force: true })
123-
cy.wait('@addCollection')
124-
cy.wait('@fetchCollections') // wait for the refetch after the POST
125-
}
101+
it('can add collections to index', () => {
102+
visitPluginPage()
103+
104+
// Intercepts used to wait for the UI to refresh after toggles
105+
cy.intercept('POST', '**/meilisearch/content-type').as('addCollection')
106+
cy.intercept('GET', '**/meilisearch/content-type/**').as(
107+
'fetchCollections',
108+
)
109+
110+
cy.get("table[role='grid'] tbody tr")
111+
.should('have.length.at.least', 1)
112+
.each((_row, idx) => {
113+
const rowIndex = idx + 1
114+
const rowSelector = `table[role='grid'] tbody tr:nth-child(${rowIndex})`
115+
const checkboxSelector = `${rowSelector} button[role="checkbox"]`
116+
117+
// Click only if not already checked to avoid deleting the collection
118+
cy.get(checkboxSelector).then(checkbox => {
119+
const isChecked =
120+
checkbox.attr('aria-checked') === 'true' ||
121+
checkbox.attr('data-state') === 'checked'
122+
123+
if (!isChecked) {
124+
cy.wrap(checkbox).click({ force: true })
125+
cy.wait('@addCollection')
126+
cy.wait('@fetchCollections') // wait for the refetch after the POST
127+
}
128+
})
129+
130+
// Re-select the row after the network sync to avoid stale element references
131+
cy.get(rowSelector)
132+
.should('contain.text', 'Yes')
133+
.and('contain.text', 'Hooked')
126134
})
135+
})
127136

128-
// Re-select the row after the network sync to avoid stale element references
129-
cy.get(rowSelector)
130-
.should('contain.text', 'Yes')
131-
.and('contain.text', 'Hooked')
132-
})
137+
// This test assumes that the collections are indexed (in previous test)
138+
it('displays the number of inxed documents for each collection', () => {
139+
visitPluginPage()
140+
141+
// 1 user in database -> 1 document in `user` index
142+
checkCollectionContent({ rowNb: 1, contains: ['1 / 1'] })
143+
// `about-us` is in the `content` index (2 documents)
144+
checkCollectionContent({ rowNb: 2, contains: ['2 / 2'] })
145+
// 2 categories in db -> 2 documents in `category` index
146+
checkCollectionContent({ rowNb: 3, contains: ['2 / 2'] })
147+
// `homepage` is in the `content` index (2 documents)
148+
checkCollectionContent({ rowNb: 4, contains: ['2 / 2'] })
149+
// 2 restaurants in db -> 2 documents in `restaurant` index
150+
checkCollectionContent({ rowNb: 5, contains: ['2 / 2'] })
151+
})
133152
})
134153

135-
// This test assumes that the collections are indexed (in previous test)
136-
it('displays the number of inxed documents for each collection', () => {
137-
visitPluginPage()
138-
139-
// 1 user in database -> 1 document in `user` index
140-
checkCollectionContent({ rowNb: 1, contains: ['1 / 1'] })
141-
// `about-us` is in the `content` index (2 documents)
142-
checkCollectionContent({ rowNb: 2, contains: ['2 / 2'] })
143-
// 2 categories in db -> 2 documents in `category` index
144-
checkCollectionContent({ rowNb: 3, contains: ['2 / 2'] })
145-
// `homepage` is in the `content` index (2 documents)
146-
checkCollectionContent({ rowNb: 4, contains: ['2 / 2'] })
147-
// 2 restaurants in db -> 2 documents in `restaurant` index
148-
checkCollectionContent({ rowNb: 5, contains: ['2 / 2'] })
154+
describe.only('Content hooks', () => {
155+
it('indexes new content in the collections', () => {
156+
cy.visit(
157+
`${adminUrl}/admin/content-manager/collection-types/api::restaurant.restaurant`,
158+
)
159+
160+
cy.contains('a', 'Create new entry').click()
161+
cy.url().should('include', '/create')
162+
163+
cy.get('input[name="title').type('The slimy snail')
164+
cy.get('form').contains('button', 'Save').click()
165+
166+
cy.removeNotifications()
167+
visitPluginPage()
168+
169+
const expectedNb = FIXTURES.RESTAURANTS_COUNT + 1
170+
cy.checkCollectionContent({
171+
rowNb: 5,
172+
contains: [`${expectedNb} / ${expectedNb}`],
173+
})
174+
})
149175
})
150176
})

playground/pre-seeded-database.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)