Reset chapter visibilities
This commit is contained in:
parent
9c82dc2bf4
commit
45b3414226
|
|
@ -4,7 +4,6 @@ describe('Bookmarks', () => {
|
||||||
cy.exec('python ../server/manage.py prepare_bookmarks_for_cypress');
|
cy.exec('python ../server/manage.py prepare_bookmarks_for_cypress');
|
||||||
|
|
||||||
cy.viewport('macbook-15');
|
cy.viewport('macbook-15');
|
||||||
cy.startGraphQLCapture();
|
|
||||||
cy.apolloLogin('rahel.cueni', 'test');
|
cy.apolloLogin('rahel.cueni', 'test');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,11 @@ Cypress.Commands.add('login', (username, password, visitLogin = false) => {
|
||||||
cy.visit('/beta-login');
|
cy.visit('/beta-login');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username != '') {
|
if (username !== '') {
|
||||||
cy.get('[data-cy=email-input]').type(username);
|
cy.get('[data-cy=email-input]').type(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password != '') {
|
if (password !== '') {
|
||||||
cy.get('[data-cy=password-input]').type(password);
|
cy.get('[data-cy=password-input]').type(password);
|
||||||
}
|
}
|
||||||
cy.get('[data-cy=login-button]').click();
|
cy.get('[data-cy=login-button]').click();
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,14 @@
|
||||||
"lint": "eslint --ext .js,.vue src",
|
"lint": "eslint --ext .js,.vue src",
|
||||||
"fix-lint": "eslint --ext .js,.vue --fix src",
|
"fix-lint": "eslint --ext .js,.vue --fix src",
|
||||||
"build": "node build/build.js",
|
"build": "node build/build.js",
|
||||||
"open:cypress:e2e": "cypress open --config-file cypress.e2e.json",
|
"open:cypress:e2e": "npm run cypress:e2e:open",
|
||||||
"open:cypress:frontend": "cypress open --config-file cypress.frontend.json",
|
"open:cypress:frontend": "npm run cypress:frontend:open",
|
||||||
"test:cypress:e2e": "cypress run --config-file cypress.e2e.json",
|
"test:cypress:e2e": "npm run cypress:e2e:test",
|
||||||
"test:cypress:frontend": "cypress run --config-file cypress.frontend.json",
|
"test:cypress:frontend": "npm run cypress:frontend:test",
|
||||||
|
"cypress:e2e:open": "cypress open --config-file cypress.e2e.json",
|
||||||
|
"cypress:frontend:open": "cypress open --config-file cypress.frontend.json",
|
||||||
|
"cypress:e2e:test": "cypress run --config-file cypress.e2e.json",
|
||||||
|
"cypress:frontend:test": "cypress run --config-file cypress.frontend.json",
|
||||||
"install:cypress": "cypress install",
|
"install:cypress": "cypress install",
|
||||||
"test:unit": "jest"
|
"test:unit": "jest"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,9 @@ class Snapshot(models.Model):
|
||||||
without_owner = Q(owner__isnull=True)
|
without_owner = Q(owner__isnull=True)
|
||||||
no_snapshot = Q(contentblocksnapshot__isnull=True)
|
no_snapshot = Q(contentblocksnapshot__isnull=True)
|
||||||
owner_user = Q(owner=user)
|
owner_user = Q(owner=user)
|
||||||
|
chapter.title_hidden_for.remove(selected_class)
|
||||||
|
chapter.description_hidden_for.remove(selected_class)
|
||||||
|
|
||||||
for content_block in qs.filter(without_owner & no_snapshot):
|
for content_block in qs.filter(without_owner & no_snapshot):
|
||||||
content_block.hidden_for.remove(selected_class)
|
content_block.hidden_for.remove(selected_class)
|
||||||
for content_block in qs.filter(owner_user):
|
for content_block in qs.filter(owner_user):
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ query ModulesQuery($slug: String, $id: ID) {
|
||||||
}
|
}
|
||||||
chapters {
|
chapters {
|
||||||
id
|
id
|
||||||
|
titleHiddenFor { name }
|
||||||
|
descriptionHiddenFor { name }
|
||||||
contentBlocks {
|
contentBlocks {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
|
|
||||||
self.module = ModuleFactory(slug=self.slug)
|
self.module = ModuleFactory(slug=self.slug)
|
||||||
self.skillbox_class = SchoolClass.objects.get(name='skillbox')
|
self.skillbox_class = SchoolClass.objects.get(name='skillbox')
|
||||||
|
self.teacher2 = User.objects.get(username='teacher2')
|
||||||
|
self.second_class_name = 'second_class'
|
||||||
|
self.second_class = SchoolClass.objects.get(name=self.second_class_name)
|
||||||
|
|
||||||
# module M has a chapter
|
# module M has a chapter
|
||||||
self.chapter = ChapterFactory(parent=self.module, slug='some-chapter')
|
self.chapter = ChapterFactory(parent=self.module, slug='some-chapter')
|
||||||
|
|
@ -62,7 +65,7 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
self.hidden_content_block.hidden_for.add(self.skillbox_class)
|
self.hidden_content_block.hidden_for.add(self.skillbox_class)
|
||||||
self.custom_content_block.visible_for.add(self.skillbox_class)
|
self.custom_content_block.visible_for.add(self.skillbox_class)
|
||||||
|
|
||||||
# chapter description is hidden for school class X
|
# chapter title is hidden for school class X
|
||||||
self.chapter.title_hidden_for.add(self.skillbox_class)
|
self.chapter.title_hidden_for.add(self.skillbox_class)
|
||||||
|
|
||||||
# we make a snapshot S of the module M
|
# we make a snapshot S of the module M
|
||||||
|
|
@ -196,20 +199,14 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
user=self.teacher)
|
user=self.teacher)
|
||||||
self.assertEqual(Snapshot.objects.count(), 1)
|
self.assertEqual(Snapshot.objects.count(), 1)
|
||||||
self.assertEqual(self.snapshot.custom_objectives.count(), 2)
|
self.assertEqual(self.snapshot.custom_objectives.count(), 2)
|
||||||
school_class_name = 'second_class'
|
result = self.get_client(self.teacher2).execute(APPLY_SNAPSHOT_MUTATION, variables={
|
||||||
second_class = SchoolClass.objects.get(name=school_class_name)
|
|
||||||
request = RequestFactory().get('/')
|
|
||||||
teacher2 = User.objects.get(username='teacher2')
|
|
||||||
request.user = teacher2
|
|
||||||
client = Client(schema=schema, context_value=request)
|
|
||||||
result = client.execute(APPLY_SNAPSHOT_MUTATION, variables={
|
|
||||||
'input': {
|
'input': {
|
||||||
'snapshot': to_global_id('SnapshotNode', self.snapshot.pk),
|
'snapshot': to_global_id('SnapshotNode', self.snapshot.pk),
|
||||||
'selectedClass': to_global_id('SchoolClassNode', second_class.pk),
|
'selectedClass': to_global_id('SchoolClassNode', self.second_class.pk),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(result.get('errors'))
|
self.assertIsNone(result.get('errors'))
|
||||||
module = self._test_module_visibility(client, school_class_name)
|
module = self._test_module_visibility(self.get_client(self.teacher2), self.second_class_name)
|
||||||
original_creator = module['chapters'][0]['contentBlocks'][2].get('originalCreator')
|
original_creator = module['chapters'][0]['contentBlocks'][2].get('originalCreator')
|
||||||
self.assertIsNotNone(original_creator)
|
self.assertIsNotNone(original_creator)
|
||||||
self.assertEqual(original_creator.get('id'), to_global_id('PublicUserNode', self.teacher.pk))
|
self.assertEqual(original_creator.get('id'), to_global_id('PublicUserNode', self.teacher.pk))
|
||||||
|
|
@ -249,15 +246,13 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
self.assertEqual(changes['hiddenObjectives'], 1)
|
self.assertEqual(changes['hiddenObjectives'], 1)
|
||||||
|
|
||||||
def test_apply_initial_snapshot(self):
|
def test_apply_initial_snapshot(self):
|
||||||
teacher2 = User.objects.get(username='teacher2')
|
|
||||||
teacher2_client = self.get_client(user=teacher2)
|
|
||||||
third_class = SchoolClassFactory(
|
third_class = SchoolClassFactory(
|
||||||
users=[teacher2],
|
users=[self.teacher2],
|
||||||
name='third_class'
|
name='third_class'
|
||||||
)
|
)
|
||||||
|
|
||||||
# make a neutral snapshot, nothing new, nothing hidden
|
# make a neutral snapshot, nothing new, nothing hidden
|
||||||
result = teacher2_client.execute(CREATE_SNAPSHOT_MUTATION, variables={
|
result = self.get_client(user=self.teacher2).execute(CREATE_SNAPSHOT_MUTATION, variables={
|
||||||
'input': {
|
'input': {
|
||||||
'module': self.slug,
|
'module': self.slug,
|
||||||
'selectedClass': to_global_id('SchoolClassNode', third_class.pk),
|
'selectedClass': to_global_id('SchoolClassNode', third_class.pk),
|
||||||
|
|
@ -305,12 +300,10 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
|
|
||||||
teacher2 = User.objects.get(username='teacher2')
|
teacher2 = User.objects.get(username='teacher2')
|
||||||
teacher2_client = self.get_client(user=teacher2)
|
teacher2_client = self.get_client(user=teacher2)
|
||||||
school_class_name = 'second_class'
|
|
||||||
second_class = SchoolClass.objects.get(name=school_class_name)
|
|
||||||
result = teacher2_client.execute(APPLY_SNAPSHOT_MUTATION, variables={
|
result = teacher2_client.execute(APPLY_SNAPSHOT_MUTATION, variables={
|
||||||
'input': {
|
'input': {
|
||||||
'snapshot': snapshot_id,
|
'snapshot': snapshot_id,
|
||||||
'selectedClass': to_global_id('SchoolClassNode', second_class.pk),
|
'selectedClass': to_global_id('SchoolClassNode', self.second_class.pk),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(result.get('errors'))
|
self.assertIsNone(result.get('errors'))
|
||||||
|
|
@ -323,6 +316,48 @@ class CreateSnapshotTestCase(SkillboxTestCase):
|
||||||
self.assertEqual(len(chapter['contentBlocks']), 4)
|
self.assertEqual(len(chapter['contentBlocks']), 4)
|
||||||
|
|
||||||
|
|
||||||
|
def test_snapshot_chapter_visibility_after_apply(self):
|
||||||
|
self.chapter.title_hidden_for.remove(self.skillbox_class)
|
||||||
|
self.chapter.description_hidden_for.remove(self.skillbox_class)
|
||||||
|
|
||||||
|
self.chapter.title_hidden_for.add(self.second_class)
|
||||||
|
self.chapter.description_hidden_for.add(self.second_class)
|
||||||
|
|
||||||
|
def assert_chapter_hidden(hidden):
|
||||||
|
result = self.get_client(self.teacher2).execute(MODULE_QUERY, variables={
|
||||||
|
'slug': self.module.slug
|
||||||
|
})
|
||||||
|
self.assertIsNone(result.get('errors'))
|
||||||
|
chapter = result['data']['module']['chapters'][0]
|
||||||
|
self.assertEqual(self.second_class_name in map(lambda x: x['name'], chapter['titleHiddenFor']), hidden)
|
||||||
|
self.assertEqual(self.second_class_name in map(lambda x: x['name'], chapter['descriptionHiddenFor']), hidden)
|
||||||
|
|
||||||
|
assert_chapter_hidden(True)
|
||||||
|
|
||||||
|
result = self.graphene_client.execute(CREATE_SNAPSHOT_MUTATION, variables={
|
||||||
|
'input': {
|
||||||
|
'module': self.slug,
|
||||||
|
'selectedClass': to_global_id('SchoolClassNode', self.skillbox_class.pk),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
self.assertIsNone(result.get('errors'))
|
||||||
|
snapshot = result['data']['createSnapshot']['snapshot']
|
||||||
|
snapshot_id = snapshot['id']
|
||||||
|
chapter = snapshot['chapters'][0]
|
||||||
|
self.assertEqual(chapter['titleHidden'], False)
|
||||||
|
self.assertEqual(chapter['descriptionHidden'], False)
|
||||||
|
|
||||||
|
result = self.get_client(self.teacher2).execute(APPLY_SNAPSHOT_MUTATION, variables={
|
||||||
|
'input': {
|
||||||
|
'snapshot': snapshot_id,
|
||||||
|
'selectedClass': to_global_id('SchoolClassNode', self.second_class.pk),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
self.assertIsNone(result.get('errors'))
|
||||||
|
|
||||||
|
assert_chapter_hidden(False)
|
||||||
|
|
||||||
|
|
||||||
class SnapshotTestCase(SkillboxTestCase):
|
class SnapshotTestCase(SkillboxTestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.createDefault()
|
self.createDefault()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue