Skip to content

Commit

Permalink
Adjust timeout of GroupForm's unit test (#6618)
Browse files Browse the repository at this point in the history
* adjust timeout of GroupForm's unit test
  • Loading branch information
goplayoutside3 authored Jan 13, 2025
1 parent b952ddd commit d83397b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/lib-user/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"panoptes-client": "~5.6.0",
"react-i18next": "~14.1.3",
"swr": "~2.2.4",
"uuid": "~11.0.3"
"uuid": "~11.0.4"
},
"peerDependencies": {
"@zooniverse/grommet-theme": "3.x.x",
Expand Down
55 changes: 29 additions & 26 deletions packages/lib-user/src/components/shared/GroupForm/GroupForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,109 +9,112 @@ describe('components > shared > GroupForm', function() {

const user = userEvent.setup()
const CreateStory = composeStory(Create, Meta)

it('should collect group display name', function() {
render(<CreateStory />)

const displayName = screen.getByRole('textbox', { name: 'Group Name' })
expect(displayName).to.be.ok()
})

it('should have radio buttons for public or private visibility', function() {
render(<CreateStory />)

const privateRadio = screen.getByRole('radio', { name: 'Private - only members can view this group' })
const publicRadio = screen.getByRole('radio', { name: 'Public - you can share this group with anyone' })
expect(privateRadio).to.be.ok()
expect(publicRadio).to.be.ok()
})

it('should default to private visibility', function() {
render(<CreateStory />)

const privateRadio = screen.getByRole('radio', { name: 'Private - only members can view this group' })
expect(privateRadio.checked).to.be.true()
})

it('should have a select for stats visibility', function() {
render(<CreateStory />)

// the Grommet Select component renders as a button with a textbox. The statsVisibility input uses the Grommet Select, therefore we need to find the textbox role. The textbox name includes the value of the select, which by default is 'private_agg_only'.
const statsVisibility = screen.getByRole('textbox', { name: 'Stats Visibility, private_agg_only' })
expect(statsVisibility).to.be.ok()
})

describe('with private visibility', function() {
it('should show private stats visibility options', async function() {
render(<CreateStory />)

// by default, the visibility is private
const privateRadio = screen.getByRole('radio', { name: 'Private - only members can view this group' })
expect(privateRadio.checked).to.be.true()

const statsVisibility = screen.getByRole('textbox', { name: 'Stats Visibility, private_agg_only' })
await user.click(statsVisibility)

const options = screen.getAllByRole('option')

// the private visibility options are 'private_agg_only' and 'private_show_agg_and_ind'
expect(options.length).to.equal(2)
})
})

describe('with public visibility', function() {
it('should show public stats visibility options', async function() {
render(<CreateStory />)

const publicRadio = screen.getByRole('radio', { name: 'Public - you can share this group with anyone' })
await user.click(publicRadio)
expect(publicRadio.checked).to.be.true()

const statsVisibility = screen.getByRole('textbox', { name: 'Stats Visibility, public_agg_only' })
await user.click(statsVisibility)

const options = screen.getAllByRole('option')

// the public visibility options are 'public_agg_only', 'public_show_agg_and_ind', and 'public_show_all'
expect(options.length).to.equal(3)
})
})

describe('without a display name', function() {
it('should show display name is required', async function() {
render(<CreateStory />)

const submit = screen.getByRole('button', { name: 'Create new group' })
await user.click(submit)

const error = screen.getByText('required')
expect(error).to.be.ok()
})
})

describe('with an invalid display name, below minimum characters', function() {
it('should show display name is invalid', async function() {
render(<CreateStory />)

const displayName = screen.getByRole('textbox', { name: 'Group Name' })
await user.type(displayName, 'abc')
const submit = screen.getByRole('button', { name: 'Create new group' })
await user.click(submit)

const error = screen.getByText('must be > 3 characters')
expect(error).to.be.ok()
})
})

describe('with an invalid display name, above maximum characters', function() {
// this turns off Mocha's time limit for slow tests
this.timeout(0)

it('should show display name is invalid', async function() {
render(<CreateStory />)

const displayName = screen.getByRole('textbox', { name: 'Group Name' })
await user.type(displayName, 'a'.repeat(61))
const submit = screen.getByRole('button', { name: 'Create new group' })
await user.click(submit)

const error = screen.getByText('must be < 60 characters')
expect(error).to.be.ok()
})
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18235,10 +18235,10 @@ uuid@^9.0.0, uuid@^9.0.1:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

uuid@~11.0.3:
version "11.0.4"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.0.4.tgz#37943977894ef806d2919a7ca3f89d6e23c60bac"
integrity sha512-IzL6VtTTYcAhA/oghbFJ1Dkmqev+FpQWnCBaKq/gUluLxliWvO8DPFWfIviRmYbtaavtSQe4WBL++rFjdcGWEg==
uuid@~11.0.4:
version "11.0.5"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.0.5.tgz#07b46bdfa6310c92c3fb3953a8720f170427fc62"
integrity sha512-508e6IcKLrhxKdBbcA2b4KQZlLVp2+J5UwQ6F7Drckkc5N9ZJwFa4TgWtsww9UG8fGHbm6gbV19TdM5pQ4GaIA==

valid-url@~1.0.9:
version "1.0.9"
Expand Down

0 comments on commit d83397b

Please sign in to comment.