Commit b1c94160 by Braden MacDonald

Add test for backwards compatibility

parent dfdecfb6
{
"question_text": "Note: This is an example of data in the format used by prior versions of this block. Not in particular the old `size` data.",
"zones": [
{
"index": 1,
"width": 200,
"title": "Zone 1",
"height": 100,
"y": "200",
"x": "100",
"id": "zone-1"
},
{
"index": 2,
"width": 200,
"title": "Zone 2",
"height": 100,
"y": 0,
"x": 0,
"id": "zone-2"
}
],
"items": [
{
"displayName": "1",
"feedback": {
"incorrect": "No 1",
"correct": "Yes 1"
},
"zone": "Zone 1",
"backgroundImage": "",
"id": 0,
"size": {
"width": "190px",
"height": "auto"
}
},
{
"displayName": "2",
"feedback": {
"incorrect": "No 2",
"correct": "Yes 2"
},
"zone": "Zone 2",
"backgroundImage": "",
"id": 1,
"size": {
"width": "190px",
"height": "100px"
},
"inputOptions": {
"value": 100,
"margin": 5
}
},
{
"displayName": "Pic",
"feedback": {
"incorrect": "",
"correct": ""
},
"zone": "Zone 1",
"backgroundImage": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNjAwIiBzdHlsZT0iYmFja2dyb3VuZDogI2VlZjsiPjwvc3ZnPg==",
"id": 2,
"size": {
"width": "100px",
"height": "auto"
}
}
],
"state": {
"items": {},
"finished": true
},
"feedback": {
"start": "Intro Feedback",
"finish": "Final Feedback"
},
"title": "Drag and Drop (Old-style data)"
}
\ No newline at end of file
......@@ -191,3 +191,38 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
container_width=target_img_width,
expected_percent=expected_width_percent,
)
class SizingBackwardsCompatibilityTests(InteractionTestBase, BaseIntegrationTest):
"""
Test backwards compatibility with data generated in older versions of this block.
Older versions allowed authors to specify a fixed width and height for each draggable, in
pixels (new versions only have a configurable width, and it is a percent width).
"""
PAGE_TITLE = 'Drag and Drop v2 Sizing Backwards Compatibility'
PAGE_ID = 'drag_and_drop_v2_sizing_backwards_compatibility'
@staticmethod
def _get_scenario_xml():
"""
Set up the test scenario:
* One DndDv2 block using 'old_version_data.json'
"""
dnd_block = "<drag-and-drop-v2 data='{data}'/>".format(
data=loader.load_unicode("data/old_version_data.json")
)
return "<vertical_demo>{}</vertical_demo>".format(dnd_block)
def test_draggable_sizes(self):
""" Test the fixed pixel widths set in old versions of the block """
self._expect_width_px(item_id=0, width_px=190, zone_id="Zone 1")
self._expect_width_px(item_id=1, width_px=190, zone_id="Zone 2")
self._expect_width_px(item_id=2, width_px=100, zone_id="Zone 1")
def _expect_width_px(self, item_id, width_px, zone_id):
item = self._get_unplaced_item_by_value(item_id)
self.assertEqual(item.size["width"], width_px)
self.place_item(item_id, zone_id)
item = self._get_placed_item_by_value(item_id)
self.assertEqual(item.size["width"], width_px)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment