Re-write local cache on client reset
Also clean up some code
This commit is contained in:
parent
e177608360
commit
2d6724db9e
|
|
@ -44,4 +44,22 @@ describe('The Login Page', () => {
|
||||||
cy.get('body').contains('Berufliche Grundbildung');
|
cy.get('body').contains('Berufliche Grundbildung');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.only('logs out then logs in again', () => {
|
||||||
|
cy.viewport('macbook-15');
|
||||||
|
cy.apolloLogin('rahel.cueni', 'test');
|
||||||
|
cy.visit('/me/my-class');
|
||||||
|
cy.get('[data-cy=header-user-widget]').should('exist').within(() => {
|
||||||
|
cy.get('[data-cy=user-widget-avatar]').should('exist').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.get('[data-cy=logout]').click();
|
||||||
|
|
||||||
|
cy.login('rahel.cueni', 'test');
|
||||||
|
|
||||||
|
cy.get('[data-cy=header-user-widget]').should('exist').within(() => {
|
||||||
|
cy.get('[data-cy=user-widget-avatar]').should('exist').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.get('.profile-sidebar').should('be.visible');
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
import ContentNavigation from '@/components/ContentNavigation.vue';
|
import ContentNavigation from '@/components/ContentNavigation.vue';
|
||||||
import BookNavigation from '@/components/book-navigation/BookNavigation';
|
import BookNavigation from '@/components/book-navigation/BookNavigation';
|
||||||
import UserWidget from '@/components/UserWidget.vue';
|
import UserWidget from '@/components/UserWidget.vue';
|
||||||
import LogoutWidget from '@/components/LogoutWidget.vue';
|
|
||||||
import Logo from '@/components/icons/Logo';
|
import Logo from '@/components/icons/Logo';
|
||||||
import CurrentClass from '@/components/school-class/CurrentClass';
|
import CurrentClass from '@/components/school-class/CurrentClass';
|
||||||
|
|
||||||
|
|
@ -31,7 +30,6 @@
|
||||||
components: {
|
components: {
|
||||||
ContentNavigation,
|
ContentNavigation,
|
||||||
UserWidget,
|
UserWidget,
|
||||||
LogoutWidget,
|
|
||||||
BookNavigation,
|
BookNavigation,
|
||||||
Logo,
|
Logo,
|
||||||
CurrentClass
|
CurrentClass
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
import LOGOUT_MUTATION from '@/graphql/gql/mutations/logoutUser.gql';
|
import LOGOUT_MUTATION from '@/graphql/gql/mutations/logoutUser.gql';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
logout() {
|
logout() {
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
|
|
@ -32,7 +31,6 @@
|
||||||
&__logout {
|
&__logout {
|
||||||
font-family: $sans-serif-font-family;
|
font-family: $sans-serif-font-family;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
margin: 0 15px 0 $large-spacing;
|
|
||||||
background: none;
|
background: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
eingeben
|
eingeben
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-sidebar__item" @click="logout">
|
<div class="profile-sidebar__item">
|
||||||
<a class="profile-sidebar__link">Logout</a>
|
<logout-widget></logout-widget>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -29,32 +29,20 @@
|
||||||
import ProfileWidget from '@/components/profile/ProfileWidget';
|
import ProfileWidget from '@/components/profile/ProfileWidget';
|
||||||
import Cross from '@/components/icons/Cross';
|
import Cross from '@/components/icons/Cross';
|
||||||
|
|
||||||
import LOGOUT_MUTATION from '@/graphql/gql/mutations/logoutUser.gql';
|
|
||||||
|
|
||||||
import ClassSelectionWidget from '@/components/school-class/ClassSelectionWidget';
|
import ClassSelectionWidget from '@/components/school-class/ClassSelectionWidget';
|
||||||
|
|
||||||
import sidebarMixin from '@/mixins/sidebar';
|
import sidebarMixin from '@/mixins/sidebar';
|
||||||
|
import LogoutWidget from '@/components/LogoutWidget';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
LogoutWidget,
|
||||||
ClassSelectionWidget,
|
ClassSelectionWidget,
|
||||||
ProfileWidget,
|
ProfileWidget,
|
||||||
Cross
|
Cross
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [sidebarMixin],
|
mixins: [sidebarMixin],
|
||||||
|
|
||||||
methods: {
|
|
||||||
logout() {
|
|
||||||
this.$apollo.mutate({
|
|
||||||
mutation: LOGOUT_MUTATION,
|
|
||||||
}).then(({data}) => {
|
|
||||||
if (data.logout.success) {
|
|
||||||
location.replace('/logout')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,22 @@ import fetch from 'unfetch'
|
||||||
import {typeDefs} from '@/graphql/typedefs';
|
import {typeDefs} from '@/graphql/typedefs';
|
||||||
import {resolvers} from '@/graphql/resolvers';
|
import {resolvers} from '@/graphql/resolvers';
|
||||||
|
|
||||||
|
const writeLocalCache = cache => {
|
||||||
|
// we use the cache as our local state
|
||||||
|
cache.writeData({
|
||||||
|
data: {
|
||||||
|
scrollPosition: {
|
||||||
|
__typename: 'ScrollPosition',
|
||||||
|
scrollTo: ''
|
||||||
|
},
|
||||||
|
sidebar: {
|
||||||
|
__typename: 'Sidebar',
|
||||||
|
open: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default function (uri) {
|
export default function (uri) {
|
||||||
const httpLink = createHttpLink({
|
const httpLink = createHttpLink({
|
||||||
// uri: process.env.NODE_ENV !== 'production' ? 'http://localhost:8000/api/graphql/' : '/api/graphql/',
|
// uri: process.env.NODE_ENV !== 'production' ? 'http://localhost:8000/api/graphql/' : '/api/graphql/',
|
||||||
|
|
@ -96,27 +112,19 @@ export default function (uri) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// we use the cache as our local state
|
writeLocalCache(cache);
|
||||||
cache.writeData({
|
|
||||||
data: {
|
|
||||||
scrollPosition: {
|
|
||||||
__typename: 'ScrollPosition',
|
|
||||||
scrollTo: ''
|
|
||||||
},
|
|
||||||
sidebar: {
|
|
||||||
__typename: 'Sidebar',
|
|
||||||
open: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create the apollo client
|
// Create the apollo client
|
||||||
return new ApolloClient({
|
const client = new ApolloClient({
|
||||||
link: composedLink,
|
link: composedLink,
|
||||||
// link: httpLink,
|
// link: httpLink,
|
||||||
cache,
|
cache,
|
||||||
connectToDevTools: true,
|
connectToDevTools: true,
|
||||||
typeDefs,
|
typeDefs,
|
||||||
resolvers
|
resolvers
|
||||||
})
|
});
|
||||||
|
client.onResetStore(() => {
|
||||||
|
writeLocalCache(cache);
|
||||||
|
});
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue