'Scenario: Ensure previews are shown when adding new blocks, regardless of preview setting.
Given that I have a library in Studio with 40 XBlocks
Then previews are visible
And when I click the toggle previews button
Then the previews will not be visible
And when I add an XBlock
Then I will be on the 5th page
And the XBlock will have loaded a preview
And when I revisit the library
And I go to the 5th page
Then the top XBlock will be the one I added
And it will not have a preview
And when I add an XBlock
Then the XBlock I added will have a preview
And the top XBlock will not have one.'

def test_preview_add_xblock(self):

    self.assertTrue(self.lib_page.are_previews_showing())
    self.lib_page.toggle_previews()
    self.assertFalse(self.lib_page.are_previews_showing())
    add_component(self.lib_page, 'problem', 'Checkboxes')
    self.assertEqual(self.lib_page.get_page_number(), '5')
    first_added = self.lib_page.xblocks[0]
    self.assertIn('Checkboxes', first_added.name)
    self.assertFalse(self.lib_page.xblocks[0].is_placeholder())
    self.lib_page.visit()
    self.lib_page.wait_until_ready()
    self.lib_page.go_to_page(5)
    self.assertTrue(self.lib_page.xblocks[0].is_placeholder())
    add_component(self.lib_page, 'problem', 'Multiple    Choice')
    first_added = self.lib_page.xblocks[0]
    second_added = self.lib_page.xblocks[1]
    self.assertIn('Multiple    Choice', second_added.name)
    self.assertFalse(second_added.is_placeholder())
    self.assertTrue(first_added.is_placeholder())
