Skip to content

Commit c836d0e

Browse files
committed
test: remove testid and find by text instead
1 parent 1e1b34d commit c836d0e

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

src/sections/create-collection/CreateCollection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function CreateCollection({
6464

6565
if (collectionUserPermissions && !canUserAddCollection) {
6666
return (
67-
<div className="pt-4" data-testid="not-allowed-to-create-collection-alert">
67+
<div className="pt-4">
6868
<Alert variant="danger" dismissible={false}>
6969
{t('notAllowedToCreateCollection')}
7070
</Alert>

src/sections/edit-collection/EditCollection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const EditCollection = ({
6464

6565
if (collectionUserPermissions && !canUserEditCollection) {
6666
return (
67-
<div className="pt-4" data-testid="not-allowed-to-edit-collection-alert">
67+
<div className="pt-4">
6868
<Alert variant="danger" dismissible={false}>
6969
{t('notAllowedToEditCollection')}
7070
</Alert>

tests/component/sections/create-collection/CreateCollection.spec.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ describe('CreateCollection', () => {
103103
})
104104

105105
it('should show alert error message when user is not allowed to create collection', () => {
106-
collectionRepository.getUserPermissions = cy.stub().resolves(
107-
CollectionMother.createUserPermissions({
108-
canAddCollection: false
109-
})
110-
)
106+
const DELAYED_TIME = 200
107+
collectionRepository.getUserPermissions = cy.stub().callsFake(() => {
108+
return Cypress.Promise.delay(DELAYED_TIME).then(() =>
109+
CollectionMother.createUserPermissions({
110+
canAddCollection: false
111+
})
112+
)
113+
})
111114

112115
cy.mountAuthenticated(
113116
<CreateCollection
@@ -116,18 +119,33 @@ describe('CreateCollection', () => {
116119
metadataBlockInfoRepository={metadataBlockInfoRepository}
117120
/>
118121
)
119-
cy.findAllByTestId('not-allowed-to-create-collection-alert').should('exist')
122+
123+
cy.wait(DELAYED_TIME * 2)
124+
125+
cy.findByText(
126+
/You do not have permissions to create a collection within this collection./
127+
).should('exist')
120128
})
121129

122130
it('should not show alert error message when user is allowed to create collection', () => {
131+
const DELAYED_TIME = 200
132+
collectionRepository.getUserPermissions = cy.stub().callsFake(() => {
133+
return Cypress.Promise.delay(DELAYED_TIME).then(() => userPermissionsMock)
134+
})
135+
123136
cy.mountAuthenticated(
124137
<CreateCollection
125138
collectionRepository={collectionRepository}
126139
parentCollectionId="root"
127140
metadataBlockInfoRepository={metadataBlockInfoRepository}
128141
/>
129142
)
130-
cy.findAllByTestId('not-allowed-to-create-collection-alert').should('not.exist')
143+
144+
cy.wait(DELAYED_TIME * 2)
145+
146+
cy.findByText(
147+
/You do not have permissions to create a collection within this collection./
148+
).should('not.exist')
131149
})
132150

133151
it('should show alert error message when getting the user permissions fails', () => {

tests/component/sections/edit-collection/EditCollection.spec.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const allMetadataBlocksMock = [
3333
const testUser = UserMother.create()
3434
const userRepository: UserRepository = {} as UserRepository
3535

36-
describe('CreateCollection', () => {
36+
describe('EditCollection', () => {
3737
beforeEach(() => {
3838
collectionRepository.create = cy.stub().resolves(1)
3939
collectionRepository.getById = cy.stub().resolves(collection)
@@ -103,11 +103,14 @@ describe('CreateCollection', () => {
103103
})
104104

105105
it('should show alert error message when user is not allowed to edit the collection', () => {
106-
collectionRepository.getUserPermissions = cy.stub().resolves(
107-
CollectionMother.createUserPermissions({
108-
canEditCollection: false
109-
})
110-
)
106+
const DELAYED_TIME = 200
107+
collectionRepository.getUserPermissions = cy.stub().callsFake(() => {
108+
return Cypress.Promise.delay(DELAYED_TIME).then(() =>
109+
CollectionMother.createUserPermissions({
110+
canEditCollection: false
111+
})
112+
)
113+
})
111114

112115
cy.mountAuthenticated(
113116
<EditCollection
@@ -116,18 +119,33 @@ describe('CreateCollection', () => {
116119
metadataBlockInfoRepository={metadataBlockInfoRepository}
117120
/>
118121
)
119-
cy.findAllByTestId('not-allowed-to-edit-collection-alert').should('exist')
122+
123+
cy.wait(DELAYED_TIME * 2)
124+
125+
cy.findByText(/You do not have permissions to edit this collection./, { timeout: 0 }).should(
126+
'exist'
127+
)
120128
})
121129

122130
it('should not show alert error message when user is allowed to edit the collection', () => {
131+
const DELAYED_TIME = 200
132+
collectionRepository.getUserPermissions = cy.stub().callsFake(() => {
133+
return Cypress.Promise.delay(DELAYED_TIME).then(() => userPermissionsMock)
134+
})
135+
123136
cy.mountAuthenticated(
124137
<EditCollection
125138
collectionId="root"
126139
collectionRepository={collectionRepository}
127140
metadataBlockInfoRepository={metadataBlockInfoRepository}
128141
/>
129142
)
130-
cy.findAllByTestId('not-allowed-to-edit-collection-alert').should('not.exist')
143+
144+
cy.wait(DELAYED_TIME * 2)
145+
146+
cy.findByText(/You do not have permissions to edit this collection./, { timeout: 0 }).should(
147+
'not.exist'
148+
)
131149
})
132150

133151
it('should show alert error message when getting the user permissions fails', () => {

0 commit comments

Comments
 (0)