mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
fix(webapp): query categories on login to get the count (#8542)
* fix(webapp): queru categories to get the count * padd the weapper to fill in
This commit is contained in:
parent
92edde02d8
commit
470ea3f23e
@ -15,6 +15,11 @@ const stubs = {
|
||||
}
|
||||
|
||||
const authUserMock = jest.fn().mockReturnValue({ activeCategories: [] })
|
||||
const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
Category: [{ id: 'cat0' }, { id: 'cat1' }, { id: 'cat2' }, { id: 'cat3' }, { id: 'cat4' }],
|
||||
},
|
||||
})
|
||||
|
||||
describe('LoginForm', () => {
|
||||
let mocks
|
||||
@ -47,6 +52,9 @@ describe('LoginForm', () => {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
},
|
||||
$apollo: {
|
||||
query: apolloQueryMock,
|
||||
},
|
||||
}
|
||||
return mount(LoginForm, { mocks, localVue, propsData, store, stubs })
|
||||
}
|
||||
@ -74,7 +82,9 @@ describe('LoginForm', () => {
|
||||
|
||||
describe('no categories saved', () => {
|
||||
it('resets the categories', async () => {
|
||||
await fillIn(Wrapper())
|
||||
const wrapper = Wrapper()
|
||||
await fillIn(wrapper)
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(storeMocks.mutations['posts/RESET_CATEGORIES']).toHaveBeenCalled()
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).not.toHaveBeenCalled()
|
||||
})
|
||||
@ -82,13 +92,28 @@ describe('LoginForm', () => {
|
||||
|
||||
describe('categories saved', () => {
|
||||
it('sets the categories', async () => {
|
||||
authUserMock.mockReturnValue({ activeCategories: ['cat1', 'cat9', 'cat12'] })
|
||||
await fillIn(Wrapper())
|
||||
authUserMock.mockReturnValue({ activeCategories: ['cat0', 'cat2', 'cat4'] })
|
||||
const wrapper = Wrapper()
|
||||
await fillIn(wrapper)
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(storeMocks.mutations['posts/RESET_CATEGORIES']).toHaveBeenCalled()
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledTimes(3)
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat1')
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat9')
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat12')
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat0')
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat2')
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat4')
|
||||
})
|
||||
})
|
||||
|
||||
describe('all categories saved', () => {
|
||||
it('resets the categories', async () => {
|
||||
authUserMock.mockReturnValue({
|
||||
activeCategories: ['cat0', 'cat1', 'cat2', 'cat3', 'cat4', 'cat5'],
|
||||
})
|
||||
const wrapper = Wrapper()
|
||||
await fillIn(wrapper)
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(storeMocks.mutations['posts/RESET_CATEGORIES']).toHaveBeenCalled()
|
||||
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -59,6 +59,7 @@ import LocaleSwitch from '~/components/LocaleSwitch/LocaleSwitch'
|
||||
import Logo from '~/components/Logo/Logo'
|
||||
import ShowPassword from '../ShowPassword/ShowPassword.vue'
|
||||
import { mapGetters, mapMutations } from 'vuex'
|
||||
import CategoryQuery from '~/graphql/CategoryQuery'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -98,9 +99,13 @@ export default {
|
||||
const { email, password } = this.form
|
||||
try {
|
||||
await this.$store.dispatch('auth/login', { email, password })
|
||||
const result = await this.$apollo.query({
|
||||
query: CategoryQuery(),
|
||||
})
|
||||
const categories = result.data.Category
|
||||
if (this.currentUser && this.currentUser.activeCategories) {
|
||||
this.resetCategories()
|
||||
if (this.currentUser.activeCategories.length < 19) {
|
||||
if (this.currentUser.activeCategories.length < categories.length) {
|
||||
this.currentUser.activeCategories.forEach((categoryId) => {
|
||||
this.toggleCategory(categoryId)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user